From ken at seehart.com Thu Mar 14 23:02:04 2013 From: ken at seehart.com (Ken Seehart) Date: Thu, 14 Mar 2013 20:02:04 -0700 Subject: Yet another attempt at a safe eval() call In-Reply-To: <50e6da35$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <50e6da35$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51428F2C.6090901@seehart.com> On 1/4/2013 5:33 AM, Steven D'Aprano wrote: > On Fri, 04 Jan 2013 07:24:04 -0500, Terry Reedy wrote: > >> On 1/3/2013 6:25 PM, Grant Edwards wrote: >>> I've written a small assembler in Python 2.[67], and it needs to >>> evaluate integer-valued arithmetic expressions in the context of a >>> symbol table that defines integer values for a set of names. The >>> "right" thing is probably an expression parser/evaluator using ast, but >>> it looked like that would take more code that the rest of the assembler >>> combined, and I've got other higher-priority tasks to get back to. >> Will ast.literal_eval do what you want? > No. Grant needs to support variables, not just literal constants, hence > the symbol table. > > Apologies for the delayed response... Seems like it would be a bit safer and easier to approach this problem by stretching the capability of ast.literal_eval() rather than attempting to sandbox eval(). How about ast.literal_eval after performing lexical substitution using the symbol table? Assignment into the symbol table, and error handling, are exercises left to the reader. Something vaguely like this: /pseudocode:/ def safe_eval(s, symbols={}): while search(s, r'\w+'): replace match with '('+repr(symbols[match])+')' in s return ast.literal_eval(s) - Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From techgeek201 at gmail.com Mon Mar 18 19:51:48 2013 From: techgeek201 at gmail.com (eli m) Date: Mon, 18 Mar 2013 16:51:48 -0700 (PDT) Subject: Small program ideas In-Reply-To: References: Message-ID: Any other ideas? From breamoreboy at yahoo.co.uk Mon Mar 18 20:56:56 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 19 Mar 2013 00:56:56 +0000 Subject: Small program ideas In-Reply-To: References: Message-ID: On 18/03/2013 23:51, eli m wrote: > Any other ideas? > How about coming up with a new message passing syntax for objects? I understand from recent postings that this should be fairly easy :) -- Cheers. Mark Lawrence From d12123176 at mydit.ie Thu Mar 28 14:46:54 2013 From: d12123176 at mydit.ie (PMT) Date: Thu, 28 Mar 2013 11:46:54 -0700 (PDT) Subject: Small program ideas In-Reply-To: References: Message-ID: Em s?bado, 16 de fevereiro de 2013 03h22min41s UTC, eli m escreveu: > Any small program ideas? I would prefer to stick to command line ones. Thanks. What about this one? Do you know how to do the elevator simulation? From neilc at norwich.edu Fri Mar 29 09:43:24 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Mar 2013 13:43:24 GMT Subject: Small program ideas References: Message-ID: On 2013-03-28, PMT wrote: > Em s?bado, 16 de fevereiro de 2013 03h22min41s UTC, eli m escreveu: >> Any small program ideas? I would prefer to stick to command >> line ones. Thanks. > > What about this one? > > Do you know how to do the elevator simulation? Cribbed from an early chapter of the excellent computer science manual, _Simply Scheme_: A command line program to convert a sentence into Pig-Latin. C:\> piglatin.py Look in the bag! Ooklay in the agbay! Start with a function that converts a single word to Pig-Latin, and work your way up to the final program in small steps. -- Neil Cerutti From torriem at gmail.com Sun Mar 3 01:46:42 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 02 Mar 2013 23:46:42 -0700 Subject: i need help In-Reply-To: <5125F488.6070401@libero.it> References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> Message-ID: <5132F1D2.4090801@gmail.com> On 02/21/2013 03:18 AM, leonardo wrote: > thanks, problem solved Apparently not. The shift key on your keyboard still seems to be non-functional. ;) From kwpolska at gmail.com Sun Mar 3 13:45:26 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sun, 3 Mar 2013 19:45:26 +0100 Subject: i need help In-Reply-To: <5132F1D2.4090801@gmail.com> References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> <5132F1D2.4090801@gmail.com> Message-ID: On Sun, Mar 3, 2013 at 7:46 AM, Michael Torrie wrote: > On 02/21/2013 03:18 AM, leonardo wrote: >> thanks, problem solved > > Apparently not. The shift key on your keyboard still seems to be > non-functional. ;) > -- > http://mail.python.org/mailman/listinfo/python-list It is! How else could he type those two question marks and 10 double-quotes? -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From bryan.devaney at gmail.com Mon Mar 4 10:07:53 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Mon, 4 Mar 2013 07:07:53 -0800 (PST) Subject: i need help In-Reply-To: References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> <5132F1D2.4090801@gmail.com> Message-ID: On Sunday, March 3, 2013 6:45:26 PM UTC, Kwpolska wrote: > On Sun, Mar 3, 2013 at 7:46 AM, Michael Torrie wrote: > > > On 02/21/2013 03:18 AM, leonardo wrote: > > >> thanks, problem solved > > > > > > Apparently not. The shift key on your keyboard still seems to be > > > non-functional. ;) > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > It is! How else could he type those two question marks and 10 double-quotes? > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html Onscreen Keyboard? From bryan.devaney at gmail.com Mon Mar 4 10:07:53 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Mon, 4 Mar 2013 07:07:53 -0800 (PST) Subject: i need help In-Reply-To: References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> <5132F1D2.4090801@gmail.com> Message-ID: On Sunday, March 3, 2013 6:45:26 PM UTC, Kwpolska wrote: > On Sun, Mar 3, 2013 at 7:46 AM, Michael Torrie wrote: > > > On 02/21/2013 03:18 AM, leonardo wrote: > > >> thanks, problem solved > > > > > > Apparently not. The shift key on your keyboard still seems to be > > > non-functional. ;) > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > It is! How else could he type those two question marks and 10 double-quotes? > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html Onscreen Keyboard? From ian.g.kelly at gmail.com Mon Mar 4 11:45:40 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Mar 2013 09:45:40 -0700 Subject: i need help In-Reply-To: References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> <5132F1D2.4090801@gmail.com> Message-ID: On Mon, Mar 4, 2013 at 8:07 AM, Bryan Devaney wrote: > On Sunday, March 3, 2013 6:45:26 PM UTC, Kwpolska wrote: >> >> It is! How else could he type those two question marks and 10 double-quotes? >> > > Onscreen Keyboard? Or voice recognition, perhaps. We have no idea what the OP's actual input system might be, which is why it might be best not to harass him over something so trivial as uncapitalized letters. One post in this thread pointing it out was plenty. From alister.ware at ntlworld.com Mon Mar 4 11:45:39 2013 From: alister.ware at ntlworld.com (Alister) Date: Mon, 04 Mar 2013 16:45:39 GMT Subject: i need help References: <5125E44C.90004@libero.it> <5125F488.6070401@libero.it> <5132F1D2.4090801@gmail.com> Message-ID: On Mon, 04 Mar 2013 07:07:53 -0800, Bryan Devaney wrote: > On Sunday, March 3, 2013 6:45:26 PM UTC, Kwpolska wrote: >> On Sun, Mar 3, 2013 at 7:46 AM, Michael Torrie >> wrote: >> >> > On 02/21/2013 03:18 AM, leonardo wrote: >> >> >> thanks, problem solved >> >> >> > >> > Apparently not. The shift key on your keyboard still seems to be >> >> > non-functional. ;) >> >> > -- >> >> > http://mail.python.org/mailman/listinfo/python-list >> >> >> >> It is! How else could he type those two question marks and 10 >> double-quotes? >> >> >> >> -- >> >> Kwpolska | GPG KEY: 5EAAEA16 >> >> stop html mail | always bottom-post >> >> http://asciiribbon.org | http://caliburn.nl/topposting.html > > Onscreen Keyboard? using alt & the numeric keypad ? alt 62, alt 34 -- New York's got the ways and means; Just won't let you be. -- The Grateful Dead From piet at vanoostrum.org Wed Mar 6 21:13:17 2013 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 06 Mar 2013 22:13:17 -0400 Subject: why can not parse the web in almost same xpath expression? References: Message-ID: python writes: > import urllib > import lxml.html > down='http://v.163.com/special/visualizingdata/' > file=urllib.urlopen(down).read() > root=lxml.html.document_fromstring(file) > urllist=root.xpath('//div[@class="down s-fc3 f-fl"]//a') > for url in urllist: > print url.get("href") > > i get the output , > http://mov.bn.netease.com/movieMP4/2012/12/A/7/S8H1TH9A7.mp4 > http://mov.bn.netease.com/movieMP4/2012/12/D/9/S8H1ULCD9.mp4 > http://mov.bn.netease.com/movieMP4/2012/12/4/P/S8H1UUH4P.mp4 > http://mov.bn.netease.com/movieMP4/2012/12/B/V/S8H1V8RBV.mp4 > http://mov.bn.netease.com/movieMP4/2012/12/6/E/S8H1VIF6E.mp4 > http://mov.bn.netease.com/movieMP4/2012/12/B/G/S8H1VQ2BG.mp4 > > when i change > > xpath('//div[@class="down s-fc3 f-fl"]//a') > > into > > xpath('//div[@class="col f-cb"]//div[@class="down s-fc3 f-fl"]//a') > > that is to say , > > urllist=root.xpath('//div[@class="col f-cb"]//div[@class="down s-fc3 f-fl"]//a') > > why i can't get nothing? There is only one
in the document and that div contains only a single
but the latter does not contain any . The URLs that you get in the first code are not contained in a
. They are contained in a
, however. So xpath('//div[@class="m-tdli"]//div[@class="down s-fc3 f-fl"]//a') works. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From solipsis at pitrou.net Fri Mar 1 14:03:42 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 19:03:42 +0000 (UTC) Subject: =?utf-8?b?SU1BUDRfU1NM?= and OpenSSL compatibility References: <20130225224327.GA10266@fama.tangosoft.com> <20130226175741.207720rbieqlm6x1@webmail.in-berlin.de> Message-ID: W. Martin Borgert debian.org> writes: > > > > There is already the ssl_context option for that: > > http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4_SSL > > Many thanks! Two more questions: > > 1. Is there any plan to backport this Python >= 3.3 feature to > Python 2? No, we don't backport new features to maintenance releases. > 2. Would the following lines be correct for Python 3.3? > > >>> import imaplib > >>> IMAP4_SSL("192.168.1.1.", ssl_context = > SSLContext(ssl.PROTOCOL_SSLv3)) It should be, yes. Regards Antoine. From mcepl at redhat.com Fri Mar 1 17:46:10 2013 From: mcepl at redhat.com (Matej Cepl) Date: Fri, 1 Mar 2013 23:46:10 +0100 Subject: IMAP4_SSL and OpenSSL compatibility References: <20130225224327.GA10266@fama.tangosoft.com> Message-ID: On 2013-02-26, 16:57 GMT, W. Martin Borgert wrote: > 1. Is there any plan to backport this Python >= 3.3 feature to > Python 2? No, development of Python 2 ceased to exist (only important bugfixes or security fix will happen, IIRC) If you need advanced use of SSL, use pyOpenSSL (it has been ported to Python 3 already, so you won't loose any compatibility). Mat?j From jeanmichel at sequans.com Fri Mar 1 05:06:43 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 1 Mar 2013 11:06:43 +0100 (CET) Subject: Do you feel bad because of the Python docs? In-Reply-To: <57ebc67e-09a5-4eaa-a1cc-40a7298cc385@ps9g2000pbb.googlegroups.com> Message-ID: <1832688780.12502496.1362132403723.JavaMail.root@sequans.com> [snip hostile replies] It's somehow funny to read such posts on a thread about someone complaining about the community python being hostile. I think we should really try to resist the urge of answering trolls because no matter how many times we slap them, they'll stay trolls and probably get even bigger. Instead, we take revenge by helping someone asking us to do his homework and show the world how merciful the python community is. 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 jake.angulo at gmail.com Sun Mar 3 18:47:27 2013 From: jake.angulo at gmail.com (Jake Angulo) Date: Mon, 4 Mar 2013 10:47:27 +1100 Subject: Do you feel bad because of the Python docs? In-Reply-To: <1832688780.12502496.1362132403723.JavaMail.root@sequans.com> References: <57ebc67e-09a5-4eaa-a1cc-40a7298cc385@ps9g2000pbb.googlegroups.com> <1832688780.12502496.1362132403723.JavaMail.root@sequans.com> Message-ID: The OP speaks for himself alone. Python - for such a very young language, and with the documentation and community blogs available at this point - I cannot ask for more. And who needs docs when the python syntax is as good as writing plain english sentence? On Fri, Mar 1, 2013 at 9:06 PM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > [snip hostile replies] > > It's somehow funny to read such posts on a thread about someone > complaining about the community python being hostile. > I think we should really try to resist the urge of answering trolls > because no matter how many times we slap them, they'll stay trolls and > probably get even bigger. > > Instead, we take revenge by helping someone asking us to do his homework > and show the world how merciful the python community is. > > 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. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Mar 5 20:43:31 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Tue, 05 Mar 2013 17:43:31 -0800 Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: On Wed, 27 Feb 2013 15:25:25 -0800 (PST), alex23 wrote: > On Feb 27, 1:13?pm, Rick Johnson wrote: > > > [...] do you /really/ expect that people > > have the time to open an issue on the bug tracker? > > If someone can write a paragraph on their blog or this list > complaining about a problem, then yes, they have the time to open an > issue on the bug tracker. I've tried twice to register with the bug tracker -- including just before sending this post. Both times I got something like this: Subject: Failed issue tracker submission From: Python tracker Date: Wed, 06 Mar 2013 00:56:44 +0000 An unexpected error occurred during the processing of your message. The tracker administrator is being notified. So, it's not all that easy to report bugs for me, anyway. I'd given up, prior, but reading this thread I thought I'd try one more time. I had wanted to report doc bugs, too, as I used to do copy and line editing. I seem to be able to find typos and such rather easily, but reporting said bugs -- not so easy. Something seems amiss, I'd say. It may be just me, but the point still stands. --Bob Hanson -- Hanson's Heuristic: Ninety-eight percent of what I think I know is bullshit. The rest is crap. From breamoreboy at yahoo.co.uk Tue Mar 5 22:12:43 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 06 Mar 2013 03:12:43 +0000 Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: On 06/03/2013 01:43, Bob Hanson wrote: > On Wed, 27 Feb 2013 15:25:25 -0800 (PST), alex23 wrote: > >> On Feb 27, 1:13 pm, Rick Johnson wrote: >> >>> [...] do you /really/ expect that people >>> have the time to open an issue on the bug tracker? >> >> If someone can write a paragraph on their blog or this list >> complaining about a problem, then yes, they have the time to open an >> issue on the bug tracker. > > I've tried twice to register with the bug tracker -- including > just before sending this post. Both times I got something like > this: > > Subject: Failed issue tracker submission > From: Python tracker > Date: Wed, 06 Mar 2013 00:56:44 +0000 > > An unexpected error occurred during the processing > of your message. The tracker administrator is being > notified. > > So, it's not all that easy to report bugs for me, anyway. I'd > given up, prior, but reading this thread I thought I'd try one > more time. > > I had wanted to report doc bugs, too, as I used to do copy and > line editing. I seem to be able to find typos and such rather > easily, but reporting said bugs -- not so easy. > > Something seems amiss, I'd say. It may be just me, but the point > still stands. > > --Bob Hanson > You'll be delighted to know that everybody will have to sign a contributor agreement if they're supplying a patch file on the bug tracker, see http://blog.python.org/2013/03/introducing-electronic-contributor.html and http://mail.python.org/pipermail/python-dev/2013-March/124540.html -- Cheers. Mark Lawrence From invalid at invalid.invalid Fri Mar 8 22:10:47 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Fri, 08 Mar 2013 19:10:47 -0800 Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: On Wed, 06 Mar 2013 03:12:43 +0000, Mark Lawrence wrote: > On 06/03/2013 01:43, Bob Hanson wrote: > > > [problem reporting bugs] > > You'll be delighted to know that everybody will have to sign a > contributor agreement if they're supplying a patch file on the bug > tracker, see > http://blog.python.org/2013/03/introducing-electronic-contributor.html > and http://mail.python.org/pipermail/python-dev/2013-March/124540.html Thanks, Mark. I have other responses to reply to, as well. I suspect that between your advice and the others, I'll learn how to help with at least doc bugs, soon. And sorry for the late reply. I changed ISPs (dialup to DSL) which turned out to be a major... uh... event for the geniuses at the telephone company out here in the "frontier" of the Oregon Cascades. Regards, Bob Hanson -- Sent from my Smart shoephone. Please excuse failure to top-post, failure to snip-to-context, and failure to leave message-digest subject header intact. From invalid at invalid.invalid Tue Mar 5 20:50:22 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Tue, 05 Mar 2013 17:50:22 -0800 Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: [Sorry for the double-post -- I somehow had Followup-To set to poster in the first post.] On Wed, 27 Feb 2013 15:25:25 -0800 (PST), alex23 wrote: > On Feb 27, 1:13?pm, Rick Johnson wrote: > > > [...] do you /really/ expect that people > > have the time to open an issue on the bug tracker? > > If someone can write a paragraph on their blog or this list > complaining about a problem, then yes, they have the time to open an > issue on the bug tracker. I've tried twice to register with the bug tracker -- including just before sending this post. Both times I got something like this: Subject: Failed issue tracker submission From: Python tracker Date: Wed, 06 Mar 2013 00:56:44 +0000 An unexpected error occurred during the processing of your message. The tracker administrator is being notified. So, it's not all that easy to report bugs for me, anyway. I'd given up, prior, but reading this thread I thought I'd try one more time. I had wanted to report doc bugs, too, as I used to do copy and line editing. I seem to be able to find typos and such rather easily, but reporting said bugs -- not so easy. Something seems amiss, I'd say. It may be just me, but the point still stands. --Bob Hanson -- Hanson's Heuristic: Ninety-eight percent of what I think I know is bullshit. The rest is crap. From invalid at invalid.invalid Tue Mar 5 20:51:36 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Tue, 05 Mar 2013 17:51:36 -0800 Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: [Sorry for the double-post -- I somehow had Followup-To set to poster in the first post.] On Wed, 27 Feb 2013 15:25:25 -0800 (PST), alex23 wrote: > On Feb 27, 1:13?pm, Rick Johnson wrote: > > > [...] do you /really/ expect that people > > have the time to open an issue on the bug tracker? > > If someone can write a paragraph on their blog or this list > complaining about a problem, then yes, they have the time to open an > issue on the bug tracker. I've tried twice to register with the bug tracker -- including just before sending this post. Both times I got something like this: Subject: Failed issue tracker submission From: Python tracker Date: Wed, 06 Mar 2013 00:56:44 +0000 An unexpected error occurred during the processing of your message. The tracker administrator is being notified. So, it's not all that easy to report bugs for me, anyway. I'd given up, prior, but reading this thread I thought I'd try one more time. I had wanted to report doc bugs, too, as I used to do copy and line editing. I seem to be able to find typos and such rather easily, but reporting said bugs -- not so easy. Something seems amiss, I'd say. It may be just me, but the point still stands. --Bob Hanson -- Hanson's Heuristic: Ninety-eight percent of what I think I know is bullshit. The rest is crap. From steve+comp.lang.python at pearwood.info Tue Mar 5 22:38:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 03:38:36 GMT Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> Message-ID: <5136ba3b$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 05 Mar 2013 17:51:36 -0800, Bob Hanson wrote: > I've tried twice to register with the bug tracker -- including just > before sending this post. Both times I got something like this: > > Subject: Failed issue tracker submission From: Python tracker > Date: Wed, 06 Mar 2013 > 00:56:44 +0000 > > An unexpected error occurred during the processing of your message. > The tracker administrator is being notified. Works for me. Please try again, and if it still does not work, please email me off-list and I will help you either set up an account or report a tracker bug. -- Steven From invalid at invalid.invalid Fri Mar 8 22:31:50 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Fri, 08 Mar 2013 19:31:50 -0800 Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <5136ba3b$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06 Mar 2013 03:38:36 GMT, Steven D'Aprano wrote: > On Tue, 05 Mar 2013 17:51:36 -0800, Bob Hanson wrote: > > > [trouble reporting bugs] > > Works for me. > > Please try again, and if it still does not work, please email me off-list > and I will help you either set up an account or report a tracker bug. Thanks, Steven. I'll likely take you up on your offer to help me off-list via email as I also wanted to talk with you about your circular-means function in your stats package. I do want to help with doc bugs. I'll probably have to get fairly involved to be able to submit more major doc-bug patches -- as others have said. And, as I said to Mark, sorry for the late reply. (I was without internet access for a few days while the experts at the phone company once again attempted to simulate minimal competence culminating with their "DSL install expert" -- who had never heard of Linux -- trying to puzzle out my desktop.) Regards, Bob Hanson -- Sent by smoke signals from the top of Mount St. Helens. Please excuse the sulfur fumes. From rosuav at gmail.com Fri Mar 8 22:45:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 14:45:00 +1100 Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <5136ba3b$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 9, 2013 at 2:31 PM, Bob Hanson wrote: > (I was without internet access for a few days while the experts > at the phone company once again attempted to simulate minimal > competence culminating with their "DSL install expert" -- who had > never heard of Linux -- trying to puzzle out my desktop.) I know exactly how that feels. Back in 2002 or thereabouts when we got our current Optus cable connection installed, we were an all-OS/2 shop (and we still have a good bit of OS/2, but there's some Windows and a good bit of Linux around now too). Rather than go through the hassle of having the guy try to figure out OS/2, we just rigged up a temporary Windows box and let him have his fun. Soon as he'd left, we unplugged the network cable from that machine and plugged it into our router (and then did a MAC address clone in the router, as for some reason the device was set to accept traffic only from the NIC the tech had installed). Funny, though, that Linux is still able to be obscure. ChrisA From tjreedy at udel.edu Wed Mar 6 18:50:35 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 18:50:35 -0500 Subject: Do you feel bad because of the Python docs? In-Reply-To: <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> Message-ID: On 3/6/2013 2:48 PM, rh wrote: >> I've tried twice to register with the bug tracker -- including >> just before sending this post. Both times I got something like >> this: >> >> Subject: Failed issue tracker submission >> From: Python tracker >> Date: Wed, 06 Mar 2013 00:56:44 +0000 >> >> An unexpected error occurred during the processing >> of your message. The tracker administrator is being >> notified. >> >> So, it's not all that easy to report bugs for me, anyway. I'd >> given up, prior, but reading this thread I thought I'd try one >> more time. >> >> I had wanted to report doc bugs, too, as I used to do copy and >> line editing. I seem to be able to find typos and such rather >> easily, but reporting said bugs -- not so easy. From http://docs.python.org/3/bugs.html "Documentation bugs If you find a bug in this documentation or would like to propose an improvement, please send an e-mail to docs at python.org describing the bug and where you found it. If you have a suggestion how to fix it, include that as well. docs at python.org is a mailing list run by volunteers; your request will be noticed, even if it takes a while to be processed." For anything more than trivial changes (typos, grammar errors), a tracker issue is better. But the above is better than nothing. -- Terry Jan Reedy From rantingrickjohnson at gmail.com Wed Mar 6 19:47:33 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 16:47:33 -0800 (PST) Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> Message-ID: <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> On Wednesday, March 6, 2013 5:50:35 PM UTC-6, Terry Reedy wrote: > If you find a bug in this documentation or would like to propose an > improvement, please send an e-mail to docs at python.org describing the bug > and where you found it. If you have a suggestion how to fix it, include > that as well. That's great Terry, but how will the next person find the link? I went to Python.org and i did not see it on the home page, nor the doc page... and i've been Python-ing for years now! If i can't find the link, how will a noob find it? How much longer are we going to "treat the symptoms" before we realize that we're dealing with a disease that can be cured? From wuwei23 at gmail.com Wed Mar 6 20:06:56 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 6 Mar 2013 17:06:56 -0800 (PST) Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> Message-ID: <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> On Mar 7, 10:47?am, Rick Johnson wrote: > That's great Terry, but how will the next person find the link? Why do you have such a low opinion of others that you think they're unable to look up "Reporting Bugs" in the _documentation_? From ckaynor at zindagigames.com Wed Mar 6 20:28:10 2013 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 6 Mar 2013 17:28:10 -0800 Subject: Do you feel bad because of the Python docs? In-Reply-To: <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> Message-ID: I actually just tried that, and the results weren't very good. Using the doc's search feature, the "Reporting Bugs" (and the "About these documents") page was significantly down the page (about 2/3 of the way) - not the most obvious result in the pile. All the other searches I could think of either didn't return either of those pages at all, or they were also 1/2-2/3 of the way down the page. The link is also on the main documentation page, but it is, again, near the bottom, making it hidden from many users. Both of them show up just above the bottom of the window with it maximized on my screen. The first of the issues may be difficult to fix, but would likely be fairly useful - that would generally be my first port of call. The second one is more minor as most people will scroll down to see whats farther down, if they go to the main page to find the links. Chris On Wed, Mar 6, 2013 at 5:06 PM, alex23 wrote: > On Mar 7, 10:47 am, Rick Johnson wrote: > > That's great Terry, but how will the next person find the link? > > Why do you have such a low opinion of others that you think they're > unable to look up "Reporting Bugs" in the _documentation_? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmx at ross.cx Wed Mar 6 21:04:29 2013 From: gmx at ross.cx (Michael Ross) Date: Thu, 07 Mar 2013 03:04:29 +0100 Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> Message-ID: On Thu, 07 Mar 2013 02:28:10 +0100, Chris Kaynor wrote: > I actually just tried that, and the results weren't very good. > > Using the doc's search feature, the "Reporting Bugs" (and the "About > these documents") page >was significantly down the page (about 2/3 of > the way) - not the most obvious result in the pile. All the >other > searches I could think of either didn't return either of those pages at > all, or they were also 1/2-2/3 >of the way down the page. > > Using Google it took me about 3 seconds to find the page. "python report doc bug". Works with Bing or DuckDuckGo too. First hit on either engine. The doc's search is ... fine if I search for e. g. 'subprocess.Popen', but near-useless for general searches. > > The link is also on the main documentation page, but it is, again, near > the bottom, making it hidden from >many users. Both of them show up just > above the bottom of the window with it maximized on my screen. > > > > The first of the issues may be difficult to fix, Is it? You'd just have to have an additional search box labeld "search whole page with google/bing/whatever" (?) > but would likely be fairly useful - that would generally be my first > port of call. The second one is more >minor as most people will scroll > down to see whats farther down, if they go to the main page to find the > >links. > > > > Chris > > > > On Wed, Mar 6, 2013 at 5:06 PM, alex23 wrote: >> >> >> On Mar 7, 10:47 am, Rick Johnson wrote: >> >>> That's great Terry, but how will the next person find the link? >> >> >> >> Why do you have such a low opinion of others that you think they're >> >> unable to look up "Reporting Bugs" in the _documentation_? >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> > From rantingrickjohnson at gmail.com Wed Mar 6 20:31:43 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 17:31:43 -0800 (PST) Subject: Do you feel bad because of the Python docs? In-Reply-To: <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> Message-ID: On Wednesday, March 6, 2013 7:06:56 PM UTC-6, alex23 wrote: > Why do you have such a low opinion of others that you think they're > unable to look up "Reporting Bugs" in the _documentation_? I don't have a low opinion of anybody here. However the fact that this community needs an entry level path for bug/grievance reports is *glaringly* obvious. It would greatly benefit this community by: 1. Removing excess chatter from the bug tracker. We need to keep the tracker folks focused on *real* bugs that can be patched. Not engaged in endless discussions on the semantics of "what is a bug" and what "IS NOT a bug". 2. Removing barriers to reporting bugs/grievances. Remember, if reporting issues is too difficult, people will just give up. Then, the next person who gets slammed with the same problem will go through the same trouble only to produce no results AGAIN. Rinse and repeat! 3. Give us insight as to what aspects of the language/docs are troubling for folks. We need to know where the bottle necks are when learning the language, and since we are experienced, we lack the noob insight to even see the problems. I'll bet $100 you hated writing self as the first argument to each method. But now you've become so accustomed that you could so it in your sleep. That does not validate the asininity of doing such a thing! How can we fix entry-level problems if we DON'T KNOW WHAT THE PROBLEMS ARE! 4. Create a *real* sense of community. By creating a place for people to voice complaints, we are letting them know that "Hey, you opinion is important to us, even if you are a total NOOB!". Even if their "pet problem" is never solved (maybe because it was a misunderstanding all along), they are more likely to get involved more deeply in Python community later on. Heck, maybe they will work their way up to py-dev and rub shoulders with GvR one day, "the skys the limit"! I have already offered my assistance managing such a list. But i cannot start such a list without wide community support; I cannot start the list without GvR publicly supporting it; I cannot start the list without a prominent link on python.org; because if i do start a list without all these things, i will be wasting my time. From wuwei23 at gmail.com Wed Mar 6 21:28:42 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 6 Mar 2013 18:28:42 -0800 (PST) Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> Message-ID: <99d379b6-2d51-4b97-b5c7-d4db4481e129@hd10g2000pbc.googlegroups.com> On Mar 7, 11:31?am, Rick Johnson wrote: > I don't have a low opinion of anybody here. However the fact that > this community needs an entry level path for bug/grievance reports > is *glaringly* obvious. Please explain how finding your vanity list would be easier than reading the Python doc's table of contents and clicking on the entry "Reporting Bugs". From rantingrickjohnson at gmail.com Wed Mar 6 21:57:27 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 18:57:27 -0800 (PST) Subject: Do you feel bad because of the Python docs? In-Reply-To: <99d379b6-2d51-4b97-b5c7-d4db4481e129@hd10g2000pbc.googlegroups.com> References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> <99d379b6-2d51-4b97-b5c7-d4db4481e129@hd10g2000pbc.googlegroups.com> Message-ID: <4c4592aa-91a5-4562-861e-36624cac2eeb@googlegroups.com> On Wednesday, March 6, 2013 8:28:42 PM UTC-6, alex23 wrote: > On Mar 7, 11:31 am, Rick Johnson wrote: > > I don't have a low opinion of anybody here. However the fact that > > this community needs an entry level path for bug/grievance reports > > is *glaringly* obvious. > > Please explain how finding your vanity list would be easier than > reading the Python doc's table of contents and clicking on the entry > "Reporting Bugs". Firstly: It's not a "Rick's Vanity List" unless my name is on it. I don't expect to be named the "BDFL of PyWarts". Heck, i don't even expect to be "named" at all. GvR DOES NOT need to mention my name. All i am asking is that he show some support for the general *idea* of "lowering the bar for bug/grievance reporting". Or at least start by admitting we have a problem. Secondly: The "report bugs" feature of the doc is more concerned with "doc related" bugs. I want a holistic approach that will invite ALL Python related issues (docs, language, community, modules, 3rd party modules, etc...) to follow a linear path. There may be better ways of achieving my goals (f.e. Terry proposed a great idea). My point is that we need to lower the bar and try to integrate a linear path that will allow all levels of Python programmers to participate. From wuwei23 at gmail.com Wed Mar 6 22:12:37 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 6 Mar 2013 19:12:37 -0800 (PST) Subject: Do you feel bad because of the Python docs? References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> <99d379b6-2d51-4b97-b5c7-d4db4481e129@hd10g2000pbc.googlegroups.com> <4c4592aa-91a5-4562-861e-36624cac2eeb@googlegroups.com> Message-ID: On Mar 7, 12:57?pm, Rick Johnson wrote: > GvR DOES NOT need to mention my name. All i am asking is that he show > some support for the general *idea* of "lowering the bar for bug/grievance > reporting". Or at least start by admitting we have a problem. Your obsession with Guido is tiring. Open source is not a cult of personality. It's about doing what you can where you can when you can to make things better. Insisting that he "endorse" your ideas is ridiculous. > Secondly: The "report bugs" feature of the doc is more concerned with > "doc related" bugs. It would really help your arguments if you actually spent some time investigating the issues you're ranting against: http://docs.python.org/3/bugs.html Documentation bugs are a brief paragraph at the top of the page, the rest of which addresses bugs with the language & standard library. > I want a holistic approach that will invite ALL Python related issues (docs, > language, community, modules, 3rd party modules, etc...) to follow a linear path. Third party modules will never be handled by the Python bug tracker, nor should they be lumped into the same "path"; they're the concern of their developers who shouldn't be bound by your desire for a One True Way. Community "bugs" should be addressed on the python list. > My point is that we You keep saying "we" when you mean other people apart from yourself. If you have ideas for improvement, _then implement them_. The crate.io guys didn't wait for community validation to address what they perceived were issues with PyPI, they rolled up their sleeves and did something about it. From rantingrickjohnson at gmail.com Wed Mar 6 22:48:52 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 19:48:52 -0800 (PST) Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> <99d379b6-2d51-4b97-b5c7-d4db4481e129@hd10g2000pbc.googlegroups.com> <4c4592aa-91a5-4562-861e-36624cac2eeb@googlegroups.com> Message-ID: <48055f42-6cdd-4f97-a4e2-a7b09f9cc4a3@googlegroups.com> On Wednesday, March 6, 2013 9:12:37 PM UTC-6, alex23 wrote: > Your obsession with Guido is tiring. And your false accusations that i am somehow "obsessed" with GvR have BEEN tiring for quite some time! I am neither passionate for or prejudice against the man. I simple ask that he live up to his job title. > Open source is not a cult of > personality. It's about doing what you can where you can when you can > to make things better. Insisting that he "endorse" your ideas is > ridiculous. Of course insisting that he validate me *personally* would be ridiculous. But i am NOT suggesting that he validate ME, i am suggesting that he do his job. And his job is to oversee the language evolution and maintain a sense of community. Specifically: "leading by example". Q: "Why even have a python-list if GvR and all the "heavies" at py-dev never participate in the conversations?" By NOT participating they are speaking louder than words. > Third party modules will never be handled by the Python bug tracker, > nor should they be lumped into the same "path"; they're the concern of > their developers I agree, that was an unfortunate typo. > If you have ideas for improvement, _then implement them_. The crate.io > guys didn't wait for community validation to address what they > perceived were issues with PyPI, they rolled up their sleeves and did > something about it. Great, and i commend the contribution. But is yet ANOTHER Python package list going to help anyone? How about 10 or 20 more Python package indexes? Community fragmentation and language forks due to core-dev stubbornness is unfortunate. I would much rather had them contribute to the existing package index instead of creating a new one. Congratulations Alex, your solution of pushing everyone away is working flawlessly -- just don't be surprised when you find yourself cold and alone. From rosuav at gmail.com Wed Mar 6 21:16:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 13:16:53 +1100 Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> <857d97ed-7c86-43c9-9751-9728652ac122@hd10g2000pbc.googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 12:31 PM, Rick Johnson wrote: > We need to know where the bottle necks are when learning the language, and since we are experienced, we lack the noob insight to even see the problems. I'll bet $100 you hated writing self as the first argument to each method. But now you've become so accustomed that you could so it in your sleep. Gambling debts are due within twenty-four hours. Please remit that hundred dollars immediately; I had absolutely no problem with the explicit 'self' argument. Thanks, it's about time I earned some money arguing with you. ChrisA From tjreedy at udel.edu Wed Mar 6 20:52:59 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 20:52:59 -0500 Subject: Do you feel bad because of the Python docs? In-Reply-To: <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> Message-ID: On 3/6/2013 7:47 PM, Rick Johnson wrote: > On Wednesday, March 6, 2013 5:50:35 PM UTC-6, Terry Reedy wrote: > >> If you find a bug in this documentation or would like to propose an >> improvement, please send an e-mail to docs at python.org describing the bug >> and where you found it. If you have a suggestion how to fix it, include >> that as well. > > That's great Terry, but how will the next person find the link? The same way I did. Go to http://docs.python.org/3/ (or /2/ and click on Reporting bugs, which takes one to the above and more. > I went to Python.org and i did not see it on the home page, nor the doc page... Which doc page? > How much longer are we going to "treat the symptoms" We would VERY MUCH like a system to make it easier for readers to report doc bugs and developers to fix them. No one yet has come up with both a reasonable idea and workable implementation. Here is an idea I just came up with. *Someone* writes javascript that allows the following: Reader using the web version sees a mistake, selects some text with the mistake, right clicks, selects 'Suggest correction', gets a box or form with the selected text, page and location or context info, and a text entry box. Reader enters correction in text box and clicks OK. Message is emailed or posted to python.org. *Someone* writes a python script to process reports by generating a proposed patch for human review. -- Terry Jan Reedy From rantingrickjohnson at gmail.com Wed Mar 6 21:41:02 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 18:41:02 -0800 (PST) Subject: Do you feel bad because of the Python docs? In-Reply-To: References: <512cb0a0$0$30001$c3e8da3$5496439d@news.astraweb.com> <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <2d3eea1e-db12-4448-80b3-2743866a2d42@googlegroups.com> Message-ID: On Wednesday, March 6, 2013 7:52:59 PM UTC-6, Terry Reedy wrote: > > How much longer are we going to "treat the symptoms" > > We would VERY MUCH like a system to make it easier for readers to report > doc bugs and developers to fix them. No one yet has come up with both a > reasonable idea and workable implementation. Here is an idea I just came > up with. > > *Someone* writes javascript that allows the following: Reader using the > web version sees a mistake, selects some text with the mistake, right > clicks, selects 'Suggest correction', gets a box or form with the > selected text, page and location or context info, and a text entry box. > Reader enters correction in text box and clicks OK. Message is emailed > or posted to python.org. YES, YES, YES! This is even better than "PyWarts" because the user will not need to log onto a forum and then compose a post. In effect, the forum will come to him! I love it! However, there is a dark-side on the opposite side of this mountain. Your idea solves "doc related" issues, but what about "language related" issues? I still love your idea, however, i am looking for a holistic approach to solving the issue. > *Someone* writes a python script to process reports by generating a > proposed patch for human review. Also, i would like to add. That all user submitted "reports" should be posted in a searchable database somewhere that is public; so we can keep track of which parts of the docs (or language) are creating the highest volume of complaints\bugs. From invalid at invalid.invalid Fri Mar 8 23:12:38 2013 From: invalid at invalid.invalid (Bob Hanson) Date: Fri, 08 Mar 2013 20:12:38 -0800 Subject: Do you feel bad because of the Python docs? References: <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> Message-ID: <3cblj891u465s49s08doriof23udqlr0ai@4ax.com> On Wed, 06 Mar 2013 18:50:35 -0500, Terry Reedy wrote: > On 3/6/2013 2:48 PM, rh wrote: > > > [Bob Hanson wrote:] > > > > > I've tried twice to register with the bug tracker -- including > > > just before sending this post. [...] > > > > > > [other details and errors snipped] > > > > > > I had wanted to report doc bugs, too, as I used to do copy and > > > line editing. I seem to be able to find typos and such rather > > > easily, but reporting said bugs -- not so easy. > > From http://docs.python.org/3/bugs.html > > "Documentation bugs > > If you find a bug in this documentation or would like to propose an > improvement, please send an e-mail to docs at python.org describing the bug > and where you found it. If you have a suggestion how to fix it, include > that as well. > > docs at python.org is a mailing list run by volunteers; your request will > be noticed, even if it takes a while to be processed." > > For anything more than trivial changes (typos, grammar errors), a > tracker issue is better. But the above is better than nothing. Thanks, Terry. I've been wanting to contribute for years, but a variety of issues (details of which are not relevant here) makes my helping improve the documentation probably the best fit for my abilities and situation. I do notice trivial changes, but I also feel some of the documentation could benefit from a much more thorough general editing to improve both ease of reading and general clarity. Contributing in this way sounds like I'll want to get more involved and probably do the contributor-signing thing and such -- or whatever steps I need to follow. And again, sorry for the late reply -- I was without internet for a few days while I changed ISPs. Regards, Bob Hanson -- Don't take yourself serious -- or no one else will. From tjreedy at udel.edu Sat Mar 9 01:22:39 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Mar 2013 01:22:39 -0500 Subject: Do you feel bad because of the Python docs? In-Reply-To: <3cblj891u465s49s08doriof23udqlr0ai@4ax.com> References: <57fd0b09-b30d-4e62-845a-aac198113a40@googlegroups.com> <54967758-e84c-4b9c-a09c-10fbdbec230f@googlegroups.com> <63b306c9-db6f-4c4c-b3c6-4c602ba31201@kt16g2000pbb.googlegroups.com> <20130306114842.c0da03f1ba6a3c99d429f3a8@lavabit.com> <3cblj891u465s49s08doriof23udqlr0ai@4ax.com> Message-ID: On 3/8/2013 11:12 PM, Bob Hanson wrote: > I do notice trivial changes, I am currently set up again to do doc changes, so if you already have some non-controversial changes to the *current* docs, the online html versions, go ahead and email them to me. > but I also feel some of the > documentation could benefit from a much more thorough general > editing to improve both ease of reading and general clarity. Big edits will need discussion on the tracker and will likely be opposed by someone. > Contributing in this way sounds like I'll want to get more > involved and probably do the contributor-signing thing and such > -- or whatever steps I need to follow. Please do the agreement thing now. We just added the e-form a week ago and with that are getting more serious about asking for the agreements. -- Terry Jan Reedy From mcepl at redhat.com Wed Mar 6 08:07:52 2013 From: mcepl at redhat.com (Matej Cepl) Date: Wed, 6 Mar 2013 14:07:52 +0100 Subject: Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial) In-Reply-To: References: Message-ID: <20130306130752.GA8554@wycliff.ceplovi.cz> On 2013-02-26, 16:25 GMT, Terry Reedy wrote: > On 2/21/2013 4:22 PM, Matej Cepl wrote: >> as my method to commemorate Aaron Swartz, I have decided to port his >> html2text to work fully with the latest python 3.3. After some time >> dealing with various bugs, I have now in my repo >> https://github.com/mcepl/html2text (branch python3) working solution >> which works all the way to python 3.2 (inclusive; >> https://travis-ci.org/mcepl/html2text). However, the last problem >> remains. This >> >>
  • Run this command: >>
    ls -l *.html
  • >>
  • ?
  • >> >> should lead to >> >> * Run this command: >> >> ls -l *.html >> >> * ? >> >> but it doesn?t. It leads to this (with python 3.3 only) >> >> * Run this command: >> ls -l *.html >> >> * ? >> >> Does anybody know about something which changed in modules re or >> http://docs.python.org/3.3/whatsnew/changelog.html between 3.2 and >> 3.3, which could influence this script? > > Search the changelob or 3.3 misc/News for items affecting those two > modules. There are at least 4. > http://docs.python.org/3.3/whatsnew/changelog.html > > It is faintly possible that the switch from narrow/wide builds to > unified builds somehow affected that. Have you tested with 2.7/3.2 on > both narrow and wide unicode builds? So, in the end, I have went the long way and bisected cpython to find the commit which broke my tests, and it seems that the culprit is http://hg.python.org/cpython/rev/123f2dc08b3e so it is clearly something Unicode related. Unfortunately, it really doesn't tell me what exactly is broken (is it a known regression) and if there is known workaround. Could anybody suggest a way how to find bugs on http://bugs.python.org related to some particular commit (plain search for 123f2dc0 didn?t find anything). Any thoughts? Mat?j P.S.: Crossposting to python-devel in hope there would be somebody understanding more about that particular commit. For that I have also intentionally not trim the original messages to preserve context. From solipsis at pitrou.net Fri Mar 1 09:54:14 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 14:54:14 +0000 (UTC) Subject: Writing to same file from two threads References: <7xliabvv4g.fsf@ruckus.brouhaha.com> <512ead61$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > On Wed, 27 Feb 2013 13:26:18 +0000, Antoine Pitrou wrote: > > > For the record, binary files are thread-safe in Python 3, but text files > > are not. > > Where is this documented please? In the documentation, of course ;) http://docs.python.org/3.3/library/io.html#multi-threading Regards Antoine. From rosuav at gmail.com Fri Mar 1 02:59:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Mar 2013 18:59:16 +1100 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: On Fri, Mar 1, 2013 at 6:50 PM, Morten Engvoldsen wrote: > Hi, > No i don't want user to blame when date is changed and serial number > reset when it should not. Do you think the following function will > help for this: > > import datetime as dt >>>> import pytz >>>> utc = pytz.timezone("UTC") >>>> norway = pytz.timezone("Europe/Norway") >>>> a = dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=utc) >>>> b = a.astimezone(norway) > > Your suggestion is really appreciated.. (posting reply on-list, hope that's okay!) That would be fine for the normal case. It's just possible that the user will change the computer's clock, which would result in the serial changing oddly. If that's not a problem to you, the job's done! ChrisA From mortenengv at gmail.com Fri Mar 1 04:42:36 2013 From: mortenengv at gmail.com (Morten Engvoldsen) Date: Fri, 1 Mar 2013 10:42:36 +0100 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: Hi, Thanks.. :) so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can compare the date.... ---------- Forwarded message ---------- From: Chris Angelico To: python-list at python.org Cc: Date: Fri, 1 Mar 2013 18:59:16 +1100 Subject: Re: Issue with continous incrementing of unbroken sequence for a entire working day On Fri, Mar 1, 2013 at 6:50 PM, Morten Engvoldsen wrote: > Hi, > No i don't want user to blame when date is changed and serial number > reset when it should not. Do you think the following function will > help for this: > > import datetime as dt >>>> import pytz >>>> utc = pytz.timezone("UTC") >>>> norway = pytz.timezone("Europe/Norway") >>>> a = dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=utc) >>>> b = a.astimezone(norway) > > Your suggestion is really appreciated.. (posting reply on-list, hope that's okay!) That would be fine for the normal case. It's just possible that the user will change the computer's clock, which would result in the serial changing oddly. If that's not a problem to you, the job's done! ChrisA From mortenengv at gmail.com Fri Mar 1 06:25:02 2013 From: mortenengv at gmail.com (Morten Engvoldsen) Date: Fri, 1 Mar 2013 12:25:02 +0100 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: Hi, I have wrote the below code for getting the serial number: look like i am able to get correct serial number: from datetime import date def read_data_file(): with open("workfile.txt", 'r') as f: for line in f.readlines(): read_data = line.split(' ') return read_data def write_data_file(data): fo = open("workfile.txt", "w") fo.write(str(data)) fo.close() def comput_date(read_date, now_time, read_serial): if read_date == now_time: read_serial = int(read_serial) return read_serial + 1 else: read_serial = 1 return read_serial def process_sales_record(): now_time = time.strftime("%d-%m-%y") readdata = read_data_file() if readdata: read_serial = readdata[0] read_date = readdata[1] copute_date = comput_date(read_date, now_time, read_serial) serial_number = copute_date print serial_number sales_recrod = {'record1':'product1', 'record2':'product2','record3':'product3'} for i in sales_recrod: print sales_recrod[i] serial_number += 1 print serial_number data = str(serial_number) + ' ' + now_time writedata = write_data_file(data) print readdata Kindly suggest how can i improve this code now.... or is it okey in this way.. On Fri, Mar 1, 2013 at 10:42 AM, Morten Engvoldsen wrote: > Hi, > Thanks.. :) > so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can > compare the date.... > > From mortenengv at gmail.com Fri Mar 1 11:31:19 2013 From: mortenengv at gmail.com (Morten Engvoldsen) Date: Fri, 1 Mar 2013 17:31:19 +0100 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: Hi, Yes, i think checking only date is sufficient . here is my code: from datetime import date def read_data_file(): with open("workfile.txt", 'r') as f: for line in f.readlines(): read_data = line.split(' ') return read_data def write_data_file(data): fo = open("workfile.txt", "w") fo.write(str(data)) fo.close() def comput_date(read_date, now_time, read_serial): if read_date == now_time: read_serial = int(read_serial) return read_serial + 1 else: read_serial = 1 return read_serial def process_sales_record(): now_time = time.strftime("%d-%m-%y") readdata = read_data_file() if readdata: read_serial = readdata[0] read_date = readdata[1] copute_date = comput_date(read_date, now_time, read_serial) serial_number = copute_date print serial_number sales_recrod = {'record1':'product1', 'record2':'product2','record3':'product3'} for i in sales_recrod: print sales_recrod[i] serial_number += 1 print serial_number data = str(serial_number) + ' ' + now_time writedata = write_data_file(data) print readdata Can you give me suggestion how can i improve this code.... ---------- Forwarded message ---------- From: MRAB To: python-list at python.org Cc: Date: Fri, 01 Mar 2013 14:09:43 +0000 Subject: Re: Issue with continous incrementing of unbroken sequence for a entire working day On 2013-03-01 09:42, Morten Engvoldsen wrote: Hi, Thanks.. :) so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can compare the date.... I think you're only interested in the date, not the time of day: time.strftime("%d-%m-%y") From mortenengv at gmail.com Sat Mar 2 16:20:16 2013 From: mortenengv at gmail.com (Morten Engvoldsen) Date: Sat, 2 Mar 2013 22:20:16 +0100 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: Hi, Thanks to all.. this is great forum with so many good people. I have learnt a lot of Python from this forum. Hope one day i will learn enough that i can start answering in this forum.. :) Thanks again.. From python at mrabarnett.plus.com Fri Mar 1 09:09:43 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Mar 2013 14:09:43 +0000 Subject: Issue with continous incrementing of unbroken sequence for a entire working day In-Reply-To: References: Message-ID: <5130B6A7.6030701@mrabarnett.plus.com> On 2013-03-01 09:42, Morten Engvoldsen wrote: > Hi, > Thanks.. :) > so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can > compare the date.... > I think you're only interested in the date, not the time of day: time.strftime("%d-%m-%y") From solipsis at pitrou.net Fri Mar 1 14:10:53 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 19:10:53 +0000 (UTC) Subject: Speeding up Python's exit References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Grant Edwards invalid.invalid> writes: > > > I assume that the memory used by the Python process will be reclaimed > > by the operating system, but other resources such as opened files may > > not be. > > All open files (including sockets, pipes, serial ports, etc) will be > flushed (from an OS standpoint) and closed. According to POSIX, no, open files will not be flushed: ?The _Exit() and _exit() functions shall not call functions registered with atexit() nor any registered signal handlers. Open streams shall not be flushed. Whether open streams are closed (without flushing) is implementation-defined.? http://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html (under the hood, os._exit() calls C _exit()) Regards Antoine. From davea at davea.name Fri Mar 1 14:17:37 2013 From: davea at davea.name (Dave Angel) Date: Fri, 01 Mar 2013 14:17:37 -0500 Subject: Speeding up Python's exit In-Reply-To: References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5130FED1.6060302@davea.name> On 03/01/2013 02:10 PM, Antoine Pitrou wrote: > Grant Edwards invalid.invalid> writes: >> >> All open files (including sockets, pipes, serial ports, etc) will be >> flushed (from an OS standpoint) and closed. > > According to POSIX, no, open files will not be flushed: > > ?The _Exit() and _exit() functions shall not call functions registered with > atexit() nor any registered signal handlers. Open streams shall not be flushed. > Whether open streams are closed (without flushing) is implementation-defined.? > Note he didn't say the python buffers would be flushed. It's the OS buffers that are flushed. -- DaveA From solipsis at pitrou.net Fri Mar 1 17:51:20 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 22:51:20 +0000 (UTC) Subject: Speeding up Python's exit References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> <5130FED1.6060302@davea.name> Message-ID: Dave Angel davea.name> writes: > > Note he didn't say the python buffers would be flushed. It's the OS > buffers that are flushed. Now please read my message again. The OS buffers are *not* flushed according to POSIX. From jason.swails at gmail.com Fri Mar 1 21:51:52 2013 From: jason.swails at gmail.com (Jason Swails) Date: Fri, 1 Mar 2013 21:51:52 -0500 Subject: Speeding up Python's exit In-Reply-To: References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> <5130FED1.6060302@davea.name> Message-ID: On Fri, Mar 1, 2013 at 5:51 PM, Antoine Pitrou wrote: > Dave Angel davea.name> writes: > > > > Note he didn't say the python buffers would be flushed. It's the OS > > buffers that are flushed. > > Now please read my message again. The OS buffers are *not* flushed > according > to POSIX. > I have observed this behavior on some Linux systems with a Fortran program that terminated abnormally (via a kill signal). Other Linux systems I've used appear to flush their file buffers to disk in the event of a kill signal, it really depends on the system. If a file object's destructor is not called when the Python interpreter exits and it's up to the OS to flush the file buffers to disk, you can't be sure that it will do so. And as Antoine pointed out, POSIX standard doesn't require that they do. All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Sun Mar 3 18:27:08 2013 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 03 Mar 2013 18:27:08 -0500 Subject: Speeding up Python's exit References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> <5130FED1.6060302@davea.name> Message-ID: Antoine Pitrou wrote: >Now please read my message again. The OS buffers are *not* flushed according >to POSIX. POSIX says open *streams* might not be flushed. POSIX streams are C FILE * streams and generally aren't regarded as being part of the OS. When you call os._exit() in a Python program any unwritten data still in Python's own file buffers will be lost. Any unwritten data still in the C library's FILE * buffers will be lost. Any data successfuly written through a POSIX file descriptor (eg. using the write() function) will not be lost becasue os._exit() was used. Note that this doesn't mean that OS buffers will flushed when os._exit() is called. Data that hasn't yet been physically written to disk, hasn't be successfully transmitted over the network, or otherwise hasn't been fully comitted could still be lost. However, exiting Python normally doesn't change this. Only the Python process's own internal buffers are flushed, the OS doesn't change its handling of its buffers. If you want written data to be fully committed before exiting you need to use other OS services that guarantee this. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From solipsis at pitrou.net Fri Mar 1 09:59:29 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 14:59:29 +0000 (UTC) Subject: Speeding up Python's exit References: <512f8aa9$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > I just quit an interactive session using Python 2.7 on Linux. It took in > excess of twelve minutes to exit, with the load average going well past 9 > for much of that time. > > I think the reason it took so long was that Python was garbage-collecting > a giant dict with 10 million entries, each one containing a list of the > form [1, [2, 3], 4]. But still, that's terribly slow -- ironically, it > took longer to dispose of the dict (12+ minutes) than it took to create > it in the first place (approx 3 minutes, with a maximum load of 4). > > Can anyone explain why this was so painfully slow, and what (if anything) > I can do to avoid it in the future? You are basically asking people to guess where your performance problem comes from, without even providing a snippet so that people can reproduce ;) > I know there is a function os._exit which effectively kills the Python > interpreter dead immediately, without doing any cleanup. What are the > consequences of doing this? I assume that the memory used by the Python > process will be reclaimed by the operating system, but other resources > such as opened files may not be. The OS always disposes of per-process resources when the process terminates (except if the OS is buggy ;-)). However, file buffers will not be flushed, atexit handlers and other destructors will not be called, database transactions will be abandoned (rolled back), etc. Regards Antoine. From softw.devl at gmail.com Fri Mar 1 09:41:50 2013 From: softw.devl at gmail.com (Melton Low (devl)) Date: Fri, 01 Mar 2013 07:41:50 -0700 Subject: =?UTF-8?B?W0FOTl3CoFB5TGludCAwLjI3IC8gbG9naWxhYi1hc3RuZyAwLjI=?= =?UTF-8?B?NC4y?= In-Reply-To: <20130228173037.GB6949@logilab.fr> References: <20130228173037.GB6949@logilab.fr> Message-ID: <5130BE2E.3060209@gmail.com> Hi Sylvain, Clicking on the download linked from [1] below gives me an error. Same with logilab-astng link [2]. Not Found The requested URL /pub/pylint/pylint-0.27.0.tar.gz was not found on this server. Apache/2.2.16 (Debian) mod_ssl/2.2.16 OpenSSL/0.9.8o Server at download.logilab.org Port 80 Maybe I need to wait for the server to be updated? Any idea. Mel Sylvain Th?nault wrote: > Hi there, > > I'm very pleased to announce the release of pylint 0.27 [1] and > logilab-astng 0.24.2 [2] . There has been a lot of enhancements and > bug fixes since the latest release, so you're strongly encouraged > to upgrade. See ChangeLog for details. > > Many thanks to all the people who contributed to this release! > > [1] http://www.logilab.org/project/pylint/0.27.0 / > [2] http://www.logilab.org/project/logilab-astng/0.24.2 > > Enjoy! From sylvain.thenault at logilab.fr Mon Mar 4 03:53:37 2013 From: sylvain.thenault at logilab.fr (Sylvain =?utf-8?B?VGjDqW5hdWx0?=) Date: Mon, 4 Mar 2013 09:53:37 +0100 Subject: =?utf-8?B?W0FOTl3CoFB5TGlu?= =?utf-8?Q?t?= 0.27 / logilab-astng 0.24.2 In-Reply-To: <5130BE2E.3060209@gmail.com> References: <20130228173037.GB6949@logilab.fr> <5130BE2E.3060209@gmail.com> Message-ID: <20130304085337.GC2512@logilab.fr> On 01 mars 07:41, Melton Low (devl) wrote: > Hi Sylvain, Hi, > Clicking on the download linked from [1] below gives me an error. > Same with logilab-astng link [2]. > > Not Found > > The requested URL /pub/pylint/pylint-0.27.0.tar.gz was not found on > this server. > > Apache/2.2.16 (Debian) mod_ssl/2.2.16 OpenSSL/0.9.8o Server at > download.logilab.org Port 80 > > Maybe I need to wait for the server to be updated? sorry, I forgot a step. Fixed now. thx and sorry for the incovenience -- Sylvain Th?nault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42) Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations D?veloppement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org From maroso at libero.it Mon Mar 4 14:04:14 2013 From: maroso at libero.it (io) Date: 04 Mar 2013 19:04:14 GMT Subject: Read csv file and create a new file References: <512fac9c$0$40355$4fafbaef@reader1.news.tin.it> Message-ID: <5134f02e$0$40360$4fafbaef@reader1.news.tin.it> What you wrote seems interesting but i haven't understood. Can you explain in simple words considering i'm italian and i'm not understanding so well some terms you use. Sorry, i'm sure you are suggesting something really valid but can't understand it. Marco. From steve+comp.lang.python at pearwood.info Mon Mar 4 18:58:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2013 23:58:45 GMT Subject: Read csv file and create a new file References: <512fac9c$0$40355$4fafbaef@reader1.news.tin.it> <5134f02e$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <51353535$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 04 Mar 2013 19:04:14 +0000, io wrote: > What you wrote seems interesting but i haven't understood. Can you > explain in simple words considering i'm italian and i'm not > understanding so well some terms you use. Sorry, i'm sure you are > suggesting something really valid but can't understand it. > > Marco. Who are you talking to? Your reply has no context. When replying to a message, please quote enough of the previous message so that readers can understand what you are replying to. There is usually no need to quote the entire message. Often just a few lines is enough. If you spend some time reading other people's questions and answers, you will see what I mean. -- Steven From stefan_ml at behnel.de Fri Mar 1 02:48:34 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 01 Mar 2013 08:48:34 +0100 Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: <513024d5$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <513024d5$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 01.03.2013 04:47: > On Thu, 28 Feb 2013 22:03:09 +0100, Stefan Behnel wrote: > >> The most widely used static Python compiler is Cython > > Cython is not a Python compiler. Cython code will not run in a vanilla > Python implementation. It has different keywords and syntax, e.g.: > > cdef inline int func(double num): > ... > > which gives SyntaxError in a Python compiler. Including Cython, if you're compiling a ".py" file. The above is only valid syntax in ".pyx" files. Two languages, one compiler. Or three languages, if you want, because Cython supports both Python 2 and Python 3 code in separate compilation modes. The old model, which you might have learned at school: * a Python implementation is something that runs Python code * a Cython implementation is something that does not run Python code hasn't been generally true since, well, probably forever. Even Cython's predecessor Pyrex was capable of compiling a notable subset of Python code, and Cython has gained support for pretty much all Python language features about two years ago. Quoting the project homepage: "the Cython language is a superset of the Python language". http://cython.org/ If you don't believe that, just try it yourself. Try to compile some Python 3 code with it, if you find the time. Oh, and pass the "-3" option to the compiler in that case, so that it knows that it should switch to Python 3 syntax/semantics mode. It can't figure that out from the file extension (although you can supply the language level of the file in a header comment tag). And while you're at it, also pass the "-a" option to let it generate an HTML analysis of your code that highlights CPython interaction and thus potential areas for manual optimisation. The "superset" bit doesn't mean I've stopped fixing bugs from time to time that CPython's regression test suite reveals. If you want to get an idea of Cython's compatibility level, take a look at the test results, there are still about 470 failing tests left out of 26000 in the test suites of Py2.7 and 3.4: https://sage.math.washington.edu:8091/hudson/job/cython-devel-tests-pyregr/ One reason for a couple of those failures (definitely not all of them) is that Cython rejects some code at compile time that CPython only rejects at runtime. That's because the tests were explicitly written for CPython and assume that the runtime cannot detect some errors before executing the code. So, in a way, being capable of doing static analysis actually prevents Cython from being fully CPython compatible. I do not consider that a bad thing. And, BTW, we also compile most of Python's benchmark suite by now: https://sage.math.washington.edu:8091/hudson/view/bench/ The results are definitely not C-ishly fast, usually only some 10-80% improvement or so, e.g. only some 35% in the Django benchmark, but some of the results are quite ok for plain Python code that is not manually optimised for compilation. Remember, there are lots of optimisations that we deliberately do not apply, and static analysis generally cannot detect a lot of dynamic code patterns, runtime determined types, etc. That's clearly PyPy's domain, with its own set of pros and cons. The idea behind Cython is not that it will magically make your plain Python code incredibly fast. The idea is to make it really, really easy for users to bring their code up to C speed *themselves*, in the exact spots where the code really needs it. And yes, as was already mentioned in this thread, there is a pure Python mode for this that allows you to keep your code in plain Python syntax while optimising it for compilation. The "Cython optimised" benchmarks on the page above do exactly that. I wrote a half-rant about static Python compilation in a recent blog post. It's in English, and you might actually want to read it. I would say that I can claim to know what I'm talking about. http://blog.behnel.de/index.php?p=241 Stefan From steve+comp.lang.python at pearwood.info Fri Mar 1 20:49:40 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2013 01:49:40 GMT Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? References: <513024d5$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51315ab4$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Mar 2013 08:48:34 +0100, Stefan Behnel wrote: > Steven D'Aprano, 01.03.2013 04:47: >> On Thu, 28 Feb 2013 22:03:09 +0100, Stefan Behnel wrote: >> >>> The most widely used static Python compiler is Cython >> >> Cython is not a Python compiler. Cython code will not run in a vanilla >> Python implementation. It has different keywords and syntax, e.g.: >> >> cdef inline int func(double num): >> ... >> >> which gives SyntaxError in a Python compiler. > > Including Cython, if you're compiling a ".py" file. The above is only > valid syntax in ".pyx" files. Two languages, one compiler. Or three > languages, if you want, because Cython supports both Python 2 and Python > 3 code in separate compilation modes. Ah, that's very interesting, and thank you for the correction. I have re- set my thinking about Cython. -- Steven From dihedral88888 at googlemail.com Fri Mar 1 01:21:31 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 28 Feb 2013 22:21:31 -0800 (PST) Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: References: Message-ID: kramer65? 2013?3?1????UTC+8??4?25?07???? > Hello, > > > > I'm using Python for a while now and I love it. There is just one thing I cannot understand. There are compilers for languages like C and C++. why is it impossible to create a compiler that can compile Python code to machinecode? > > > > My reasoning is as follows: > > When GCC compiles a program written in C++, it simply takes that code and decides what instructions that would mean for the computer's hardware. What does the CPU need to do, what does the memory need to remember, etc. etc. If you can create this machinecode from C++, then I would suspect that it should also be possible to do this (without a C-step in between) for programs written in Python. > > > > Where is my reasoning wrong here? Is that because Python is dynamically typed? Does machinecode always need to know whether a variable is an int or a float? And if so, can't you build a compiler which creates machinecode that can handle both ints and floats in case of doubt? Or is it actually possible to do, but so much work that nobody does it? > > > > I googled around, and I *think* it is because of the dynamic typing, but I really don't understand why this would be an issue.. > > > > Any insights on this would be highly appreciated! I think a smart object can perform some experiments in its lifetime in sensing and collecting data to improve its methods in the long run. This will require a dynamical language definitely. From invalid at invalid.invalid Mon Mar 4 11:36:36 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 4 Mar 2013 16:36:36 +0000 (UTC) Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? References: Message-ID: On 2013-02-28, kramer65 wrote: > I'm using Python for a while now and I love it. There is just one > thing I cannot understand. There are compilers for languages like C > and C++. why is it impossible to create a compiler that can compile > Python code to machinecode? The main issue is that python has dynamic typing. The type of object that is referenced by a particular name can vary, and there's no way (in general) to know at compile time what the type of object "foo" is. That makes generating object code to manipulate "foo" very difficult. > My reasoning is as follows: When GCC compiles a program written in > C++, it simply takes that code and decides what instructions that > would mean for the computer's hardware. What does the CPU need to do, > what does the memory need to remember, etc. etc. If you can create > this machinecode from C++, then I would suspect that it should also > be possible to do this (without a C-step in between) for programs > written in Python. > > Where is my reasoning wrong here? Is that because Python is > dynamically typed? Yes. > Does machinecode always need to know whether a > variable is an int or a float? Yes. Not only might it be an int or a float, it might be a string, a list, a dictionary, a network socket, a file, or some user-defined object type that the compiler has no way of knowing about. > And if so, can't you build a compiler which creates machinecode that > can handle both ints and floats in case of doubt? That's pretty much what you've got now. The Python compiler compiles the source code as much as it can, and the VM is the "machinecode that can handle both ints and floats". > Or is it actually possible to do, but so much work that nobody does > it? > > I googled around, and I *think* it is because of the dynamic typing, > but I really don't understand why this would be an issue.. Can you explain how to generate machine code to handle any possible object type than any Python user might ever create? -- Grant Edwards grant.b.edwards Yow! for ARTIFICIAL at FLAVORING!! gmail.com From cmpython at gmail.com Mon Mar 4 17:55:06 2013 From: cmpython at gmail.com (CM) Date: Mon, 4 Mar 2013 14:55:06 -0800 (PST) Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? References: Message-ID: > The main issue is that python has dynamic typing. ?The type of object > that is referenced by a particular name can vary, and there's no way > (in general) to know at compile time what the type of object "foo" is. > > That makes generating object code to manipulate "foo" very difficult. Could you help me understand this better? For example, if you have this line in the Python program: foo = 'some text' bar = {'apple':'fruit'} If the interpreter can determine at runtime that foo is a string and bar is a dict, why can't the compiler figure that out at compile time? Or is the problem that if later in the program you have this line: foo = 12 now foo is referring to an integer object, not a string, and compilers can't have two names referring to two different types of objects? Something like that? I in no way doubt you that this is not possible, I just don't understand enough about how compiling works to yet "get" why dynamic typing is a problem for compilers. Thanks. From dihedral88888 at googlemail.com Mon Mar 4 18:12:07 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 4 Mar 2013 15:12:07 -0800 (PST) Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: References: Message-ID: <3447eb2a-892e-44cd-8136-2cda4d7165f5@googlegroups.com> On Tuesday, March 5, 2013 6:55:06 AM UTC+8, CM wrote: > > The main issue is that python has dynamic typing. ?The type of object > > > that is referenced by a particular name can vary, and there's no way > > > (in general) to know at compile time what the type of object "foo" is. > > > > > > That makes generating object code to manipulate "foo" very difficult. > > > > Could you help me understand this better? For example, if you > > have this line in the Python program: > > > > foo = 'some text' > > bar = {'apple':'fruit'} > > > > If the interpreter can determine at runtime that foo is a string > > and bar is a dict, why can't the compiler figure that out at > > compile time? Or is the problem that if later in the program > > you have this line: > > > > foo = 12 > > > > now foo is referring to an integer object, not a string, and > > compilers can't have two names referring to two different > > types of objects? Something like that? > > > > I in no way doubt you that this is not possible, I just don't > > understand enough about how compiling works to yet "get" > > why dynamic typing is a problem for compilers. > > > > Thanks. The dynamic type part is normally in the higher level components of objects and functions and generators. Of course if one can be sure of the types of variables used in some functions then that is the cython way to speed up pure OOP python programs in executions. From tjreedy at udel.edu Mon Mar 4 19:31:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Mar 2013 19:31:09 -0500 Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: References: Message-ID: On 3/4/2013 5:55 PM, CM wrote: > Could you help me understand this better? For example, if you > have this line in the Python program: > > foo = 'some text' > bar = {'apple':'fruit'} > > If the interpreter can determine at runtime that foo is a string > and bar is a dict, why can't the compiler figure that out at > compile time? Or is the problem that if later in the program > you have this line: > > foo = 12 > > now foo is referring to an integer object, not a string, and > compilers can't have two names referring to two different > types of objects? I believe you mean one name referring to multiple types. > Something like that? Something like that. In python, objects are strongly typed, names do not have types. Or if you prefer, names are typed according to their current binding, which can freely change. As for why this can be an advantage, consider this simple function. def min2(a, b): if a <= b: return a else: return b When the def statement is executed, the names 'a' and 'b' have no binding and therefore no type, not even a temporary type. In a statically typed language, either you or the compiler must rewrite that function for every pair of types that are ever input to min2. If the compiler does it, it either has to analyze an entire program, or it have to compile variations on the fly, as needed. The latter is what the psycho module, and, I believe, the pypy jit compiler does. -- Terry Jan Reedy From rosuav at gmail.com Mon Mar 4 19:33:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2013 11:33:47 +1100 Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: References: Message-ID: On Tue, Mar 5, 2013 at 9:55 AM, CM wrote: > >> The main issue is that python has dynamic typing. The type of object >> that is referenced by a particular name can vary, and there's no way >> (in general) to know at compile time what the type of object "foo" is. >> >> That makes generating object code to manipulate "foo" very difficult. > > Could you help me understand this better? For example, if you > have this line in the Python program: > > foo = 'some text' > bar = {'apple':'fruit'} > > If the interpreter can determine at runtime that foo is a string > and bar is a dict, why can't the compiler figure that out at > compile time? Or is the problem that if later in the program > you have this line: > > foo = 12 > > now foo is referring to an integer object, not a string, and > compilers can't have two names referring to two different > types of objects? Something like that? > > I in no way doubt you that this is not possible, I just don't > understand enough about how compiling works to yet "get" > why dynamic typing is a problem for compilers. Python doesn't have "variables" with "values"; it has names, which may (or may not) point to objects. Dynamic typing just means that one name is allowed to point to multiple different types of object at different times. The problem with dynamic typing is more one of polymorphism. Take this expression as an example: foo += bar; In C, the compiler knows the data types of the two variables, and can compile that to the appropriate code. If they're both integers, that'll possibly become a single machine instruction that adds two registers and stores the result back. In C++, foo could be a custom class with an operator+= function. The compiler will know, however, what function to call; unless it's a virtual function, in which case there's a run-time check to figure out what subclass foo is of, and then the function is called dynamically. In Python, *everything* is a subclass of PyObject, and every function call is virtual. That += operation is backed by the __iadd__ function, defined by PyObject and possibly overridden by whatever type foo is. So, at run time, the exact function is looked up. C++ is most definitely a compiled language, at least in most implementations I've seen. But it has the exact same issue as Python has: true dynamism requires run-time lookups. That's really what you're seeing here; it's nothing to do with any sort of "compiled" vs "interpreted" dichotomy, but with "compile time" vs "run time" lookups. In C, everything can be done at compile time; in Python, most things are done at run time. It's mainly a matter of degree. A more dynamic language needs to do more work at run time. ChrisA From benjamin.kaplan at case.edu Mon Mar 4 19:27:52 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 4 Mar 2013 16:27:52 -0800 Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? In-Reply-To: References: Message-ID: On Mar 4, 2013 3:02 PM, "CM" wrote: > > > > The main issue is that python has dynamic typing. The type of object > > that is referenced by a particular name can vary, and there's no way > > (in general) to know at compile time what the type of object "foo" is. > > > > That makes generating object code to manipulate "foo" very difficult. > > Could you help me understand this better? For example, if you > have this line in the Python program: > > foo = 'some text' > bar = {'apple':'fruit'} > > If the interpreter can determine at runtime that foo is a string > and bar is a dict, why can't the compiler figure that out at > compile time? Or is the problem that if later in the program > you have this line: > > foo = 12 > > now foo is referring to an integer object, not a string, and > compilers can't have two names referring to two different > types of objects? Something like that? > > I in no way doubt you that this is not possible, I just don't > understand enough about how compiling works to yet "get" > why dynamic typing is a problem for compilers. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list In the case of literals, the compiler can figure out type information (and I believe it does do some constant folding). But as soon as you let something else get in between you and the constant, you lose all guarantees. import random if random.random() <0.5 : spam = 3 else: spam = "hello world" Then you get into monkey patching and dealing with types that may not be defined at compile time. The only way a python compiler could convert that to x86 assembly is if generated code that would look up the type information at runtime. You'd basically be outputting a python interpreter. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Mar 4 20:35:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2013 01:35:34 GMT Subject: Why is it impossible to create a compiler than can compile Python to machinecode like C? References: Message-ID: <51354be6$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 04 Mar 2013 16:36:36 +0000, Grant Edwards wrote: > On 2013-02-28, kramer65 wrote: > >> I'm using Python for a while now and I love it. There is just one thing >> I cannot understand. There are compilers for languages like C and C++. >> why is it impossible to create a compiler that can compile Python code >> to machinecode? > > The main issue is that python has dynamic typing. The type of object > that is referenced by a particular name can vary, and there's no way (in > general) to know at compile time what the type of object "foo" is. > > That makes generating object code to manipulate "foo" very difficult. That's only a limitation with a static compiler that tries to generate fast machine code at compile time. A JIT compiler can generate fast machine code at runtime. The idea is that the time you save by running more optimized code is greater than the time it costs to generate that code each time you run. If not, then you just run the normal byte-code you would have run, and you've lost very little. This has been a very successful approach. Psyco worked very well, and it's successor PyPy seems to work even better. PyPy, on average, runs about 5-6 times faster than CPython, and for some tasks about 50 times faster. That makes it broadly speaking as fast as Java and approaching C, and even in some circumstances even beat static C compilers. (Admittedly only under very restrictive circumstances.) The downside is that JIT compilers need a lot of memory. To oversimplify, you might take source code like this: x = a + b A static compiler knows what types a and b are, and can turn it into a single fairly compact piece of machine code. Using my own crappy invented machine code notation: ADD a, b STORE x A JIT compiler has to generate a runtime check and one or more fast branches, plus a fallback: CASE (a and b are both ints): ADD a, b STORE x CASE (a and b are both strings): COPY a, x CONCATENATE b, x OTHERWISE: execute byte code to add two arbitrary objects The above is probably nothing like the way PyPy actually works. Anyone interested in how PyPy really works should spend some time reading their website and blog. http://pypy.org/ I can especially recommend this to give you a flavour for just how complicated this sort of thing can become: http://morepypy.blogspot.com.au/2011/01/loop-invariant-code-motion.html -- Steven From werner at thieprojects.ch Tue Mar 5 03:53:00 2013 From: werner at thieprojects.ch (Werner Thie) Date: Tue, 05 Mar 2013 09:53:00 +0100 Subject: Twisted or Tornado? In-Reply-To: <512FF8C5.3090209@gmail.com> References: <512FF8C5.3090209@gmail.com> Message-ID: <5135B26C.3020203@thieprojects.ch> Hi On 3/1/13 1:39 AM, Michael Torrie wrote: > On 02/28/2013 05:28 PM, Jake Angulo wrote: >> My requirements for this framework in descending order: 1) Easy to >> use API 2) Widely available documentation / Examples / Community >> contributions 3) Feature-wise - kinda most that you commonly need is >> there I'm happy with twisted programming browser based multi-player games for several years now. I wouldn't say that the learning curve was steep, rather the opposite, but the gain from a clean async programming model as it is implemented in twisted really makes the difference for me, not only in writing games, but even more in maintaining them long term. It's also interesting to see, that this clean async model of twisted and its host of already provided protocols allowed me to implement solutions in notoriously problematic areas like overall stability, fault tolerance, load induced behavior, server analysis, multicore/multimachine capabilities and hot deployment with ease. Cheers, Werner From svenito at gmail.com Fri Mar 1 04:25:43 2013 From: svenito at gmail.com (Sven) Date: Fri, 1 Mar 2013 09:25:43 +0000 Subject: Twisted or Tornado? In-Reply-To: References: Message-ID: Although these articles are a _little_ old they are probably useful to help you decide which solution is most suitable for you in terms of performance http://nichol.as/benchmark-of-python-web-servers http://nichol.as/asynchronous-servers-in-python I would also be interested if any one on this list has any idea if the results above would be any different these days or whether the benchmarks are still fairly representative. On 1 March 2013 00:28, Jake Angulo wrote: > I have to say it first: I am not trolling :P > > Im working on a server project (with IOS client) and would like to create > a custom, lean and mean server - real Quick! > > My requirements for this framework in descending order: > 1) Easy to use API > 2) Widely available documentation / Examples / Community contributions > 3) Feature-wise - kinda most that you commonly need is there > > Your opinions will be valuable, if possible cite examples or URL > references, Pls! > > I prefer opinion from those who have programmed real projects in it - not > just read some blog or Slashdot :P > -- > http://mail.python.org/mailman/listinfo/python-list > -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From andriy.kornatskyy at live.com Fri Mar 1 04:55:35 2013 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Fri, 1 Mar 2013 12:55:35 +0300 Subject: Twisted or Tornado? In-Reply-To: References: , Message-ID: The following benchmarks are related to: a) python web frameworks http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html http://mindref.blogspot.com/2012/10/python-web-reverse-urls-benchmark.html http://mindref.blogspot.com/2012/10/python-web-caching-benchmark.html b) template engines http://mindref.blogspot.com/2012/10/python-templates-benchmark.html http://mindref.blogspot.com/2012/07/python-fastest-template.html With source code: https://bitbucket.org/akorn/helloworld Thanks. Andriy Kornatskyy ________________________________ > Date: Fri, 1 Mar 2013 09:25:43 +0000 > Subject: Re: Twisted or Tornado? > From: svenito at gmail.com > To: jake.angulo at gmail.com > CC: python-list at python.org > > Although these articles are a _little_ old they are probably useful to > help you decide which solution is most suitable for you in terms of > performance > > http://nichol.as/benchmark-of-python-web-servers > http://nichol.as/asynchronous-servers-in-python > > I would also be interested if any one on this list has any idea if the > results above would be any different these days or whether the > benchmarks are still fairly representative. > > > On 1 March 2013 00:28, Jake Angulo > > wrote: > I have to say it first: I am not trolling :P > > Im working on a server project (with IOS client) and would like to > create a custom, lean and mean server - real Quick! > > My requirements for this framework in descending order: > 1) Easy to use API > 2) Widely available documentation / Examples / Community contributions > 3) Feature-wise - kinda most that you commonly need is there > > Your opinions will be valuable, if possible cite examples or URL > references, Pls! > > I prefer opinion from those who have programmed real projects in it - > not just read some blog or Slashdot :P > -- > http://mail.python.org/mailman/listinfo/python-list > > > > -- > ./Sven > > -- http://mail.python.org/mailman/listinfo/python-list From jake.angulo at gmail.com Sun Mar 3 18:35:41 2013 From: jake.angulo at gmail.com (Jake Angulo) Date: Mon, 4 Mar 2013 10:35:41 +1100 Subject: Twisted or Tornado? In-Reply-To: References: Message-ID: All, Thanks for your reply - I thought I would share the outcome of my choice: I have chosen to use twisted. The API is very decent to learn, though the clincher is theres huge community / docs, and many projects used on production. I was able to make a working project prototype in hours! Thanks to the large twisted library. Our project is an ipad multiplayer game, and we didnt want to use existing servers because we want to do things exactly as we wish. Rgds, Jake On Fri, Mar 1, 2013 at 8:55 PM, Andriy Kornatskyy < andriy.kornatskyy at live.com> wrote: > > The following benchmarks are related to: > > a) python web frameworks > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html > http://mindref.blogspot.com/2012/10/python-web-reverse-urls-benchmark.html > http://mindref.blogspot.com/2012/10/python-web-caching-benchmark.html > > b) template engines > http://mindref.blogspot.com/2012/10/python-templates-benchmark.html > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > With source code: > https://bitbucket.org/akorn/helloworld > > Thanks. > > Andriy Kornatskyy > > > ________________________________ > > Date: Fri, 1 Mar 2013 09:25:43 +0000 > > Subject: Re: Twisted or Tornado? > > From: svenito at gmail.com > > To: jake.angulo at gmail.com > > CC: python-list at python.org > > > > Although these articles are a _little_ old they are probably useful to > > help you decide which solution is most suitable for you in terms of > > performance > > > > http://nichol.as/benchmark-of-python-web-servers > > http://nichol.as/asynchronous-servers-in-python > > > > I would also be interested if any one on this list has any idea if the > > results above would be any different these days or whether the > > benchmarks are still fairly representative. > > > > > > On 1 March 2013 00:28, Jake Angulo > > > wrote: > > I have to say it first: I am not trolling :P > > > > Im working on a server project (with IOS client) and would like to > > create a custom, lean and mean server - real Quick! > > > > My requirements for this framework in descending order: > > 1) Easy to use API > > 2) Widely available documentation / Examples / Community contributions > > 3) Feature-wise - kinda most that you commonly need is there > > > > Your opinions will be valuable, if possible cite examples or URL > > references, Pls! > > > > I prefer opinion from those who have programmed real projects in it - > > not just read some blog or Slashdot :P > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > ./Sven > > > > -- http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Sun Mar 3 21:40:55 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Mar 2013 19:40:55 -0700 Subject: Twisted or Tornado? In-Reply-To: References: Message-ID: <513409B7.1010605@gmail.com> On 03/03/2013 04:35 PM, Jake Angulo wrote: > All, > > Thanks for your reply - I thought I would share the outcome of my choice: > > I have chosen to use twisted. The API is very decent to learn, though the > clincher is theres huge community / docs, and many projects used on > production. > > I was able to make a working project prototype in hours! > Thanks to the large twisted library. Sweet! Thanks for letting us know the outcome. I think that's one of the most rewarding things about working with Python (and it's many libraries, frameworks, and projects). It's so fast to get a prototype up and running. From andriy.kornatskyy at live.com Tue Mar 5 03:07:44 2013 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 5 Mar 2013 11:07:44 +0300 Subject: Twisted or Tornado? In-Reply-To: References: , , Message-ID: Jake, Don't you lock yourself in twisted application server only? I doubt you will be able easily migrate to WSGI compatible application server as your needs grow. Andriy ________________________________ > From: jake.angulo at gmail.com > Date: Mon, 4 Mar 2013 10:35:41 +1100 > Subject: Re: Twisted or Tornado? > To: andriy.kornatskyy at live.com > CC: svenito at gmail.com; python-list at python.org > > > All, > > Thanks for your reply - I thought I would share the outcome of my choice: > > I have chosen to use twisted. The API is very decent to learn, though > the clincher is theres huge community / docs, and many projects used on > production. > > I was able to make a working project prototype in hours! > Thanks to the large twisted library. > > Our project is an ipad multiplayer game, and we didnt want to use > existing servers because we want to do things exactly as we wish. > > Rgds, > > Jake > > On Fri, Mar 1, 2013 at 8:55 PM, Andriy Kornatskyy > > wrote: > > The following benchmarks are related to: > > a) python web frameworks > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html > http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html > http://mindref.blogspot.com/2012/10/python-web-reverse-urls-benchmark.html > http://mindref.blogspot.com/2012/10/python-web-caching-benchmark.html > > b) template engines > http://mindref.blogspot.com/2012/10/python-templates-benchmark.html > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > With source code: > https://bitbucket.org/akorn/helloworld > > Thanks. > > Andriy Kornatskyy > > > ________________________________ > > Date: Fri, 1 Mar 2013 09:25:43 +0000 > > Subject: Re: Twisted or Tornado? > > From: svenito at gmail.com > > To: jake.angulo at gmail.com > > CC: python-list at python.org > > > > Although these articles are a _little_ old they are probably useful to > > help you decide which solution is most suitable for you in terms of > > performance > > > > http://nichol.as/benchmark-of-python-web-servers > > http://nichol.as/asynchronous-servers-in-python > > > > I would also be interested if any one on this list has any idea if the > > results above would be any different these days or whether the > > benchmarks are still fairly representative. > > > > > > On 1 March 2013 00:28, Jake Angulo > > > >> > wrote: > > I have to say it first: I am not trolling :P > > > > Im working on a server project (with IOS client) and would like to > > create a custom, lean and mean server - real Quick! > > > > My requirements for this framework in descending order: > > 1) Easy to use API > > 2) Widely available documentation / Examples / Community contributions > > 3) Feature-wise - kinda most that you commonly need is there > > > > Your opinions will be valuable, if possible cite examples or URL > > references, Pls! > > > > I prefer opinion from those who have programmed real projects in it - > > not just read some blog or Slashdot :P > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > ./Sven > > > > -- http://mail.python.org/mailman/listinfo/python-list > > From system.healer at gmail.com Tue Mar 5 22:30:05 2013 From: system.healer at gmail.com (system.healer at gmail.com) Date: Tue, 5 Mar 2013 19:30:05 -0800 (PST) Subject: Twisted or Tornado? In-Reply-To: References: Message-ID: <626cc4fe-670c-4c78-9934-c7aabc4eeaae@googlegroups.com> Second on django. This'll do. https://bitbucket.org/jespern/django-piston/ Build whatever data models you want on the back-end and start spitting out JSON with a couple lines of code. Used this to build an IAP server for iOS apps. This one hasn't gone into production yet but I know of at least one high-profile platform developer that was using this same setup for years. On Thursday, February 28, 2013 4:28:52 PM UTC-8, Jake Angulo wrote: > I have to say it first: I am not trolling :P > > > > Im working on a server project (with IOS client) and would like to create a custom, lean and mean server - real Quick! > > > > My requirements for this framework in descending order: > > 1) Easy to use API > > 2) Widely available documentation / Examples / Community contributions > > 3) Feature-wise - kinda most that you commonly need is there > > > > Your opinions will be valuable, if possible cite examples or URL references, Pls! > > > > I prefer opinion from those who have programmed real projects in it - not just read some blog or Slashdot :P From timothy.crosley at gmail.com Fri Mar 1 15:02:35 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 1 Mar 2013 12:02:35 -0800 (PST) Subject: QT Inspired web development framework for python In-Reply-To: References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> Message-ID: <30ce9c5b-f601-4bb2-a6b5-5e908e091d44@googlegroups.com> Hi Michael, Thanks! Since it simply produces html it can integrate very cleanly with django, or Any other framework that allows returning raw html. To be more specific, in django withing a view function you can return a response object that contains the HTML produced by WebElements. In the future I plan on adding even more django integration For things such as ajax abstraction. The long term vision is to be able to create apps and widgets that will run on any python framework unmodified except for calls to the database etc. Timothy Thursday, February 28, 2013 11:43:04 PM UTC-5, Michael Torrie wrote: > On 02/28/2013 06:48 PM, timothy crosley wrote: > > > I've been working on a web development framework that integrates several popular QT features (such as a graphical template builder, signal / slots, ui's built by objects) for the last few years, and I was hoping that some people here might find it useful. > > > > > > If you are interested the main link for the widgets is http://www.webelements.in > > > and the link for the framework overall is http://www.webbot.ws > > > > Very professional-looking pages, I must say! > > > > How would your framework fit into a framework such as Django? In other > > words, could it be used as the "view" part of django? Or is it meant to > > completely replace a traditional web framework? From timothy.crosley at gmail.com Fri Mar 1 15:02:35 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 1 Mar 2013 12:02:35 -0800 (PST) Subject: QT Inspired web development framework for python In-Reply-To: References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> Message-ID: <30ce9c5b-f601-4bb2-a6b5-5e908e091d44@googlegroups.com> Hi Michael, Thanks! Since it simply produces html it can integrate very cleanly with django, or Any other framework that allows returning raw html. To be more specific, in django withing a view function you can return a response object that contains the HTML produced by WebElements. In the future I plan on adding even more django integration For things such as ajax abstraction. The long term vision is to be able to create apps and widgets that will run on any python framework unmodified except for calls to the database etc. Timothy Thursday, February 28, 2013 11:43:04 PM UTC-5, Michael Torrie wrote: > On 02/28/2013 06:48 PM, timothy crosley wrote: > > > I've been working on a web development framework that integrates several popular QT features (such as a graphical template builder, signal / slots, ui's built by objects) for the last few years, and I was hoping that some people here might find it useful. > > > > > > If you are interested the main link for the widgets is http://www.webelements.in > > > and the link for the framework overall is http://www.webbot.ws > > > > Very professional-looking pages, I must say! > > > > How would your framework fit into a framework such as Django? In other > > words, could it be used as the "view" part of django? Or is it meant to > > completely replace a traditional web framework? From ian.g.kelly at gmail.com Fri Mar 1 15:30:08 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Mar 2013 13:30:08 -0700 Subject: QT Inspired web development framework for python In-Reply-To: <30ce9c5b-f601-4bb2-a6b5-5e908e091d44@googlegroups.com> References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> <30ce9c5b-f601-4bb2-a6b5-5e908e091d44@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 1:02 PM, timothy crosley wrote: > Thanks! Since it simply produces html it can integrate very cleanly with django, or > Any other framework that allows returning raw html. To be more specific, in django withing a view function you can return a response object that contains the HTML produced by WebElements. In the future I plan on adding even more django integration Is the intention here that the Django view would invoke WebElements at run-time to generate the HTML, or might one use WebElements to pre-compile HTML and JS, which could then be processed through Django's template engine? From timothy.crosley at gmail.com Fri Mar 1 15:41:43 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 1 Mar 2013 12:41:43 -0800 (PST) Subject: QT Inspired web development framework for python In-Reply-To: References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> <30ce9c5b-f601-4bb2-a6b5-5e908e091d44@googlegroups.com> Message-ID: <41eb5329-204a-45a2-ad50-804eb8904591@googlegroups.com> Hi Ian, The intention would be to invoke WebElements at view run time, this way the developer can write code to interact with the elements and effect the produced HTML dynamically on every request Timothy From timothy.crosley at gmail.com Wed Mar 13 22:04:28 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Wed, 13 Mar 2013 19:04:28 -0700 (PDT) Subject: QT Inspired web development framework for python In-Reply-To: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> Message-ID: <08ce2e3f-b67b-4afd-b9c7-6dd644958387@googlegroups.com> I've added special hooks into the framework to make integration with Django projects fairly seemless, these are detailed under the django quick start guide: http://www.webbot.ws/QuickStartGuide I hope this addresses some of the questions that have come up here, Thanks! Timothy From timothy.crosley at gmail.com Thu Mar 21 02:21:08 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Wed, 20 Mar 2013 23:21:08 -0700 (PDT) Subject: QT Inspired web development framework for python In-Reply-To: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> References: <42b84618-14a2-4504-9a64-b6aca2260ecd@googlegroups.com> Message-ID: <5ca21856-246e-4ea1-a199-d87361b83958@googlegroups.com> I really hope I'm not beating a dead horse, but I'm still really hoping for some feedback (good or bad) for this toolset/framework - as I really think it could help other Pyhton developers out. To that end I've added some demos on the main website showing how it works in action, that will hopefully make it more obvious what the framework is about and it's advantages. These are available here: http://www.webbot.ws/Demos Thanks Again, Timothy From jeanmichel at sequans.com Fri Mar 1 05:19:22 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 1 Mar 2013 11:19:22 +0100 (CET) Subject: Store a variable permanently In-Reply-To: <8df443ef-9199-421d-b38a-56b60d04de75@googlegroups.com> Message-ID: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> ----- Original Message ----- > So i have a variable called funds that i want to store the value of > even after the program is exited. My funds variable holds the total > value of funds i have. I add a certain number of funds each time i > run the program by entering how much i want to add. How would i > store the funds variable to keep its value? > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I would serialize the data. http://docs.python.org/2/library/pickle.html funds=5 pickle.dump(funds, 'funds.pickle') # to reload funds: funds = pickle.load('funds.pickle') The good thing with pickle is that it serializes a lot of things, see the "What can be pickled" section of the doc. 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 torriem at gmail.com Fri Mar 1 09:42:38 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 01 Mar 2013 07:42:38 -0700 Subject: Store a variable permanently In-Reply-To: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> References: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> Message-ID: <5130BE5E.7040901@gmail.com> On 03/01/2013 03:19 AM, Jean-Michel Pichavant wrote: > I would serialize the data. > > http://docs.python.org/2/library/pickle.html > > funds=5 pickle.dump(funds, 'funds.pickle') > > # to reload funds: > > funds = pickle.load('funds.pickle') > > > The good thing with pickle is that it serializes a lot of things, see > the "What can be pickled" section of the doc. Another solution is to use a database system. Either SQLite (file-based) or something server-based like PosgreSQL or MariaDB. From steve+comp.lang.python at pearwood.info Fri Mar 1 20:43:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2013 01:43:51 GMT Subject: Store a variable permanently References: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> Message-ID: <51315957$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Mar 2013 07:42:38 -0700, Michael Torrie wrote: > Another solution is to use a database system. Either SQLite > (file-based) or something server-based like PosgreSQL or MariaDB. The data in this case is a single integer value. Installing and running a database for a single integer is like using a using a bulldozer for moving your keyboard half an inch to the left. -- Steven From modulok at gmail.com Fri Mar 1 20:56:53 2013 From: modulok at gmail.com (Modulok) Date: Fri, 1 Mar 2013 18:56:53 -0700 Subject: Store a variable permanently In-Reply-To: <51315957$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> <51315957$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Installing and running a database for a single integer is like using a >> using a bulldozer for moving your keyboard half an inch to the left. I'd like to see that sometime XD -Modulok- From roy at panix.com Fri Mar 1 20:55:56 2013 From: roy at panix.com (Roy Smith) Date: Fri, 01 Mar 2013 20:55:56 -0500 Subject: Store a variable permanently References: <2057374708.12517060.1362133162297.JavaMail.root@sequans.com> <51315957$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51315957$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Fri, 01 Mar 2013 07:42:38 -0700, Michael Torrie wrote: > > > Another solution is to use a database system. Either SQLite > > (file-based) or something server-based like PosgreSQL or MariaDB. > > The data in this case is a single integer value. Installing and running a > database for a single integer is like using a using a bulldozer for > moving your keyboard half an inch to the left. True, but it's worth pointing out that SQLite is such a small bulldozer that it could fit in your shirt pocket with room left over for a couple of pencils. From steve+comp.lang.python at pearwood.info Fri Mar 1 21:29:54 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2013 02:29:54 GMT Subject: Store a variable permanently References: Message-ID: <51316422$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Mar 2013 11:19:22 +0100, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> So i have a variable called funds that i want to store the value of >> even after the program is exited. My funds variable holds the total >> value of funds i have. I add a certain number of funds each time i run >> the program by entering how much i want to add. How would i store the >> funds variable to keep its value? -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > Hi, > > I would serialize the data. > > http://docs.python.org/2/library/pickle.html I don't think we should recommend to a newbie that they use pickle without even warning them that using pickle is insecure and dangerous if they are opening pickles from untrusted sources. But for a single int, pickle too is overkill, and a simple human-readable and writable file is probably all that is needed: def save_value(n, configfile='myconfig'): if n != int(n): raise ValueError('expected an int') with open(configfile, 'w') as f: f.write("value=%d" % n) def load_value(configfile='myconfig'): with open(configfile) as f: s = f.read().strip() a, b = s.split("=", 1) if a.strip() != "value": raise ValueError('invalid config file') return int(b) Untested but ought to work. -- Steven From jeanmichel at sequans.com Mon Mar 11 06:19:49 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 11 Mar 2013 11:19:49 +0100 (CET) Subject: Store a variable permanently In-Reply-To: <51316422$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <262802421.3291011.1362997189936.JavaMail.root@sequans.com> ----- Original Message ----- > On Fri, 01 Mar 2013 11:19:22 +0100, Jean-Michel Pichavant wrote: > > > ----- Original Message ----- > >> So i have a variable called funds that i want to store the value > >> of > >> even after the program is exited. My funds variable holds the > >> total > >> value of funds i have. I add a certain number of funds each time i > >> run > >> the program by entering how much i want to add. How would i store > >> the > >> funds variable to keep its value? -- > >> http://mail.python.org/mailman/listinfo/python-list > >> > >> > > Hi, > > > > I would serialize the data. > > > > http://docs.python.org/2/library/pickle.html > > > I don't think we should recommend to a newbie that they use pickle > without even warning them that using pickle is insecure and dangerous > if > they are opening pickles from untrusted sources. > > But for a single int, pickle too is overkill, and a simple > human-readable > and writable file is probably all that is needed: > > def save_value(n, configfile='myconfig'): > if n != int(n): > raise ValueError('expected an int') > with open(configfile, 'w') as f: > f.write("value=%d" % n) > > def load_value(configfile='myconfig'): > with open(configfile) as f: > s = f.read().strip() > a, b = s.split("=", 1) > if a.strip() != "value": > raise ValueError('invalid config file') > return int(b) > > > Untested but ought to work. > > > -- > Steven While your point about security is fair, the others aren't. Pickle uses by default an ascii representation of the data, it's readable and writeable. import pickle a = 758 pickle.dump(a, open('test.pickle', 'w')) !cat test.pickle I758 . I don't see how 1 line of code (+ the import) can be overkill versus the dozen untested lines you provide (I'm sure it's working, my point being pickle has already been tested). More importantly, if the code evolve and you need to store 2 integers, or a tuple or anything else that is pickable, it costs you 0 dev if you're using pickle. 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 steve+comp.lang.python at pearwood.info Tue Mar 12 06:17:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2013 10:17:47 GMT Subject: Store a variable permanently References: Message-ID: <513f00cb$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 11 Mar 2013 11:19:49 +0100, Jean-Michel Pichavant wrote: [...] > While your point about security is fair, the others aren't. Pickle uses > by default an ascii representation of the data, it's readable and > writeable. > > import pickle > a = 758 > pickle.dump(a, open('test.pickle', 'w')) > !cat test.pickle > I758 > . What is that? It's not Python code, !cat test.pickle gives a syntax error. By the way, you can dump pickles directly to a string, which may be more convenient for demonstration purposes: py> import pickle py> pickle.dumps(758) 'I758\n.' I take your point that a pickle of a simple int is relatively readable, although it does require care when editing. If you drop the dot, or the newline, or change the I to lowercase, or even merely add a space after the dot, bad things happen. But yes, I will concede that a single pickled int is relatively readable. But that certainly isn't always the case: py> pickle.dumps([]) '(lp0\n.' py> pickle.dumps([None]) '(lp0\nNa.' For even a *slightly* more complex example, the pickle turns into noise. > I don't see how 1 line of code (+ the import) can be overkill versus the > dozen untested lines you provide (I'm sure it's working, my point being > pickle has already been tested). Pickle is a big module, over 1400 lines, capable of serialising almost anything. It's a big, powerful hammer for cracking armour-plated coconuts. But a single int is pretty much a peanut. Compare pickle's 1400 lines with the dozen or so lines I provided. That is all that I meant by "overkill". > More importantly, if the code evolve > and you need to store 2 integers, or a tuple or anything else that is > pickable, it costs you 0 dev if you're using pickle. Sure. And once you move beyond a single value, the ability to call pickle "human readable and writable" decreases rapidly. Without using pickle, can you tell what this represents? ((dp0 S'y' p1 I3 sS'x' p2 I2 s(lp3 S'a' p4 aS'b' p5 aI23 tp6 . -- Steven From jeanmichel at sequans.com Tue Mar 12 07:54:11 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 12 Mar 2013 12:54:11 +0100 (CET) Subject: Store a variable permanently In-Reply-To: <513f00cb$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <373301812.3852787.1363089251400.JavaMail.root@sequans.com> ----- Original Message ----- > On Mon, 11 Mar 2013 11:19:49 +0100, Jean-Michel Pichavant wrote: > > [...] > > While your point about security is fair, the others aren't. Pickle > > uses > > by default an ascii representation of the data, it's readable and > > writeable. > > > > import pickle > > a = 758 > > pickle.dump(a, open('test.pickle', 'w')) > > !cat test.pickle > > I758 > > . > > > What is that? It's not Python code, !cat test.pickle gives a syntax > error. It's a IPython shell session, !cat test.pickle writes the content of that file to stdout. But I have the feeling you already know that ;) [snip] > Pickle is a big module, over 1400 lines, capable of serialising > almost > anything. It's a big, powerful hammer for cracking armour-plated > coconuts. But a single int is pretty much a peanut. Compare pickle's > 1400 > lines with the dozen or so lines I provided. That is all that I meant > by > "overkill". I would be surprised if the 1400 lines were used to dump an integer. Anyway who cares about the size of the module, a lot of people import sys and os while using only a very subset of it. And to reuse your analogy, there's nothing wrong cracking a peanut with a hammer as long as you have it in your hands and that it takes absolutely no effort, compared to building your own small peanut cracker. Trying to crack the peanut by landing an airplane on it, that would work *and* be "overkill". Now about analogies: http://www.linguistrix.com/blog/?p=456 Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From steve+comp.lang.python at pearwood.info Wed Mar 13 13:37:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2013 17:37:10 GMT Subject: Store a variable permanently References: Message-ID: <5140b946$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Mar 2013 12:54:11 +0100, Jean-Michel Pichavant wrote: >> > import pickle >> > a = 758 >> > pickle.dump(a, open('test.pickle', 'w')) >> > !cat test.pickle >> > I758 >> > . >> >> >> What is that? It's not Python code, !cat test.pickle gives a syntax >> error. > > It's a IPython shell session, !cat test.pickle writes the content of > that file to stdout. But I have the feeling you already know that ;) Actually, no, I don't use IPython and am not familiar with it. -- Steven From jeanmichel at sequans.com Wed Mar 13 14:47:26 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 13 Mar 2013 19:47:26 +0100 (CET) Subject: Store a variable permanently In-Reply-To: <5140b946$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2115327486.4580509.1363200446151.JavaMail.root@sequans.com> ----- Original Message ----- > On Tue, 12 Mar 2013 12:54:11 +0100, Jean-Michel Pichavant wrote: > > >> > import pickle > >> > a = 758 > >> > pickle.dump(a, open('test.pickle', 'w')) > >> > !cat test.pickle > >> > I758 > >> > . > >> > >> > >> What is that? It's not Python code, !cat test.pickle gives a > >> syntax > >> error. > > > > It's a IPython shell session, !cat test.pickle writes the content > > of > > that file to stdout. But I have the feeling you already know that > > ;) > > Actually, no, I don't use IPython and am not familiar with it. > > > -- > Steven Well, slightly off topic, but you should give it a try. It's the python shell, just better. 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 Wed Mar 13 20:22:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 11:22:51 +1100 Subject: Store a variable permanently In-Reply-To: <5140b946$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5140b946$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 14, 2013 at 4:37 AM, Steven D'Aprano wrote: > On Tue, 12 Mar 2013 12:54:11 +0100, Jean-Michel Pichavant wrote: > >>> > import pickle >>> > a = 758 >>> > pickle.dump(a, open('test.pickle', 'w')) >>> > !cat test.pickle >>> > I758 >>> > . >>> >>> >>> What is that? It's not Python code, !cat test.pickle gives a syntax >>> error. >> >> It's a IPython shell session, !cat test.pickle writes the content of >> that file to stdout. But I have the feeling you already know that ;) > > Actually, no, I don't use IPython and am not familiar with it. Neither do I, but it's fairly clear what it's trying to do :) But pickle.dumps achieves the same thing in a much better way (the repr() of a string is more useful here anyway). ChrisA From quintessenceanx at gmail.com Fri Mar 1 00:14:52 2013 From: quintessenceanx at gmail.com (Quintessence) Date: Thu, 28 Feb 2013 21:14:52 -0800 (PST) Subject: Having problems crashing IDLE Message-ID: <840c99d3-9b9c-4f53-b9fa-73b8544a557c@googlegroups.com> I've been learning Python over the past week or so and I keep running into an issue where opening saved files will crash IDLE (not consistently, sometimes the same files with no changes will open and sometimes not). I was originally running Python 3.2.3, but I removed it and upgraded to 3.3.0 hoping to resolve the issue (but to no avail). While troubleshooting, someone suggested I try opening IDLE via command prompt. When I do that IDLE never crashes, but It does show this error (screenshot): http://i.imgur.com/1JqiRsY.png (3.2.3) http://i.imgur.com/5KxE88K.png (3.3.0) Some additional info: - When IDLE crashes it does not display an error, every open window simply closes. - IDLE has never crashed after opening a file when I open it via command prompt, even if it was previously consistently displaying that behavior. - I am running Windows 7 x64 with all updates. Has anyone ever encountered this? What does the error mean? From __peter__ at web.de Fri Mar 1 03:00:40 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Mar 2013 09:00:40 +0100 Subject: Having problems crashing IDLE References: <840c99d3-9b9c-4f53-b9fa-73b8544a557c@googlegroups.com> Message-ID: Quintessence wrote: > I've been learning Python over the past week or so and I keep running into > an issue where opening saved files will crash IDLE (not consistently, > sometimes the same files with no changes will open and sometimes not). I > was originally running Python 3.2.3, but I removed it and upgraded to > 3.3.0 hoping to resolve the issue (but to no avail). While > troubleshooting, someone suggested I try opening IDLE via command prompt. > When I do that IDLE never crashes, but It does show this error > (screenshot): http://i.imgur.com/1JqiRsY.png (3.2.3) > http://i.imgur.com/5KxE88K.png (3.3.0) Your posts are easier to deal with if you provide tracebacks as text. Here's what I get: Exception in Tkinter callback Traceback (most recent call last): File "/usr/local/lib/python3.3/tkinter/__init__.py", line 1442, in __call__ return self.func(*args) File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 174, in handler doafterhandler.pop()() File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 221, in doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func) ValueError: list.remove(x): x not in list > Some additional info: > - When IDLE crashes it does not display an error, every open window simply > closes. - IDLE has never crashed after opening a file when I open it via > command prompt, even if it was previously consistently displaying that > behavior. - I am running Windows 7 x64 with all updates. > > Has anyone ever encountered this? What does the error mean? This looks like the following bug: http://bugs.python.org/issue8900 You might be able to work around it by selecting the "At Startup Open Shell Window" option under Options-->Configure IDLE-->General-->Startup Preferences From quintessenceanx at gmail.com Fri Mar 1 22:03:41 2013 From: quintessenceanx at gmail.com (Quintessence) Date: Fri, 1 Mar 2013 19:03:41 -0800 (PST) Subject: Having problems crashing IDLE In-Reply-To: References: <840c99d3-9b9c-4f53-b9fa-73b8544a557c@googlegroups.com> Message-ID: Thank you for the advice! I checked the setting you specified and "Open Shell Window" at startup was already selected. Is there another bug this could be related to? Thank you! On Friday, March 1, 2013 3:00:40 AM UTC-5, Peter Otten wrote: > Quintessence wrote: > > > > > I've been learning Python over the past week or so and I keep running into > > > an issue where opening saved files will crash IDLE (not consistently, > > > sometimes the same files with no changes will open and sometimes not). I > > > was originally running Python 3.2.3, but I removed it and upgraded to > > > 3.3.0 hoping to resolve the issue (but to no avail). While > > > troubleshooting, someone suggested I try opening IDLE via command prompt. > > > When I do that IDLE never crashes, but It does show this error > > > (screenshot): http://i.imgur.com/1JqiRsY.png (3.2.3) > > > http://i.imgur.com/5KxE88K.png (3.3.0) > > > > Your posts are easier to deal with if you provide tracebacks as text. > > Here's what I get: > > > > Exception in Tkinter callback > > Traceback (most recent call last): > > File "/usr/local/lib/python3.3/tkinter/__init__.py", line 1442, in > > __call__ > > return self.func(*args) > > File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 174, in handler > > doafterhandler.pop()() > > File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 221, in > > > > doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func) > > ValueError: list.remove(x): x not in list > > > > > Some additional info: > > > - When IDLE crashes it does not display an error, every open window simply > > > closes. - IDLE has never crashed after opening a file when I open it via > > > command prompt, even if it was previously consistently displaying that > > > behavior. - I am running Windows 7 x64 with all updates. > > > > > > Has anyone ever encountered this? What does the error mean? > > > > This looks like the following bug: > > > > http://bugs.python.org/issue8900 > > > > You might be able to work around it by selecting the > > > > "At Startup Open Shell Window" option under > > > > Options-->Configure IDLE-->General-->Startup Preferences From quintessenceanx at gmail.com Fri Mar 1 22:03:41 2013 From: quintessenceanx at gmail.com (Quintessence) Date: Fri, 1 Mar 2013 19:03:41 -0800 (PST) Subject: Having problems crashing IDLE In-Reply-To: References: <840c99d3-9b9c-4f53-b9fa-73b8544a557c@googlegroups.com> Message-ID: Thank you for the advice! I checked the setting you specified and "Open Shell Window" at startup was already selected. Is there another bug this could be related to? Thank you! On Friday, March 1, 2013 3:00:40 AM UTC-5, Peter Otten wrote: > Quintessence wrote: > > > > > I've been learning Python over the past week or so and I keep running into > > > an issue where opening saved files will crash IDLE (not consistently, > > > sometimes the same files with no changes will open and sometimes not). I > > > was originally running Python 3.2.3, but I removed it and upgraded to > > > 3.3.0 hoping to resolve the issue (but to no avail). While > > > troubleshooting, someone suggested I try opening IDLE via command prompt. > > > When I do that IDLE never crashes, but It does show this error > > > (screenshot): http://i.imgur.com/1JqiRsY.png (3.2.3) > > > http://i.imgur.com/5KxE88K.png (3.3.0) > > > > Your posts are easier to deal with if you provide tracebacks as text. > > Here's what I get: > > > > Exception in Tkinter callback > > Traceback (most recent call last): > > File "/usr/local/lib/python3.3/tkinter/__init__.py", line 1442, in > > __call__ > > return self.func(*args) > > File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 174, in handler > > doafterhandler.pop()() > > File "/usr/local/lib/python3.3/idlelib/MultiCall.py", line 221, in > > > > doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func) > > ValueError: list.remove(x): x not in list > > > > > Some additional info: > > > - When IDLE crashes it does not display an error, every open window simply > > > closes. - IDLE has never crashed after opening a file when I open it via > > > command prompt, even if it was previously consistently displaying that > > > behavior. - I am running Windows 7 x64 with all updates. > > > > > > Has anyone ever encountered this? What does the error mean? > > > > This looks like the following bug: > > > > http://bugs.python.org/issue8900 > > > > You might be able to work around it by selecting the > > > > "At Startup Open Shell Window" option under > > > > Options-->Configure IDLE-->General-->Startup Preferences From __peter__ at web.de Sat Mar 2 04:09:42 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Mar 2013 10:09:42 +0100 Subject: Having problems crashing IDLE References: <840c99d3-9b9c-4f53-b9fa-73b8544a557c@googlegroups.com> Message-ID: Quintessence wrote: > Thank you for the advice! I checked the setting you specified and "Open > Shell Window" at startup was already selected. Is there another bug this > could be related to? None that I and google could find. Close idle and remove (or rename) the .idlerc directory in your home folder, and then start Idle again. If the problem persists it is very unlikely that it is configuration- related. In that case I suggest that you file a bug report yourself or amend your observations to the existing one. From idhayham at gmail.com Fri Mar 1 01:49:44 2013 From: idhayham at gmail.com (idy) Date: Thu, 28 Feb 2013 22:49:44 -0800 (PST) Subject: text formatting question Message-ID: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> I have a text string of this format Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN' I need to write this to mail body as with following format in multiple lines XYC.12345455-LOcation/user/data/MYGLE-ING XYC.23344566-LOcation/user/data/INGE-FTY XYC.22334566LOcation/user/data/GETN-YUN XYC.12345455LOcation/user/data/MYGLE-ING XYC.1111111LOcation/user/data/INGE-FTY XYC.3333333LOcation/user/data/GETN-YUN Note (XYC is common for all the text , rest of the fields are not constant. Please help From rosuav at gmail.com Fri Mar 1 01:53:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Mar 2013 17:53:41 +1100 Subject: text formatting question In-Reply-To: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> References: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 5:49 PM, idy wrote: > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN' > > I need to write this to mail body as with following format in multiple lines > > XYC.12345455-LOcation/user/data/MYGLE-ING > XYC.23344566-LOcation/user/data/INGE-FTY > XYC.22334566LOcation/user/data/GETN-YUN > XYC.12345455LOcation/user/data/MYGLE-ING > XYC.1111111LOcation/user/data/INGE-FTY > XYC.3333333LOcation/user/data/GETN-YUN You want to break the line immediately before the 'XYC'? That's quite easy; the line break is a character like any other, and can be used in a replace() call: formatted_error = Error.replace("XYC","\nXYC") If that's not the case, can you clarify what you need to do to divide it? Chris Angelico From idhayham at gmail.com Fri Mar 1 02:08:57 2013 From: idhayham at gmail.com (idy) Date: Thu, 28 Feb 2013 23:08:57 -0800 (PST) Subject: text formatting question In-Reply-To: References: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> Message-ID: <0a682b8c-34dd-4f45-b834-76c9f83d866d@googlegroups.com> On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 5:49 PM, idy wrote: > > > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN' > > > > > > I need to write this to mail body as with following format in multiple lines > > > > > > XYC.12345455-LOcation/user/data/MYGLE-ING > > > XYC.23344566-LOcation/user/data/INGE-FTY > > > XYC.22334566LOcation/user/data/GETN-YUN > > > XYC.12345455LOcation/user/data/MYGLE-ING > > > XYC.1111111LOcation/user/data/INGE-FTY > > > XYC.3333333LOcation/user/data/GETN-YUN > > > > You want to break the line immediately before the 'XYC'? That's quite > > easy; the line break is a character like any other, and can be used in > > a replace() call: > > > > formatted_error = Error.replace("XYC","\nXYC") > > > > If that's not the case, can you clarify what you need to do to divide it? > > > > Chris Angelico Chris, Thanks this works great !!! From idhayham at gmail.com Fri Mar 1 02:08:57 2013 From: idhayham at gmail.com (idy) Date: Thu, 28 Feb 2013 23:08:57 -0800 (PST) Subject: text formatting question In-Reply-To: References: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> Message-ID: <0a682b8c-34dd-4f45-b834-76c9f83d866d@googlegroups.com> On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 5:49 PM, idy wrote: > > > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN' > > > > > > I need to write this to mail body as with following format in multiple lines > > > > > > XYC.12345455-LOcation/user/data/MYGLE-ING > > > XYC.23344566-LOcation/user/data/INGE-FTY > > > XYC.22334566LOcation/user/data/GETN-YUN > > > XYC.12345455LOcation/user/data/MYGLE-ING > > > XYC.1111111LOcation/user/data/INGE-FTY > > > XYC.3333333LOcation/user/data/GETN-YUN > > > > You want to break the line immediately before the 'XYC'? That's quite > > easy; the line break is a character like any other, and can be used in > > a replace() call: > > > > formatted_error = Error.replace("XYC","\nXYC") > > > > If that's not the case, can you clarify what you need to do to divide it? > > > > Chris Angelico Chris, Thanks this works great !!! From davea at davea.name Fri Mar 1 08:52:58 2013 From: davea at davea.name (Dave Angel) Date: Fri, 01 Mar 2013 08:52:58 -0500 Subject: text formatting question In-Reply-To: <0a682b8c-34dd-4f45-b834-76c9f83d866d@googlegroups.com> References: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> <0a682b8c-34dd-4f45-b834-76c9f83d866d@googlegroups.com> Message-ID: <5130B2BA.9080801@davea.name> On 03/01/2013 02:08 AM, idy wrote: > On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote: >> >> >>> >> >> You want to break the line immediately before the 'XYC'? That's quite >> easy; the line break is a character like any other, and can be used in >> a replace() call: >> >> formatted_error = Error.replace("XYC","\nXYC") >> >> If that's not the case, can you clarify what you need to do to divide it? >> >> Chris Angelico > > Chris, > > Thanks this works great !!! > The assumption Chris made is that the characters XYC do *not* appear anywhere else in each string. if they do, then you need to write a spec as to what criteria you can count on for the data. If somebody has mangled all those lines into one long string, it's quite likely that they CANNOT be reliably separated again. Chris' suggestion is the most likely candidate, but ... -- DaveA From rosuav at gmail.com Fri Mar 1 08:57:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Mar 2013 00:57:07 +1100 Subject: text formatting question In-Reply-To: <5130B2BA.9080801@davea.name> References: <0a6178f9-51ef-4edc-b87f-2631d667797f@googlegroups.com> <0a682b8c-34dd-4f45-b834-76c9f83d866d@googlegroups.com> <5130B2BA.9080801@davea.name> Message-ID: On Sat, Mar 2, 2013 at 12:52 AM, Dave Angel wrote: > The assumption Chris made is that the characters XYC do *not* appear > anywhere else in each string. if they do, then you need to write a spec as > to what criteria you can count on for the data. > Right. I should have mentioned that. Let's hope the OP is sufficiently lucky as to have a separator uniqueness.. ChrisA From leopardsaga at gmail.com Fri Mar 1 03:43:20 2013 From: leopardsaga at gmail.com (Honghe Wu) Date: Fri, 1 Mar 2013 00:43:20 -0800 (PST) Subject: In win32 and linux platform, os modules has diffreent output order, is it a bug? Message-ID: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> env: python 2.7.3 6 test files' name in a directory as below: 12ab Abc Eab a1bc acd bc the following is test code: for root, dirs, files in os.walk(os.getcwd()): print files the output in win32 platform is: ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab'] but in linux is? ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ] they are so different. a bug? From benjamin.kaplan at case.edu Fri Mar 1 04:01:12 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 1 Mar 2013 01:01:12 -0800 Subject: In win32 and linux platform, os modules has diffreent output order, is it a bug? In-Reply-To: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> References: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 12:43 AM, Honghe Wu wrote: > env: python 2.7.3 > > 6 test files' name in a directory as below: > 12ab Abc Eab a1bc acd bc > > the following is test code: > for root, dirs, files in os.walk(os.getcwd()): > print files > > the output in win32 platform is: > ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab'] > > but in linux is? > ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ] > > they are so different. a bug? > -- The function doesn't specify a particular order, just that it will hand you a list of files. It grabs those from the underlying file system. It looks like Windows sorts it alphabetically and Linux just does whatever (maybe sorted by creation time?). I don't think it's a bug. If the order matters to you, sort it yourself. From clp2 at rebertia.com Fri Mar 1 03:55:29 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Mar 2013 00:55:29 -0800 Subject: In win32 and linux platform, os modules has diffreent output order, is it a bug? In-Reply-To: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> References: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 12:43 AM, Honghe Wu wrote: > env: python 2.7.3 > > 6 test files' name in a directory as below: > 12ab Abc Eab a1bc acd bc > > the following is test code: > for root, dirs, files in os.walk(os.getcwd()): > print files > > the output in win32 platform is: > ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab'] > > but in linux is? > ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ] > > they are so different. a bug? Nope. When os.walk() fetches a listing of the contents of a directory, it internally uses os.listdir() (or a moral equivalent thereof). The docs for os.listdir() state that "The [returned] list is in arbitrary order.". The order is dependent on the OS and filesystem, and likely also more obscure factors (e.g. the order in which the files were created). The lack of any required ordering allows for improved I/O performance in many/most cases. Cheers, Chris From leopardsaga at gmail.com Fri Mar 1 04:24:05 2013 From: leopardsaga at gmail.com (Honghe Wu) Date: Fri, 1 Mar 2013 17:24:05 +0800 Subject: In win32 and linux platform, os modules has diffreent output order, is it a bug? In-Reply-To: References: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> Message-ID: Thanks! Cause I need sorted returnd list, and the arbitrary list makes the other procedure go wrong. Maybe the I/O speed is more important in other cases. On Mar 1, 2013 4:55 PM, "Chris Rebert" wrote: > On Fri, Mar 1, 2013 at 12:43 AM, Honghe Wu wrote: > > env: python 2.7.3 > > > > 6 test files' name in a directory as below: > > 12ab Abc Eab a1bc acd bc > > > > the following is test code: > > for root, dirs, files in os.walk(os.getcwd()): > > print files > > > > the output in win32 platform is: > > ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab'] > > > > but in linux is? > > ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ] > > > > they are so different. a bug? > > Nope. When os.walk() fetches a listing of the contents of a directory, > it internally uses os.listdir() (or a moral equivalent thereof). The > docs for os.listdir() state that "The [returned] list is in arbitrary > order.". The order is dependent on the OS and filesystem, and likely > also more obscure factors (e.g. the order in which the files were > created). The lack of any required ordering allows for improved I/O > performance in many/most cases. > > Cheers, > Chris > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Mar 1 07:56:50 2013 From: nobody at nowhere.com (Nobody) Date: Fri, 01 Mar 2013 12:56:50 +0000 Subject: In win32 and linux platform, os modules has diffreent output order, is it a bug? References: <270cf08f-aefd-436c-a3e6-4adf373d5356@googlegroups.com> Message-ID: On Fri, 01 Mar 2013 17:24:05 +0800, Honghe Wu wrote: > Thanks! Cause I need sorted returnd list, and the arbitrary list makes the > other procedure go wrong. Maybe the I/O speed is more important in other > cases. You can sort the lists of files and subdirectories with e.g.: for root, dirs, files in os.walk(os.getcwd()): dirs[:] = sorted(dirs) files = sorted(files) ... Note that modifying the directory list in-place will affect which subdirectories are traversed and in what order. From winefrog at gmail.com Fri Mar 1 03:59:59 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 00:59:59 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) Message-ID: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c <24: c = c + 1 a = [] f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest') p = interp(indices) N = len(p) dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency KA,PSD = oned_Fourierspectrum(p,dt) # Call Song's 1D FS function time_axis = np.linspace(0.0,N,num = N,endpoint = False)*15/(60*24) plot_freq = 24*3600.*KA #Convert to cycles per day plot_period = 1.0/plot_freq # convert to days/cycle fpsd = plot_freq*PSD d = -1 while d <335: d = d + 1 y = fpsd[d] y1 = y1 + [y] m = np.mean(y1) m1 = m1 + [m] print m1 -------------------------------------------------------------------------------- My purpose is make a list of [mean(fpsd[0]), mean(fpsd[1]), mean(fpsd[2]).. mean(fpsd[335])]. Each y1 would be the list of fpsd[d]. I check it is working pretty well before second while loop and I can get individual mean of fpsd[d]. However, with second whole loop, it produces definitely wrong numbers. Would you help me this problem? From ulrich.eckhardt at dominolaser.com Fri Mar 1 07:00:42 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 01 Mar 2013 13:00:42 +0100 Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: Am 01.03.2013 09:59, schrieb Isaac Won: > try to make my triple nested loop working. My code would be: > c = 4 [...] > while c <24: > c = c + 1 This is bad style and you shouldn't do that in python. The question that comes up for me is whether something else is modifying "c" in that loop, but I think the answer is "no". For that reason, use Python's way: for c in range(5, 25): ... That way it is also clear that the first value in the loop is 5, while the initial "c = 4" seems to suggest something different. Also, the last value is 24, not 23. > while d <335: > d = d + 1 > y = fpsd[d] > y1 = y1 + [y] > m = np.mean(y1) > m1 = m1 + [m] Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) and the that "d in range(336)" is better style, you don't start with an empty "y1", except on the first iteration of the outer loop. I'm not really sure if that answers your problem. In any case, please drop everything not necessary to demostrate the problem before posting. This makes it easier to see what is going wrong both for you and others. Also make sure that others can actually run the code. Greetings from Hamburg! Uli From joel.goldstick at gmail.com Fri Mar 1 08:00:01 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 1 Mar 2013 08:00:01 -0500 Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt < ulrich.eckhardt at dominolaser.com> wrote: > Am 01.03.2013 09:59, schrieb Isaac Won: > > try to make my triple nested loop working. My code would be: >> c = 4 >> > [...] > > while c <24: >> c = c + 1 >> > > This is bad style and you shouldn't do that in python. The question that > comes up for me is whether something else is modifying "c" in that loop, > but I think the answer is "no". For that reason, use Python's way: > > for c in range(5, 25): > ... > > That way it is also clear that the first value in the loop is 5, while the > initial "c = 4" seems to suggest something different. Also, the last value > is 24, not 23. > > > > I concur with Uli, and add the following thoughts: What is going on with [y]? Is this really a list? So what is y1 + y1 + [y] doing? > > while d <335: >> d = d + 1 >> y = fpsd[d] >> y1 = y1 + [y] >> m = np.mean(y1) >> m1 = m1 + [m] >> > > In your outer loop you initialize these values each pass: dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency This should me moved out of the loop since nothing changes with dt or fs > Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) and > the that "d in range(336)" is better style, you don't start with an empty > "y1", except on the first iteration of the outer loop. > > I'm not really sure if that answers your problem. In any case, please drop > everything not necessary to demostrate the problem before posting. This > makes it easier to see what is going wrong both for you and others. Also > make sure that others can actually run the code. > > > Greetings from Hamburg! > > Uli > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From winefrog at gmail.com Fri Mar 1 11:28:21 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 08:28:21 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: <4d52aac9-d5f0-4124-982c-a4bcf2bc98a4@googlegroups.com> Thank you Ulich for reply, What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question. Thank you, Isaac On Friday, March 1, 2013 6:00:42 AM UTC-6, Ulrich Eckhardt wrote: > Am 01.03.2013 09:59, schrieb Isaac Won: > > > try to make my triple nested loop working. My code would be: > > > c = 4 > > [...] > > > while c <24: > > > c = c + 1 > > > > This is bad style and you shouldn't do that in python. The question that > > comes up for me is whether something else is modifying "c" in that loop, > > but I think the answer is "no". For that reason, use Python's way: > > > > for c in range(5, 25): > > ... > > > > That way it is also clear that the first value in the loop is 5, while > > the initial "c = 4" seems to suggest something different. Also, the last > > value is 24, not 23. > > > > > > > > > while d <335: > > > d = d + 1 > > > y = fpsd[d] > > > y1 = y1 + [y] > > > m = np.mean(y1) > > > m1 = m1 + [m] > > > > Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) > > and the that "d in range(336)" is better style, you don't start with an > > empty "y1", except on the first iteration of the outer loop. > > > > I'm not really sure if that answers your problem. In any case, please > > drop everything not necessary to demostrate the problem before posting. > > This makes it easier to see what is going wrong both for you and others. > > Also make sure that others can actually run the code. > > > > > > Greetings from Hamburg! > > > > Uli From ulrich.eckhardt at dominolaser.com Mon Mar 4 05:08:47 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 04 Mar 2013 11:08:47 +0100 Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: <4d52aac9-d5f0-4124-982c-a4bcf2bc98a4@googlegroups.com> References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> <4d52aac9-d5f0-4124-982c-a4bcf2bc98a4@googlegroups.com> Message-ID: Am 01.03.2013 17:28, schrieb Isaac Won: > What I really want to get from this code is m1 as I told. For this > purpose, for instance, values of fpsd upto second loop and that from > third loop should be same, but they are not. Actually it is my main > question. You are not helping yourself... >> In any case, please drop everything not necessary to demostrate the >> problem before posting. This makes it easier to see what is going >> wrong both for you and others. Also make sure that others can >> actually run the code. Read this carefully, I didn't write that to fill up empty space. Also, read Eric S. Raymond's essay on asking smart questions (you can easily locate it online), which the problems with your question in a much more general way. Uli From rosuav at gmail.com Fri Mar 1 08:41:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Mar 2013 00:41:05 +1100 Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > while c <24: > for columns in ( raw.strip().split() for raw in f ): > while d <335: Note your indentation levels: the code does not agree with your subject line. The third loop is not actually inside your second. Should it be? ChrisA From winefrog at gmail.com Fri Mar 1 11:14:03 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 08:14:03 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: Thank you, Chris. I just want to acculate value from y repeatedly. If y = 1,2,3...10, just have a [1,2,3...10] at onece. On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip().split() for raw in f ): > > > while d <335: > > > > Note your indentation levels: the code does not agree with your > > subject line. The third loop is not actually inside your second. > > Should it be? > > > > ChrisA From winefrog at gmail.com Fri Mar 1 11:14:03 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 08:14:03 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: Thank you, Chris. I just want to acculate value from y repeatedly. If y = 1,2,3...10, just have a [1,2,3...10] at onece. On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip().split() for raw in f ): > > > while d <335: > > > > Note your indentation levels: the code does not agree with your > > subject line. The third loop is not actually inside your second. > > Should it be? > > > > ChrisA From winefrog at gmail.com Fri Mar 1 11:18:54 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 08:18:54 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip().split() for raw in f ): > > > while d <335: > > > > Note your indentation levels: the code does not agree with your > > subject line. The third loop is not actually inside your second. > > Should it be? > > > > ChrisA Yes, the thiird lood should be inside of my whole loop. Thank you, Isaac From winefrog at gmail.com Fri Mar 1 11:18:54 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 08:18:54 -0800 (PST) Subject: Triple nested loop python (While loop insde of for loop inside of while loop) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Message-ID: On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won wrote: > > > while c <24: > > > for columns in ( raw.strip().split() for raw in f ): > > > while d <335: > > > > Note your indentation levels: the code does not agree with your > > subject line. The third loop is not actually inside your second. > > Should it be? > > > > ChrisA Yes, the thiird lood should be inside of my whole loop. Thank you, Isaac From breamoreboy at yahoo.co.uk Fri Mar 1 04:59:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 01 Mar 2013 09:59:13 +0000 Subject: Failure of Python devs to deliver - Battle Police SIG Message-ID: Hi all, It has become quite clear over the years that Python developers aren't doing enough to push the language forward. A Battle Police SIG will therefore be needed. Their sole task will be to ensure that all the volunteers spend their time working on Python and not frivilous pursuits like day jobs or leisure activities. The colours will be raised outside of RR's home at 05:00 Saturday 02/03/2013. For more data please contact RR directly, not me. -- Cheers. Mark Lawrence From giles at coochey.net Fri Mar 1 08:22:09 2013 From: giles at coochey.net (Giles Coochey) Date: Fri, 01 Mar 2013 13:22:09 +0000 Subject: Python Trademark Dispute - Update? Message-ID: <5130AB81.7080908@coochey.net> Is there an update on the trademark dispute that was mentioned the other week on this list? I can't help but notice that the .co.uk site that was attempting to trademark the Python name no longer returns a homepage, just a 404. -- Regards, Giles Coochey, CCNA, CCNAS NetSecSpec Ltd +44 (0) 7983 877438 http://www.coochey.net http://www.netsecspec.co.uk giles at coochey.net -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4968 bytes Desc: S/MIME Cryptographic Signature URL: From steve+comp.lang.python at pearwood.info Fri Mar 1 21:40:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2013 02:40:19 GMT Subject: Python Trademark Dispute - Update? References: Message-ID: <51316693$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Mar 2013 13:22:09 +0000, Giles Coochey wrote: > Is there an update on the trademark dispute that was mentioned the other > week on this list? > > I can't help but notice that the .co.uk site that was attempting to > trademark the Python name no longer returns a homepage, just a 404. http://pyfound.blogspot.com.au/2013/02/an-update-on-our-trademark-issue.html No further news since then. -- Steven From jaiprakashsingh213 at gmail.com Fri Mar 1 09:18:16 2013 From: jaiprakashsingh213 at gmail.com (Jaiky) Date: Fri, 1 Mar 2013 06:18:16 -0800 (PST) Subject: os.system() not responding on django... any reason? Message-ID: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> import sys,os sys.stderr = open('/dev/null') import paramiko sys.stderr = sys.__stderr__ os.system("echo \'s3\' >> myfile.txt ") #debug first in ssh2 def ssh2_connect(host, user, pswd, port=22): try: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, port, user, pswd) return ssh except Exception, e: return str(e) + "Error. Failed to connect. Wrong IP/Username/Password" def ssh2_exec(ssh, cmd, sudo=False): result = [] try: channel = ssh.get_transport().open_session() if sudo: channel.get_pty() except: return result stdin = channel.makefile('wb') stdout = channel.makefile('rb') channel.exec_command(cmd) exit_status = channel.recv_exit_status() if exit_status == 0: for line in stdout: result.append(line) channel.close() return result def ssh2_close(ssh): ssh.close() return def ssh2_copyToFile(ssh, local_file, remote_file): sftp = paramiko.SFTPClient.from_transport(ssh.get_transport()) sftp.put(local_file, remote_file) return From roy at panix.com Fri Mar 1 09:24:17 2013 From: roy at panix.com (Roy Smith) Date: Fri, 01 Mar 2013 09:24:17 -0500 Subject: os.system() not responding on django... any reason? References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: In article <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e at googlegroups.com>, Jaiky wrote: [a lot of code involving ssh and paramiko] Here's a few general suggestions: 1) Try to reduce this to the smallest possible amount of code which demonstrates the problem. You gave us a page full of complicated stuff. Keep hacking away lines of code that don't change the behavior until you get it down to something small and understandable. 2) Try to eliminate environmental problems. You're running this under django? Does it work as a stand-alone process (i.e. without django)? From marduk at python.net Fri Mar 1 09:59:34 2013 From: marduk at python.net (marduk at python.net) Date: Fri, 01 Mar 2013 09:59:34 -0500 Subject: os.system() not responding on django... any reason? In-Reply-To: References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: <1362149974.737.140661198677189.7AC66751@webmail.messagingengine.com> On Fri, Mar 1, 2013, at 09:24 AM, Roy Smith wrote: > In article <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e at googlegroups.com>, > Jaiky wrote: > > [a lot of code involving ssh and paramiko] > > Here's a few general suggestions: > > 1) Try to reduce this to the smallest possible amount of code which > demonstrates the problem. You gave us a page full of complicated stuff. > Keep hacking away lines of code that don't change the behavior until you > get it down to something small and understandable. > > 2) Try to eliminate environmental problems. You're running this under > django? Does it work as a stand-alone process (i.e. without django)? Also, what is the context (Is it running in a Django view; a model? a signal handler? in settings?)? From jaiprakashsingh213 at gmail.com Fri Mar 1 11:23:06 2013 From: jaiprakashsingh213 at gmail.com (Jaiky) Date: Fri, 1 Mar 2013 08:23:06 -0800 (PST) Subject: os.system() not responding on django... any reason? In-Reply-To: References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: <98614104-7656-4030-87ec-9529ea1804ba@googlegroups.com> it is running in view.......... From jaiprakashsingh213 at gmail.com Fri Mar 1 11:23:06 2013 From: jaiprakashsingh213 at gmail.com (Jaiky) Date: Fri, 1 Mar 2013 08:23:06 -0800 (PST) Subject: os.system() not responding on django... any reason? In-Reply-To: References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: <98614104-7656-4030-87ec-9529ea1804ba@googlegroups.com> it is running in view.......... From breamoreboy at yahoo.co.uk Fri Mar 1 14:20:34 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 01 Mar 2013 19:20:34 +0000 Subject: os.system() not responding on django... any reason? In-Reply-To: <98614104-7656-4030-87ec-9529ea1804ba@googlegroups.com> References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> <98614104-7656-4030-87ec-9529ea1804ba@googlegroups.com> Message-ID: On 01/03/2013 16:23, Jaiky wrote: > it is running in view.......... > When replying can you please ensure we have the complete context, otherwise we have to spend time looking, thanks. -- Cheers. Mark Lawrence From jaiprakashsingh213 at gmail.com Fri Mar 1 11:24:02 2013 From: jaiprakashsingh213 at gmail.com (Jaiky) Date: Fri, 1 Mar 2013 08:24:02 -0800 (PST) Subject: os.system() not responding on django... any reason? In-Reply-To: References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: <64a6acc9-e129-4b03-8fbc-ecd0035a2df7@googlegroups.com> in django inviroment.............. From jaiprakashsingh213 at gmail.com Fri Mar 1 11:24:02 2013 From: jaiprakashsingh213 at gmail.com (Jaiky) Date: Fri, 1 Mar 2013 08:24:02 -0800 (PST) Subject: os.system() not responding on django... any reason? In-Reply-To: References: <4fcc93b7-3be9-416f-a2d4-bdc6cba2133e@googlegroups.com> Message-ID: <64a6acc9-e129-4b03-8fbc-ecd0035a2df7@googlegroups.com> in django inviroment.............. From stephane at wirtel.be Fri Mar 1 10:10:11 2013 From: stephane at wirtel.be (Stephane Wirtel) Date: Fri, 1 Mar 2013 16:10:11 +0100 Subject: Best Practices with Python Message-ID: <20130301151011.GA23493@atlantis> Hi all, How are you ? me ? fine ;-) I have a lot of questions about the development with Python. I want to discuss about the tools for the enhancement of the quality of a project, not about the debugging (I don't want to discuss about pdb, ipdb, pudb, ...) I use these tools 1. Documentation sphinx: http://sphinx-doc.org/ a. I like the reStructuredText syntax b. We can parse the files and get an AST c. We can add a lot of directives or new roles for custom behaviors d. We can generate several output formats (pdf, epub, html) 2. BDD I use Behave: http://pythonhosted.org/behave/ 3. TDD unittest2 mock nose 4. Code Clone Digger ? for me this project is very useful because we can determine the duplicated code via a pattern matching. but the project seems to be dead pylint ? very strict but we can change the configuration, but very useful to have a quality of code flake8 ? more permissive than pylint. 5. Continuous Integration Server Jenkins with Shining Panda What do you think about Buildbot ? 6. Logging And you, what are your best practices ? Regards, St?phane -- St?phane Wirtel - http://wirtel.be - @matrixise From debby at josesmex.com Fri Mar 1 11:07:28 2013 From: debby at josesmex.com (debby at josesmex.com) Date: Fri, 1 Mar 2013 08:07:28 -0800 (PST) Subject: "No symbol" error using pystack gdb macro Message-ID: <8a465112-c63f-43bd-901f-ab703097522b@googlegroups.com> I'm relatively new to Python, running Python 3.3 on FreeBSD I have a process which has started to spike CPU usage. I'm trying to find out what it's doing. I tried the "pystack" macro suggested here: http://stackoverflow.com/questions/132058/showing-the-stack-trace-from-a-running-python-application/147114#147114 I got the gdbinit macro from: http://svn.python.org/projects/python/trunk/Misc/gdbinit When I attach gdb, it tells me it is loading symbols from python3.3m However when I run pystack I get: No symbol "PyStringObject" in current context. Do I need an updated version of the gdb macro for Python3.3? From dieter at handshake.de Sat Mar 2 02:08:31 2013 From: dieter at handshake.de (dieter) Date: Sat, 02 Mar 2013 08:08:31 +0100 Subject: "No symbol" error using pystack gdb macro References: <8a465112-c63f-43bd-901f-ab703097522b@googlegroups.com> Message-ID: <87ehfy1dow.fsf@handshake.de> debby at josesmex.com writes: > I'm relatively new to Python, running Python 3.3 on FreeBSD > > I have a process which has started to spike CPU usage. I'm trying to find out what it's doing. > > I tried the "pystack" macro suggested here: > > http://stackoverflow.com/questions/132058/showing-the-stack-trace-from-a-running-python-application/147114#147114 > > I got the gdbinit macro from: > > http://svn.python.org/projects/python/trunk/Misc/gdbinit > > When I attach gdb, it tells me it is loading symbols from python3.3m > > However when I run pystack I get: > > No symbol "PyStringObject" in current context. > > Do I need an updated version of the gdb macro for Python3.3? Many system installed Python versions (all, I have seen so far) are "stripped", i.e. they lack debugging information. Such information is necessary in order to use the gdb macros effectively. I suggest you install and compile your Python yourself. Likely, the generated Python will have debugging symbols without (manual) intervention. If not, the installation instructions should tell you how to get a Python with debugging symbols. From rosuav at gmail.com Fri Mar 1 12:07:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Mar 2013 04:07:19 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: Message-ID: On Sat, Mar 2, 2013 at 3:55 AM, ??? wrote: > why we bother with '{variable}'.format(variable=variable) ? > can we just '{variable}.format()' ? > > if variable is exist, then assign it. > if variable is not exist, then raise error > > I am not language expert. so sorry if this is not a good idea, or already > discussed. You're asking for a facility whereby variables magically get pulled from the caller's scope. Let me put it to you another way: def func1(): return foo + " world" def func2(): foo = "Hello" print("func1 returns: "+func1()) func2() Will this work? If not, why not? There are ways around this; you can, for instance, pass locals() to format(): '{variable}'.format(**locals()) But this is massive overkill and can unexpectedly expose a whole lot more than you wanted (an issue if you accept a format string from an untrusted source). Generally, it's best to be explicit. You can avoid repeating the name so much by using positional parameters instead: '{0}'.format(variable) Of course, this has its own considerations. But at least it isn't magical. :) ChrisA From steve+comp.lang.python at pearwood.info Fri Mar 1 20:43:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2013 01:43:18 GMT Subject: [Python-ideas] string.format() default variable assignment References: Message-ID: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 04:07:19 +1100, Chris Angelico replied to a thread of Python-ideas: > You're asking for a facility whereby variables magically get pulled from > the caller's scope. As interesting as that is, I think you sent it to the wrong list :) Again. O_o No offence Chris, but you're the only person I know who *regularly* replies to the wrong list. Does your mail client not have a "Reply to List" command, or "Reply All"? If so, then you should use it rather than manually typing the (wrong) list address in. -- Steven From rosuav at gmail.com Fri Mar 1 22:54:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Mar 2013 14:54:49 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 12:43 PM, Steven D'Aprano wrote: > On Sat, 02 Mar 2013 04:07:19 +1100, Chris Angelico replied to a thread of > Python-ideas: > >> You're asking for a facility whereby variables magically get pulled from >> the caller's scope. > > As interesting as that is, I think you sent it to the wrong list :) Yes, as was pointed out to me privately. The message had the "feel" of something that belonged on python-list, and I never for a moment thought that it was an -ideas thread... > Again. > > O_o > > > No offence Chris, but you're the only person I know who *regularly* > replies to the wrong list. Does your mail client not have a "Reply to > List" command, or "Reply All"? If so, then you should use it rather than > manually typing the (wrong) list address in. Correct, Gmail doesn't. I should switch to Thunderbird (or something else, but I've heard a good many recommendations for Tbird) but have yet to get around to setting it up. ChrisA From jeanpierreda at gmail.com Sat Mar 2 01:09:34 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 2 Mar 2013 01:09:34 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 1, 2013 at 10:54 PM, Chris Angelico wrote: >> No offence Chris, but you're the only person I know who *regularly* >> replies to the wrong list. Does your mail client not have a "Reply to >> List" command, or "Reply All"? If so, then you should use it rather than >> manually typing the (wrong) list address in. > > Correct, Gmail doesn't. I should switch to Thunderbird (or something > else, but I've heard a good many recommendations for Tbird) but have > yet to get around to setting it up. Actually, it has a few ways to reply-to-all. In this screenshot, there are three things I could click to reply-to-all: http://imgur.com/914BNuY First, I could click the big reply button. I changed a setting so that reply-to-all is the default (Settings->General->Default reply behavior). Second, there is the reply-to-all menu item in the reply dropdown. Finally, in the textbox at the bottom, there's the reply-to-all hyperlink. It sounds like changing the default would do you the most good. It usually does what I want. -- Devin From rosuav at gmail.com Sat Mar 2 01:54:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Mar 2013 17:54:57 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 5:09 PM, Devin Jeanpierre wrote: > On Fri, Mar 1, 2013 at 10:54 PM, Chris Angelico wrote: >>> No offence Chris, but you're the only person I know who *regularly* >>> replies to the wrong list. Does your mail client not have a "Reply to >>> List" command, or "Reply All"? If so, then you should use it rather than >>> manually typing the (wrong) list address in. >> >> Correct, Gmail doesn't. I should switch to Thunderbird (or something >> else, but I've heard a good many recommendations for Tbird) but have >> yet to get around to setting it up. > > Actually, it has a few ways to reply-to-all. In this screenshot, there > are three things I could click to reply-to-all: > http://imgur.com/914BNuY Yes, but reply-all sends a copy to the poster as well as the list. What I want is reply-list, acknowledging the list headers... and Gmail simply doesn't have that. I also want to be able to change my mind as to whether it's reply-all/reply-list/reply-sender after typing up a reply. Guess it's time I grabbed Tbird to find out if it can do that... ChrisA From jmz.griffin at kode5.net Sat Mar 2 03:06:28 2013 From: jmz.griffin at kode5.net (James Griffin) Date: Sat, 2 Mar 2013 08:06:28 +0000 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130302080628.GA21787@kontrol.kode5.net> [--------- Sat 2.Mar'13 at 17:54:57 +1100 Chris Angelico :---------] > On Sat, Mar 2, 2013 at 5:09 PM, Devin Jeanpierre wrote: > > On Fri, Mar 1, 2013 at 10:54 PM, Chris Angelico wrote: > >>> No offence Chris, but you're the only person I know who *regularly* > >>> replies to the wrong list. Does your mail client not have a "Reply to > >>> List" command, or "Reply All"? If so, then you should use it rather than > >>> manually typing the (wrong) list address in. > >> > >> Correct, Gmail doesn't. I should switch to Thunderbird (or something > >> else, but I've heard a good many recommendations for Tbird) but have > >> yet to get around to setting it up. > > > > Actually, it has a few ways to reply-to-all. In this screenshot, there > > are three things I could click to reply-to-all: > > http://imgur.com/914BNuY > > Yes, but reply-all sends a copy to the poster as well as the list. > What I want is reply-list, acknowledging the list headers... and Gmail > simply doesn't have that. > > I also want to be able to change my mind as to whether it's > reply-all/reply-list/reply-sender after typing up a reply. Guess it's > time I grabbed Tbird to find out if it can do that... use mutt devel or [Al]pine. Text based MUA's and News readers are more efficient IMO. From ethan at stoneleaf.us Sat Mar 2 14:59:41 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 02 Mar 2013 11:59:41 -0800 Subject: good mail readers [was Re: [Python-ideas] string.format() default variable assignment] In-Reply-To: <20130302080628.GA21787@kontrol.kode5.net> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <20130302080628.GA21787@kontrol.kode5.net> Message-ID: <51325A2D.7090604@stoneleaf.us> On 03/02/2013 12:06 AM, James Griffin wrote: > [--------- Sat 2.Mar'13 at 17:54:57 +1100 Chris Angelico :---------] >> I also want to be able to change my mind as to whether it's >> reply-all/reply-list/reply-sender after typing up a reply. Guess it's >> time I grabbed Tbird to find out if it can do that... > > use mutt devel or [Al]pine. Text based MUA's and News readers are more efficient IMO. I'll take a look at those three. While I certainly prefer Tbird over anything MS has to offer, it certainly has its own list of irritations. -- ~Ethan~ From jeanpierreda at gmail.com Sat Mar 2 09:53:47 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 2 Mar 2013 09:53:47 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: > Yes, but reply-all sends a copy to the poster as well as the list. > What I want is reply-list, acknowledging the list headers... and Gmail > simply doesn't have that. I've been replying to the poster and the list for ages. Is it bad netiquette? > I also want to be able to change my mind as to whether it's > reply-all/reply-list/reply-sender after typing up a reply. Guess it's > time I grabbed Tbird to find out if it can do that... You can change your mind for reply-all/reply/forward in gmail, but since there's no reply-list, can't do that one, of course. -- Devin From mail at timgolden.me.uk Sat Mar 2 10:01:47 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 02 Mar 2013 15:01:47 +0000 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5132145B.8080303@timgolden.me.uk> On 02/03/2013 14:53, Devin Jeanpierre wrote: > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: >> Yes, but reply-all sends a copy to the poster as well as the list. >> What I want is reply-list, acknowledging the list headers... and Gmail >> simply doesn't have that. > > I've been replying to the poster and the list for ages. Is it bad netiquette? Mixed, I'd say. Some do it, some even prefer it, some don't. I generally stick to the list only unless it's important that the OP sees the message sooner than later. TJG From steve+comp.lang.python at pearwood.info Sat Mar 2 19:27:38 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 00:27:38 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: >> Yes, but reply-all sends a copy to the poster as well as the list. What >> I want is reply-list, acknowledging the list headers... and Gmail >> simply doesn't have that. > > I've been replying to the poster and the list for ages. Is it bad > netiquette? I find it annoying, and yes I consider it rude. When we receive messages via a list, responses (unless personal and deliberately taken outside of the list) should remain on the list, rather than potentially bypassing any filters set up by the sender. E.g. the sender may have a filter that files mail to "Python-list" into a mail folder. If you send to the sender directly, you may break their filters. I read this list via Usenet, not email. So when somebody replies to me, and the list, I get a copy in my inbox and a copy in my news client. That's a de facto filter, which they have just broken. The mailman software used for the Python lists seem to be smart enough to only send the user one copy. But many mailing lists are not, and so when you reply to the author and CC the list, they may very well receive two copies. In effect, the person replying is saying "MY reply is so important that I don't care how you process mail, I'm going to try to force you to read it MY way instead of in your preferred way." So, yes, I do consider it rude. In the grand scheme of things though, it is a relatively minor rudeness. Pushing into line, or invading personal space, rather than breaking into my house and smearing excrement on the walls. -- Steven From roy at panix.com Sat Mar 2 19:42:50 2013 From: roy at panix.com (Roy Smith) Date: Sat, 02 Mar 2013 19:42:50 -0500 Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <513298fa$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: > > > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: > >> Yes, but reply-all sends a copy to the poster as well as the list. What > >> I want is reply-list, acknowledging the list headers... and Gmail > >> simply doesn't have that. > > > > I've been replying to the poster and the list for ages. Is it bad > > netiquette? > > I find it annoying, and yes I consider it rude. I actually find it convenient and useful when people do that. If somebody's replying to a thread I'm active on, I consider the responses to that thread to be higher priority than the rest of the firehose, so it's good for me that they've copied me directly. I also read this list via usenet. During the workday, I don't have convenient access to a newsreader, but I do get mail. If I post a question to the group from home in the morning, when people cc me directly on replies, I get them quickly. If they only post to the group, I have to either wait until I get home to catch up on netnews, or use one of several less convenient means of accessing the group from work. From steve+comp.lang.python at pearwood.info Sat Mar 2 22:19:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 03:19:55 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5132c15b$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 19:42:50 -0500, Roy Smith wrote: > In article <513298fa$0$30001$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: >> >> > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico >> > wrote: >> >> Yes, but reply-all sends a copy to the poster as well as the list. >> >> What I want is reply-list, acknowledging the list headers... and >> >> Gmail simply doesn't have that. >> > >> > I've been replying to the poster and the list for ages. Is it bad >> > netiquette? >> >> I find it annoying, and yes I consider it rude. > > I actually find it convenient and useful when people do that. If > somebody's replying to a thread I'm active on, I consider the responses > to that thread to be higher priority than the rest of the firehose, so > it's good for me that they've copied me directly. Does your newsreader not have a "watch thread" command? > I also read this list via usenet. During the workday, I don't have > convenient access to a newsreader, but I do get mail. If I post a > question to the group from home in the morning, when people cc me > directly on replies, I get them quickly. If they only post to the > group, I have to either wait until I get home to catch up on netnews, > or use one of several less convenient means of accessing the group from > work. Or you could, I dunno, *work* while at work. -- Steven From drobinow at gmail.com Sat Mar 2 21:11:04 2013 From: drobinow at gmail.com (David Robinow) Date: Sat, 2 Mar 2013 21:11:04 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano wrote: > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: > >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: >>> Yes, but reply-all sends a copy to the poster as well as the list. What >>> I want is reply-list, acknowledging the list headers... and Gmail >>> simply doesn't have that. >> I've been replying to the poster and the list for ages. Is it bad >> netiquette? > > I find it annoying, and yes I consider it rude. When we receive messages ... Do you consider it rude that you choose to use a newsreader, thus inconveniencing those of us who use the mailing list, as God intended. (I honestly can't remember if there's any advantage to News, not having used it this century) [Going out of my way to respond only to the list] From roy at panix.com Sat Mar 2 21:15:41 2013 From: roy at panix.com (Roy Smith) Date: Sat, 02 Mar 2013 21:15:41 -0500 Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , David Robinow wrote: > On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano > wrote: > > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: > > > >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: > >>> Yes, but reply-all sends a copy to the poster as well as the list. What > >>> I want is reply-list, acknowledging the list headers... and Gmail > >>> simply doesn't have that. > >> I've been replying to the poster and the list for ages. Is it bad > >> netiquette? > > > > I find it annoying, and yes I consider it rude. When we receive messages > ... > Do you consider it rude that you choose to use a newsreader, thus > inconveniencing those of us who use the mailing list, as God intended. > (I honestly can't remember if there's any advantage to News, not > having used it this century) > [Going out of my way to respond only to the list] There's a number of advantages to news vs. mail. The biggest is that news spools generally keep a long history around, so it's easy to go back and review a long thread. From drobinow at gmail.com Sat Mar 2 22:01:41 2013 From: drobinow at gmail.com (David Robinow) Date: Sat, 2 Mar 2013 22:01:41 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith wrote: > In article , > David Robinow wrote: > >> On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano >> wrote: >> > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: >> > >> >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico wrote: >> >>> Yes, but reply-all sends a copy to the poster as well as the list. What >> >>> I want is reply-list, acknowledging the list headers... and Gmail >> >>> simply doesn't have that. >> >> I've been replying to the poster and the list for ages. Is it bad >> >> netiquette? >> > >> > I find it annoying, and yes I consider it rude. When we receive messages >> ... >> Do you consider it rude that you choose to use a newsreader, thus >> inconveniencing those of us who use the mailing list, as God intended. >> (I honestly can't remember if there's any advantage to News, not >> having used it this century) >> [Going out of my way to respond only to the list] > > There's a number of advantages to news vs. mail. The biggest is that > news spools generally keep a long history around, so it's easy to go > back and review a long thread. That can't be the biggest since mail stays around forever unless deliberately deleted. From rosuav at gmail.com Sat Mar 2 22:06:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 14:06:10 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 3, 2013 at 2:01 PM, David Robinow wrote: > On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith wrote: >> There's a number of advantages to news vs. mail. The biggest is that >> news spools generally keep a long history around, so it's easy to go >> back and review a long thread. > That can't be the biggest since mail stays around forever unless > deliberately deleted. But your mail has only what you receive. You have to hunt down a separate archive of what was posted before you joined the thread. Advantage goes to news, but a slight one, and if that's the biggest, it's not a great advertisement. ChrisA From drobinow at gmail.com Sat Mar 2 22:18:25 2013 From: drobinow at gmail.com (David Robinow) Date: Sat, 2 Mar 2013 22:18:25 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 10:06 PM, Chris Angelico wrote: > On Sun, Mar 3, 2013 at 2:01 PM, David Robinow wrote: >> On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith wrote: >>> There's a number of advantages to news vs. mail. The biggest is that >>> news spools generally keep a long history around, so it's easy to go >>> back and review a long thread. >> That can't be the biggest since mail stays around forever unless >> deliberately deleted. > > But your mail has only what you receive. You have to hunt down a > separate archive of what was posted before you joined the thread. > Advantage goes to news, but a slight one, and if that's the biggest, > it's not a great advertisement. I have no idea what you're trying to say here. As far as I know, when I subscribe to a list I get all the mail. I don't "join" threads. I don't even know what that means. [This has drifted way off topic so I won't be responding again, but I'll enjoy reading what anyone cares to write.] From rosuav at gmail.com Sat Mar 2 22:46:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 14:46:36 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 3, 2013 at 2:18 PM, David Robinow wrote: > On Sat, Mar 2, 2013 at 10:06 PM, Chris Angelico wrote: >> But your mail has only what you receive. You have to hunt down a >> separate archive of what was posted before you joined the thread. >> Advantage goes to news, but a slight one, and if that's the biggest, >> it's not a great advertisement. > I have no idea what you're trying to say here. As far as I know, when > I subscribe to a list I get all the mail. I don't "join" threads. I > don't even know what that means. > [This has drifted way off topic so I won't be responding again, but > I'll enjoy reading what anyone cares to write.] Err, joined the list is what I meant. At any given time, there are a certain number of active threads; anyone who joins the list will get the posts since joining but not the ones prior, for which they'll have to dig around elsewhere. Since netiquette recommends that posts quote enough of the prior posts to provide context, this shouldn't be a major problem, but there is a bit of advantage to news here. ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 2 22:21:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 03:21:37 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 21:11:04 -0500, David Robinow wrote: > On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano > wrote: >> On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote: >> >>> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico >>> wrote: >>>> Yes, but reply-all sends a copy to the poster as well as the list. >>>> What I want is reply-list, acknowledging the list headers... and >>>> Gmail simply doesn't have that. >>> I've been replying to the poster and the list for ages. Is it bad >>> netiquette? >> >> I find it annoying, and yes I consider it rude. When we receive >> messages > ... > Do you consider it rude that you choose to use a newsreader, thus > inconveniencing those of us who use the mailing list, as God intended. How the flying fuck does my choice of where and how *I* read this forum inconvenience YOU? Talk about an overactive sense of entitlement. The world does not revolve around you and I do not arrange my day to suit your preferences. -- Steven From jeanpierreda at gmail.com Sat Mar 2 23:00:13 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 2 Mar 2013 23:00:13 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 2, 2013 at 10:21 PM, Steven D'Aprano wrote: > How the flying fuck does my choice of where and how *I* read this forum > inconvenience YOU? > > Talk about an overactive sense of entitlement. The world does not revolve > around you and I do not arrange my day to suit your preferences. I don't agree with what he said, but I think what he was getting at is that it's inconvenient to be polite to you according to the standards you have set. -- Devin From steve+comp.lang.python at pearwood.info Sun Mar 3 04:51:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 09:51:32 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51331d24$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 03 Mar 2013 03:21:37 +0000, Steven D'Aprano wrote: > On Sat, 02 Mar 2013 21:11:04 -0500, David Robinow wrote: >> Do you consider it rude that you choose to use a newsreader, thus >> inconveniencing those of us who use the mailing list, as God intended. > > How the flying fuck does my choice of where and how *I* read this forum > inconvenience YOU? Hmmm. While I stand by the general sentiments, I think I flew off the handle there. In retrospect, I wish I had said that in a less aggressive manner. David, please consider this an apology for the bellicose response to your rhetorical question. -- Steven From steve+comp.lang.python at pearwood.info Sun Mar 3 05:33:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 10:33:22 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513326f1$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 23:00:13 -0500, Devin Jeanpierre wrote: > On Sat, Mar 2, 2013 at 10:21 PM, Steven D'Aprano > wrote: >> How the flying fuck does my choice of where and how *I* read this forum >> inconvenience YOU? >> >> Talk about an overactive sense of entitlement. The world does not >> revolve around you and I do not arrange my day to suit your >> preferences. > > I don't agree with what he said, but I think what he was getting at is > that it's inconvenient to be polite to you according to the standards > you have set. Whether I read these messages via Usenet or email or a web-based archive or by having a trained monkey forward the message to me in Morse code makes *absolutely no difference* to the sender. All he need do is send to the same list *he* reads the messages from, using whatever protocol he chooses to use. The very idea that my choice to read this in Pan newsreader rather than some email client somehow inconveniences David Robinow is stupid. Furthermore, he's picked out the *least* important part of my original email to respond to. Even if I read this via email rather than news, people emailing me directly rather than via the list may bypass any email filters I may have set up. The use of news rather than email is merely *equivalent* to a filter, where posts to this forum go into my news reader instead of my email inbox. And then there are people who go on No Mail and read responses via a web archive, including the dreaded Google Groups. Or rather than receiving individual messages, they go on digest mail. By emailing them directly, you dis-empower them, taking away their choice of how they read messages on that mailing list. I'm sorry, but *your response is not that important* that you get to thoughtlessly take away my choice of where and how I read messages. (That's generic "you", not specifically you, Devin). That's a sign of unreasonable sense of entitlement, conscious or not, and lack of consideration for others. I'm not being unreasonable here. Not withstanding the occasional person, like Roy Smith, who considers it a good thing[1], if you reply directly to the sender, in a small way you are taking away the sender's freedom of choice. And that is rude. [1] Perhaps Roy hasn't experienced really high volume threads, with hundreds of messages a day, and getting two copies of every email in any thread you replied to. I have. -- Steven From drobinow at gmail.com Mon Mar 4 11:09:10 2013 From: drobinow at gmail.com (David Robinow) Date: Mon, 4 Mar 2013 11:09:10 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ignoring my own posting ban, since I've clearly been misunderstood .. On Sat, Mar 2, 2013 at 10:21 PM, Steven D'Aprano wrote: > On Sat, 02 Mar 2013 21:11:04 -0500, David Robinow wrote: > >> Do you consider it rude that you choose to use a newsreader, thus >> inconveniencing those of us who use the mailing list, as God intended. > > How the flying fuck does my choice of where and how *I* read this forum > inconvenience YOU? > > Talk about an overactive sense of entitlement. The world does not revolve > around you and I do not arrange my day to suit your preferences. This surprises me. Not the language but the content, since the inconvenience was explicitly discussed. Many list members use gmail. It works for me. I never see double posts. gmail knows not to do that. The lack of a "reply to list" option would not concern me if everybody else used gmail. I could just use "reply all", nobody would see double posts, and we're all happy. However, some people prefer to read comp.lang.python. Thus if I use what is most convenient me, the news users see double posts. To avoid being thought rude (please note that many people are, or 'were' in the case of python-list, unaware of this issue and should be classified as ignorant rather than rude) I need to, after clicking "Reply All" Move mouse to CC: area. Highlight python-list address C-x (i.e., CUT) Move mouse to TO: area. Highlight the address (of the poster to whom I am replying) C-v (i.e., PASTE) Is that horribly difficult? No, and I intend to do it in the future. I'm mostly a lurker anyway (I knew python better 10 years ago when I was still working - inactivity and advanced age have made me dumber. I mostly read python-list for recreation) so it's not a big deal. I might be annoyed if I posted more. But here's what I don't understand. Why does somebody who posts as much as Steven (and thanks for that. Getting cussed at occasionally is a cheap price for all the free advice) not set up a simple mail filter which trashes all mail from python-list. Wouldn't that solve the problem? Or am I misunderstanding something? From drobinow at gmail.com Mon Mar 4 11:15:21 2013 From: drobinow at gmail.com (David Robinow) Date: Mon, 4 Mar 2013 11:15:21 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Crap. I just forgot to do what I just said I would do and didn't go through my "inconvenient" sequence. Sorry, Steven. It was unintentional. From davea at davea.name Mon Mar 4 13:31:19 2013 From: davea at davea.name (Dave Angel) Date: Mon, 04 Mar 2013 13:31:19 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5134E877.1040703@davea.name> On 03/04/2013 11:15 AM, David Robinow wrote: > Crap. I just forgot to do what I just said I would do and didn't go > through my "inconvenient" sequence. > Sorry, Steven. It was unintentional. > FWIW, you don't have to bother moving the python-list address to a To: field. Just remove the personal address that's there. See I saved you a few keystrokes. To: CC: python-list should work fine. -- DaveA From steve+comp.lang.python at pearwood.info Mon Mar 4 21:42:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2013 02:42:07 GMT Subject: [Python-ideas] string.format() default variable assignment References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 04 Mar 2013 11:09:10 -0500, David Robinow wrote: > But here's what I don't understand. Why does somebody who posts as > much as Steven (and thanks for that. Getting cussed at occasionally is a > cheap price for all the free advice) not set up a simple mail filter > which trashes all mail from python-list. Wouldn't that solve the > problem? Or am I misunderstanding something? When I'm working in my backyard garden, it's a real drag to put garden refuse into the green waste bin for collection. I have to cut it up into manageable-sized pieces, put them in a big carry bag, carry it through the house, then empty the bag into the green waste collection bin the local council supplies. What a drag! Maybe I should have thought of this before moving into my house, but I'm stuck with it now, moving to a new house would be difficult and expensive. Besides, apart from this one little difficulty, I like it here. Since I have all sorts of good excuses why doing the right thing is too much trouble, I just toss any plant trimmings over the fence into my neighbour's yard. It's easy for him to deal with it, all he has to do is get a goat to eat the garden waste I toss over the fence, and his problem is solved. I'm actually doing him a favour by tossing my garden trimmings into his yard. If he doesn't get a goat, the trimmings will rot and turn into compost, which improves the soil in his garden. He'll thank me some day. I really don't understand why he thinks I'm being rude. He should be grateful, not upset. If anyone is being rude, it's him, expecting me to carry all that garden waste through the house into the collection bin. Doesn't he understand how hard that is for me? -- Steven From rosuav at gmail.com Mon Mar 4 21:54:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2013 13:54:57 +1100 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 5, 2013 at 1:42 PM, Steven D'Aprano wrote: > It's easy for him to > deal with it, all he has to do is get a goat to eat the garden waste I > toss over the fence, and his problem is solved. Sounds like someone got Steven's goat. *dives for cover* ChrisA From gheskett at wdtv.com Mon Mar 4 23:01:33 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 4 Mar 2013 23:01:33 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201303042301.34061.gheskett@wdtv.com> On Monday 04 March 2013 23:00:31 Chris Angelico did opine: > On Tue, Mar 5, 2013 at 1:42 PM, Steven D'Aprano > > wrote: > > It's easy for him to > > deal with it, all he has to do is get a goat to eat the garden waste I > > toss over the fence, and his problem is solved. > > Sounds like someone got Steven's goat. > > *dives for cover* > > ChrisA Thats why this list is worth staying on. :) FWIW, I'd pulled the cover down tight and hide for a while. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! My views "You stay here, Audrey -- this is between me and the vegetable!" -- Seymour, from _Little Shop Of Horrors_ I was taught to respect my elders, but its getting harder and harder to find any... From breamoreboy at yahoo.co.uk Tue Mar 5 06:35:55 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 05 Mar 2013 11:35:55 +0000 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 05/03/2013 02:54, Chris Angelico wrote: > On Tue, Mar 5, 2013 at 1:42 PM, Steven D'Aprano > wrote: >> It's easy for him to >> deal with it, all he has to do is get a goat to eat the garden waste I >> toss over the fence, and his problem is solved. > > Sounds like someone got Steven's goat. > > *dives for cover* > > ChrisA > It's unlikely to happen but the UK should bring back the death penalty when it gets that bad :) -- Cheers. Mark Lawrence From gheskett at wdtv.com Tue Mar 5 06:55:50 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Tue, 5 Mar 2013 06:55:50 -0500 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: References: Message-ID: <201303050655.50879.gheskett@wdtv.com> On Tuesday 05 March 2013 06:54:14 Mark Lawrence did opine: > On 05/03/2013 02:54, Chris Angelico wrote: > > On Tue, Mar 5, 2013 at 1:42 PM, Steven D'Aprano > > > > wrote: > >> It's easy for him to > >> deal with it, all he has to do is get a goat to eat the garden waste > >> I toss over the fence, and his problem is solved. > > > > Sounds like someone got Steven's goat. > > > > *dives for cover* > > > > ChrisA > > It's unlikely to happen but the UK should bring back the death penalty > when it gets that bad :) I think another friend of mine had the most cogent observation when he said: You can't fix stupid, but stupid will eventually get fixed. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! My views People who are funny and smart and return phone calls get much better press than people who are just funny and smart. -- Howard Simons, "The Washington Post" I was taught to respect my elders, but its getting harder and harder to find any... From jmz at kontrol.kode5.net Tue Mar 5 03:16:16 2013 From: jmz at kontrol.kode5.net (James Griffin) Date: Tue, 5 Mar 2013 08:16:16 +0000 Subject: [Python-ideas] string.format() default variable assignment In-Reply-To: <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <51315936$0$30001$c3e8da3$5496439d@news.astraweb.com> <513298fa$0$30001$c3e8da3$5496439d@news.astraweb.com> <5132c1c0$0$30001$c3e8da3$5496439d@news.astraweb.com> <51355b7f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130305081616.GA23611@kontrol.kode5.net> [--------- Tue 5.Mar'13 at 2:42:07 +0000 Steven D'Aprano :---------] > On Mon, 04 Mar 2013 11:09:10 -0500, David Robinow wrote: > > > But here's what I don't understand. Why does somebody who posts as > > much as Steven (and thanks for that. Getting cussed at occasionally is a > > cheap price for all the free advice) not set up a simple mail filter > > which trashes all mail from python-list. Wouldn't that solve the > > problem? Or am I misunderstanding something? > > When I'm working in my backyard garden, it's a real drag to put garden > refuse into the green waste bin for collection. I have to cut it up into > manageable-sized pieces, put them in a big carry bag, carry it through > the house, then empty the bag into the green waste collection bin the > local council supplies. What a drag! Maybe I should have thought of this > before moving into my house, but I'm stuck with it now, moving to a new > house would be difficult and expensive. Besides, apart from this one > little difficulty, I like it here. Since I have all sorts of good excuses > why doing the right thing is too much trouble, I just toss any plant > trimmings over the fence into my neighbour's yard. It's easy for him to > deal with it, all he has to do is get a goat to eat the garden waste I > toss over the fence, and his problem is solved. > > I'm actually doing him a favour by tossing my garden trimmings into his > yard. If he doesn't get a goat, the trimmings will rot and turn into > compost, which improves the soil in his garden. He'll thank me some day. > > I really don't understand why he thinks I'm being rude. He should be > grateful, not upset. If anyone is being rude, it's him, expecting me to > carry all that garden waste through the house into the collection bin. > Doesn't he understand how hard that is for me? I'm sorry - i just had to reply :-) i've just got up and read this and it actually made me LOL. Thanks Steven. From olsr.kamal at gmail.com Fri Mar 1 12:53:27 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Fri, 1 Mar 2013 09:53:27 -0800 (PST) Subject: tracer une cercle dans python tkinter? Message-ID: <14fa231e-ca15-4eb4-a125-a756b0d62cdc@googlegroups.com> comment tracer une cercle contient un num?ro au un symbole dans le center dans python tkinter? From vincent.vandevyvre at swing.be Fri Mar 1 13:10:13 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 01 Mar 2013 19:10:13 +0100 Subject: tracer une cercle dans python tkinter? In-Reply-To: <14fa231e-ca15-4eb4-a125-a756b0d62cdc@googlegroups.com> References: <14fa231e-ca15-4eb4-a125-a756b0d62cdc@googlegroups.com> Message-ID: <5130EF05.6030107@swing.be> Le 01/03/13 18:53, olsr.kamal at gmail.com a ?crit : > comment tracer une cercle contient un num?ro au un symbole dans le center dans python tkinter? Posez votre question ici: http://www.developpez.net/forums/f96/autres-langages/python-zope/ -- Vincent V.V. Oqapy . Qarte . PaQager From kliateni at gmail.com Fri Mar 1 13:22:03 2013 From: kliateni at gmail.com (Karim) Date: Fri, 01 Mar 2013 19:22:03 +0100 Subject: tracer une cercle dans python tkinter? In-Reply-To: <5130EF05.6030107@swing.be> References: <14fa231e-ca15-4eb4-a125-a756b0d62cdc@googlegroups.com> <5130EF05.6030107@swing.be> Message-ID: <5130F1CB.8010207@gmail.com> On 01/03/2013 19:10, Vincent Vande Vyvre wrote: > Le 01/03/13 18:53, olsr.kamal at gmail.com a ?crit : >> comment tracer une cercle contient un num?ro au un symbole dans le center dans python tkinter? > Posez votre question ici: > > http://www.developpez.net/forums/f96/autres-langages/python-zope/ > Heuu en anglais vous toucherez plus de monde. K From __peter__ at web.de Fri Mar 1 14:06:29 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Mar 2013 20:06:29 +0100 Subject: tracer une cercle dans python tkinter? References: <14fa231e-ca15-4eb4-a125-a756b0d62cdc@googlegroups.com> Message-ID: olsr.kamal at gmail.com wrote: > comment tracer une cercle contient un num?ro au un symbole dans le center > dans python tkinter? [I hope you can cope with English] Use a Canvas widget: import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=240, height=240) canvas.pack() canvas.create_oval((20, 20), (220, 220), width=10, fill="white") tag = canvas.create_text(120, 120, text="42", justify=tk.CENTER, font=("Helvetica", 110), fill="#800") if 1: # fancy stuff; you can safely remove the complete if-statement def n(x): while True: for i in reversed(range(x+1)): yield i values = n(42) def down(): text = str(next(values)) canvas.itemconfig(tag, text=text) root.after(300, down) down() root.mainloop() See http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/canvas.html for more. From winefrog at gmail.com Fri Mar 1 13:07:26 2013 From: winefrog at gmail.com (Isaac Won) Date: Fri, 1 Mar 2013 10:07:26 -0800 (PST) Subject: Putting the loop inside of loop properly Message-ID: I just would like to make my previous question simpler and I bit adjusted my code with help with Ulich and Chris. The basic structure of my code is: for c in range(5,25): for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest') p = interp(indices) N = len(p) fpsd = plot_freq*PSD f.seek(0,0) for d in range(336): y = fpsd[d] y1 = y1 + [y] m = np.mean(y1) m1 = m1 + [m] ------------------------------------------------------------------ I just removed seemingly unnecesary lines. I expect that last loop can produce the each order values (first, second,.... last(336th)) of fpsd from former loop. fpsd would be 20 lists. So, fpsd[0] in third loop shoul be first values from 20 lists and it expects to be accumulated to y1. So, y1 should be the list of first values from 20 fpsd lists. and m is mean of y1. I expect to repeat 356 times and accumulated to m1. However, it doesn't work and fpsd values in and out of the last loop are totally different. My question is clear? Any help or questions would be really appreciated. Isaac From python at mrabarnett.plus.com Fri Mar 1 13:40:49 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Mar 2013 18:40:49 +0000 Subject: Putting the loop inside of loop properly In-Reply-To: References: Message-ID: <5130F631.5010809@mrabarnett.plus.com> On 2013-03-01 18:07, Isaac Won wrote: > I just would like to make my previous question simpler and I bit adjusted my code with help with Ulich and Chris. > The basic structure of my code is: > > for c in range(5,25): > > for columns in ( raw.strip().split() for raw in f ): [snip] When you're using .split() with no argument (split on any whitespace), you don't need to use .strip() with no argument (strip any whitespace): >>> ' foo bar '.strip().split() ['foo', 'bar'] >>> ' foo bar '.split() ['foo', 'bar'] From l.selmi at icloud.com Fri Mar 1 13:35:14 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Fri, 01 Mar 2013 19:35:14 +0100 Subject: need for help Message-ID: <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> hi guys i typed the following program: class ball: def _init_(self, color, size, direction): self.color = color self.size = size self.direction = direction def _str_(self): msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!' return msg myball = ball('red', 'small', 'down') print my ball BUT I GOT THIS ERROR: Traceback (most recent call last): File "/Users/leonardo/Documents/ball2.py", line 11, in myball = ball('red', 'small', 'down') TypeError: this constructor takes no arguments can you kindly tell me what is wrong? thanks a lot! From robert.day at merton.oxon.org Fri Mar 1 14:41:24 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Fri, 1 Mar 2013 19:41:24 +0000 Subject: need for help In-Reply-To: <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> References: <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> Message-ID: It looks like you're using single underscores, not double: the methods should be __init__ and __str__. On 1 March 2013 18:35, leonardo selmi wrote: > hi guys > > i typed the following program: > > class ball: > def _init_(self, color, size, direction): > self.color = color > self.size = size > self.direction = direction > > def _str_(self): > msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!' > return msg > > myball = ball('red', 'small', 'down') > print my ball > > BUT I GOT THIS ERROR: > > Traceback (most recent call last): > File "/Users/leonardo/Documents/ball2.py", line 11, in > myball = ball('red', 'small', 'down') > TypeError: this constructor takes no arguments > > can you kindly tell me what is wrong? > thanks a lot! > -- > http://mail.python.org/mailman/listinfo/python-list -- Robert K. Day robert.day at merton.oxon.org From davea at davea.name Fri Mar 1 14:58:06 2013 From: davea at davea.name (Dave Angel) Date: Fri, 01 Mar 2013 14:58:06 -0500 Subject: need for help In-Reply-To: <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> References: <8B3DE2FF-3A5A-4666-8FF6-70B15AAF5987@icloud.com> Message-ID: <5131084E.40308@davea.name> On 03/01/2013 01:35 PM, leonardo selmi wrote: > hi guys > > i typed the following program: > > class ball: > def _init_(self, color, size, direction): > self.color = color > self.size = size > self.direction = direction > > def _str_(self): > msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!' > return msg > > myball = ball('red', 'small', 'down') > print my ball > > BUT I GOT THIS ERROR: > > Traceback (most recent call last): > File "/Users/leonardo/Documents/ball2.py", line 11, in > myball = ball('red', 'small', 'down') > TypeError: this constructor takes no arguments > > can you kindly tell me what is wrong? > thanks a lot! > 1) please pick a useful subject line. Every message "needs help". But yours might be something like "constructor takes no arguments" 2) please tell us Python version you're targeting. I'm assuming 2.7 3) Thank you for giving a full traceback error message. Much better than an image file, or just paraphrasing, as many do. And thanks for posting as a text message, so your formatting doesn't get trashed. When I run the program, I get: davea at think2:~/temppython$ python leonardo.py File "leonardo.py", line 13 print my ball ^ SyntaxError: invalid syntax davea at think2:~/temppython$ Which is caused by having a space in the middle of the myball variable. After fixing that, I get your error, which is triggered by misspelling __init__ (you omitted one of the underscores at each end). After fixing that, I get davea at think2:~/temppython$ python leonardo.py <__main__.ball instance at 0x7f330da5bbd8> davea at think2:~/temppython$ which is triggered by the same error in the __str__ method. These special methods are sometimes called dunder methods, because they all need double underscores, at both front and back. davea at think2:~/temppython$ python leonardo.py hi, i am a small redball! davea at think2:~/temppython$ The other thing you should fix is the class definition line. You forgot to derive your class from object, which makes your class an old style one, deprecated for many many years. Doesn't matter here, but sooner or later it will. And Python 3 supports only new-style classes, so you might as well be using them. class ball(object): #new style class -- DaveA From alister.ware at ntlworld.com Fri Mar 1 17:01:56 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 01 Mar 2013 22:01:56 GMT Subject: need for help References: Message-ID: On Fri, 01 Mar 2013 19:35:14 +0100, leonardo selmi wrote: > hi guys > > i typed the following program: > > class ball: > def _init_(self, color, size, direction): > self.color = color self.size = size self.direction = direction > > def _str_(self): > msg = 'hi, i am a ' + self.size + ' ' + self.color + 'ball!' > return msg > > myball = ball('red', 'small', 'down') > print my ball > > BUT I GOT THIS ERROR: > > Traceback (most recent call last): > File "/Users/leonardo/Documents/ball2.py", line 11, in > myball = ball('red', 'small', 'down') > TypeError: this constructor takes no arguments > > can you kindly tell me what is wrong? > thanks a lot! as far as I can see is_init_ should be __init__ (double underscore) -- The autodecrement is not magical. -- Larry Wall in the perl man page From rantingrickjohnson at gmail.com Fri Mar 1 17:59:28 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 1 Mar 2013 14:59:28 -0800 (PST) Subject: need for help In-Reply-To: References: Message-ID: <5f6f9e76-d44c-463e-af3e-88ac7adddc35@googlegroups.com> On Friday, March 1, 2013 12:35:14 PM UTC-6, leonardo selmi wrote: > class ball: > > [...] > Now that you've gotten the exceptions sorted, it may be time to join the *other* 99% of programmers by editing that class identifier. All class symbols should start with (at minimum) a capitol letter. After you do that, you should start reading and adapting as much of the Python style guide you can handle. http://www.python.org/dev/peps/pep-0008/ From smsm_egy2000 at yahoo.com Fri Mar 1 15:25:30 2013 From: smsm_egy2000 at yahoo.com (alagmy) Date: Fri, 1 Mar 2013 12:25:30 -0800 (PST) Subject: HTC ChaCha review Message-ID: HTC ChaCha review http://natigtas7ab.blogspot.com/2012/10/htc-chacha-review.html From olsr.kamal at gmail.com Fri Mar 1 15:46:32 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Fri, 1 Mar 2013 12:46:32 -0800 (PST) Subject: comment tracer des neoudspar Click Message-ID: <17b99241-d7fc-4ed4-89a6-62ea48cb4576@googlegroups.com> comment tracer des neouds apr?s Click sur un canvas par un buttoun tkinter qui prendre les coordonn?es et tracer un neoud? From l.selmi at icloud.com Fri Mar 1 15:59:12 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Fri, 01 Mar 2013 21:59:12 +0100 Subject: book advice Message-ID: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> hi is there anyone can suggest me a good book to learn python? i read many but there is always something unclear or examples which give me errors. how can I start building a sound educational background thanks for any help best regards From joel.goldstick at gmail.com Fri Mar 1 16:23:20 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 1 Mar 2013 16:23:20 -0500 Subject: book advice In-Reply-To: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> References: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> Message-ID: On Fri, Mar 1, 2013 at 3:59 PM, leonardo selmi wrote: > hi > > is there anyone can suggest me a good book to learn python? i read many > but there is always something unclear or examples which give me errors. > how can I start building a sound educational background > start here: http://www.python.org/doc/ There are lots of links for different levels and learning styles. Keep at it. Move from tutorial when you get too stuck. > > thanks for any help > > best regards > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From msarro at gmail.com Fri Mar 1 17:20:42 2013 From: msarro at gmail.com (Matty Sarro) Date: Fri, 1 Mar 2013 17:20:42 -0500 Subject: book advice In-Reply-To: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> References: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> Message-ID: Google "learn python the hard way" by Zed A. Shaw. It's free and fantastic. Read it, and once you're done read "The Pragmatic Programmer " On Mar 1, 2013 4:04 PM, "leonardo selmi" wrote: > hi > > is there anyone can suggest me a good book to learn python? i read many > but there is always something unclear or examples which give me errors. > how can I start building a sound educational background > > thanks for any help > > best regards > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Fri Mar 1 22:01:18 2013 From: davea at davea.name (Dave Angel) Date: Fri, 01 Mar 2013 22:01:18 -0500 Subject: book advice In-Reply-To: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> References: <26877B1D-9857-4730-AA4E-A545779521E1@icloud.com> Message-ID: <51316B7E.7050200@davea.name> On 03/01/2013 03:59 PM, leonardo selmi wrote: > hi > > is there anyone can suggest me a good book to learn python? i read many but there is always something unclear or examples which give me errors. > how can I start building a sound educational background > > thanks for any help > > best regards > The question isn't even clear. You should explain that Python is your first programming language, and you should also tell us what version of Python you're trying to use, and on what OS. Your first tutorial MUST be oriented to match both of these, or you're going to have too much trouble with compatibilities to learn much. Say you're using a particular tutorial, and you have successfully done each of the samples, and understand how they worked. If you then come across a sample which gives you errors, why not post them here, and ask for help. As often as not, it's a typo when you copied the example, or it's a version mismatch. Likewise, if you then find something that's unclear, there are really only three possibilities: 1) the author blew it, either by poor explanation or by using concepts not previously explained properly 2) you didn't understand one of the earlier concepts, or 3) you're going at too fast a pace for your abilities. (That's not a knock on your abilities, we all run at a different pace while first learning than we do when we're acclimated to a topic) When I come across unclear explanation, and I want to understand it, I stop after a couple of passes through the explanation, and try some stuff. Either the exercises in the same tutorial, or just some related things that let me get a handle on things. Once I can express the unclarity in a small sample program, it's the perfect time to post it here, and ask why it works the way it does (or doesn't). If you stick to common parts of the standard library, you'll probably find the tutor at python.org mailing list to be easier to get help at. I read both, and respond where I can. -- DaveA From bryan.devaney at gmail.com Tue Mar 5 06:55:26 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Tue, 5 Mar 2013 03:55:26 -0800 (PST) Subject: book advice In-Reply-To: References: Message-ID: On Friday, March 1, 2013 8:59:12 PM UTC, leonardo selmi wrote: > hi > > > > is there anyone can suggest me a good book to learn python? i read many but there is always something unclear or examples which give me errors. > > how can I start building a sound educational background > > > > thanks for any help > > > > best regards If you have net access and are learning your first programming language, I'd say head on over to one of the free web python courses that include an online interpreter. It sorts out a great deal of the 'incompatible version' problems people have with offline tutorials. I'm not sure what the policy is in regards linking to one so I'll just say Google one. Once you've found your feet, I do hear good things about 'learn python the hard way' but I've not read it myself. Generally once you've covered the foundations and understand the terms, Python.org's docs are very good. From bryan.devaney at gmail.com Tue Mar 5 06:55:26 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Tue, 5 Mar 2013 03:55:26 -0800 (PST) Subject: book advice In-Reply-To: References: Message-ID: On Friday, March 1, 2013 8:59:12 PM UTC, leonardo selmi wrote: > hi > > > > is there anyone can suggest me a good book to learn python? i read many but there is always something unclear or examples which give me errors. > > how can I start building a sound educational background > > > > thanks for any help > > > > best regards If you have net access and are learning your first programming language, I'd say head on over to one of the free web python courses that include an online interpreter. It sorts out a great deal of the 'incompatible version' problems people have with offline tutorials. I'm not sure what the policy is in regards linking to one so I'll just say Google one. Once you've found your feet, I do hear good things about 'learn python the hard way' but I've not read it myself. Generally once you've covered the foundations and understand the terms, Python.org's docs are very good. From fjctlzy at gmail.com Tue Mar 5 07:32:31 2013 From: fjctlzy at gmail.com (fjctlzy at gmail.com) Date: Tue, 5 Mar 2013 12:32:31 +0000 Subject: =?utf-8?Q?RE:_book_advice?= In-Reply-To: References: , Message-ID: <5135e5e6.03d9440a.3636.ffffb74d@mx.google.com> I suggest theses( answers from quora: https://www.quora.com/Python-programming-language-1/How-can-I-learn-to-program-in-Python): The Official Python Tutorial - docs.python.org/tutorial/ "Dive Into Python", by Mark Pilgrim - www.diveintopython.net/ "A Byte of Python" - swaroopch.com/notes/Python Google's Intro to Python Class (online) - code.google.com/edu/languages/google-python-class/ "The New Boston" Programming Python Tutorials - youtube.com/user/thenewboston#g/c/EA1FEF17E1E5C0DA "Building Skills in Python", by Steven F. Lott - homepage.mac.com/s_lott/books/python/html/index.html "Think Python: How to Think Like a Computer Scientist" -greenteapress.com/thinkpython/thinkpython.html "Code Like a Pythonista: Idiomatic Python" - python.net/~goodger/projects/pycon/2007/idiomatic/handout.html OpenCourseWare: MIT 6.00 Introduction to Computer Science and Programming - ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/video-lectures "Learn Python the Hard Way" by Zed Shaw - learnpythonthehardway.com Practice Questions at PySchools - pyschools.com Begin Python - beginpython.com More Tutorials - awaretek.com/tutorials.html New - Udacity.com has many courses that use Python LearnStreet Python course: http://www.learnstreet.com/lesso... For beginners: Codecademy For beginners: Learn Python Programming Through Examples - Decent package with good example set. ?? Windows ?? ???: Bryan Devaney ????: ?2013???3???5?? ?19?:?55 ???: comp.lang.python at googlegroups.com ??: python-list at python.org ??: Re: book advice On Friday, March 1, 2013 8:59:12 PM UTC, leonardo selmi wrote: > hi > > > > is there anyone can suggest me a good book to learn python? i read many but there is always something unclear or examples which give me errors. > > how can I start building a sound educational background > > > > thanks for any help > > > > best regards If you have net access and are learning your first programming language, I'd say head on over to one of the free web python courses that include an online interpreter. It sorts out a great deal of the 'incompatible version' problems people have with offline tutorials. I'm not sure what the policy is in regards linking to one so I'll just say Google one. Once you've found your feet, I do hear good things about 'learn python the hard way' but I've not read it myself. Generally once you've covered the foundations and understand the terms, Python.org's docs are very good. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Wed Mar 6 05:10:31 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 6 Mar 2013 02:10:31 -0800 (PST) Subject: book advice References: Message-ID: <0eb63659-1285-43d8-90b6-a8ad965d31a9@y7g2000pbu.googlegroups.com> On Mar 2, 1:59?am, leonardo selmi wrote: > hi > > is there anyone can suggest me a good book to learn python? i read many but there is always > something unclear or examples which give me errors. The following written assuming you are as new to programming generally as to python specifically. If not then please excuse me. it is written based on this line: > how can I start building a sound educational background It is completely natural that you assume learning programming means learning a programming language. And in that context python is as good a choice as you could make. However the assumption is wrong-headed. Sure you cannot program without using some programming language. Yet knowing a programming language does not do much by way of knowing programming. Look up any of the online resources on computer science and you will find courses/material on a variety of stuff such as: - operating systems - compilers - data structures - algorithms - a variety of almost unrelated flavors of math (eg graph theory, discrete math, numerical analysis) - a variety of almost unrelated flavors of theory (eg semantics, automata theory etc) - then all sorts of 'modern' stuff eg web/security/cloud etc Somewhere in all this you would find a course on programming languages and an intro course on programming -- probably using python or some other language. Now I will admit that this 'classical' approach is often misguided and has wrong emphasis. I have a series of blog posts starting http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-1.html on the mess in CS education. However the mess in CS education notwithstanding, the fact does not change that for a 'sound educational background' you should be spending 1/5 your time on a specific programming technology such as python and the remaining on more generic stuff such as Ive listed above From solipsis at pitrou.net Fri Mar 1 17:38:28 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 1 Mar 2013 22:38:28 +0000 (UTC) Subject: ANN: pathlib 0.8 Message-ID: pathlib 0.8 has been released at https://pypi.python.org/pypi/pathlib/ Changes ------- - Add PurePath.name and PurePath.anchor. - Add Path.owner and Path.group. - Add Path.replace(). - Add Path.as_uri(). - Issue #10: when creating a file with Path.open(), don't set the executable bit. - Issue #11: fix comparisons with non-Path objects. What is pathlib? ---------------- 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.7. Documentation ------------- The full documentation can be read at `Read the Docs `_. Contributing ------------ The issue tracker and repository are hosted by `BitBucket `_. Regards Antoine. From andydtaylor at gmail.com Fri Mar 1 19:12:16 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Fri, 1 Mar 2013 16:12:16 -0800 (PST) Subject: Best way to convert number of minutes to hh:mm AM/PM? Message-ID: Hi, I need to create a list of equally spaced times (as in hh:mm AM/PM) within a day to loop through. Having selected 30 minute intervals I figured I could: * Create a list from 1 to 48 * Multiply each value by 30 * Convert minutes to a time. datetime.timedelta seems to do this, but it's not a full timestamp which means strftime can't format me a time with am/pm. can anyone suggest a good approach to use? Ultimately I'd like to generate an equivalent to this text/format:'2:30 pm' Thanks, Andy From python at mrabarnett.plus.com Fri Mar 1 19:33:29 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Mar 2013 00:33:29 +0000 Subject: Best way to convert number of minutes to hh:mm AM/PM? In-Reply-To: References: Message-ID: <513148D9.5020507@mrabarnett.plus.com> On 2013-03-02 00:12, andydtaylor at gmail.com wrote: > Hi, > > I need to create a list of equally spaced times (as in hh:mm AM/PM) within a day to loop through. Having selected 30 minute intervals I figured I could: > > * Create a list from 1 to 48 > * Multiply each value by 30 > * Convert minutes to a time. datetime.timedelta seems to do this, but it's not a full timestamp which means strftime can't format me a time with am/pm. > > can anyone suggest a good approach to use? Ultimately I'd like to generate an equivalent to this text/format:'2:30 pm' > You can still use strftime, just pick a day but don't include it in the format. You can make the list like this: [(datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=30) * i).strftime("%H:%M%p") for i in range(48)] From vlastimil.brom at gmail.com Fri Mar 1 19:58:04 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 2 Mar 2013 01:58:04 +0100 Subject: Best way to convert number of minutes to hh:mm AM/PM? In-Reply-To: References: Message-ID: 2013/3/2 : > Hi, > > I need to create a list of equally spaced times (as in hh:mm AM/PM) within a day to loop through. Having selected 30 minute intervals I figured I could: > > * Create a list from 1 to 48 > * Multiply each value by 30 > * Convert minutes to a time. datetime.timedelta seems to do this, but it's not a full timestamp which means strftime can't format me a time with am/pm. > > can anyone suggest a good approach to use? Ultimately I'd like to generate an equivalent to this text/format:'2:30 pm' > > Thanks, > > > Andy > -- > http://mail.python.org/mailman/listinfo/python-list Hi, you may use e.g. gmtime and only take the hours and minutes part into account; the drawback is the range calculation in seconds: >>> [time.strftime("%I:%M%p", time.gmtime(s)) for s in range(0, 86401, 1800)] ['12:00AM', '12:30AM', '01:00AM', '01:30AM', '02:00AM', '02:30AM', '03:00AM', '03:30AM', '04:00AM', '04:30AM', '05:00AM', '05:30AM', '06:00AM', '06:30AM', '07:00AM', '07:30AM', '08:00AM', '08:30AM', '09:00AM', '09:30AM', '10:00AM', '10:30AM', '11:00AM', '11:30AM', '12:00PM', '12:30PM', '01:00PM', '01:30PM', '02:00PM', '02:30PM', '03:00PM', '03:30PM', '04:00PM', '04:30PM', '05:00PM', '05:30PM', '06:00PM', '06:30PM', '07:00PM', '07:30PM', '08:00PM', '08:30PM', '09:00PM', '09:30PM', '10:00PM', '10:30PM', '11:00PM', '11:30PM', '12:00AM'] >>> regards, vbr From cs at zip.com.au Fri Mar 1 20:22:57 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 2 Mar 2013 12:22:57 +1100 Subject: Best way to convert number of minutes to hh:mm AM/PM? In-Reply-To: References: Message-ID: <20130302012257.GA93392@cskk.homeip.net> On 01Mar2013 16:12, andydtaylor at gmail.com wrote: | I need to create a list of equally spaced times (as in hh:mm | AM/PM) within a day to loop through. Having selected 30 minute | intervals I figured I could: | | * Create a list from 1 to 48 | * Multiply each value by 30 | * Convert minutes to a time. datetime.timedelta seems to do this, | but it's not a full timestamp which means strftime can't format me | a time with am/pm. | | can anyone suggest a good approach to use? Ultimately I'd like | to generate an equivalent to this text/format:'2:30 pm' If they're just minutes to hours and minutes you don't need datetime; it is most useful to handle the many complexities of calendars. There are 60 minutes to an hour. So something like (untested): for n in range(0,48): # counts 0..47 inclusive minutes = 30 * (n + 1) hours = minutes // 60 minutes = minutes % 60 if hours >= 12: ampm = 'pm' hours -= 12 else: ampm = 'am' if hours < 1: hours += 12 print '%02d:%02d %s" % (hours, minutes, ampm) Cheers, -- Cameron Simpson The Borg assimilated my race and all I got was this lousy tagline. - Cath Lawrence From andydtaylor at gmail.com Sat Mar 2 07:09:50 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sat, 2 Mar 2013 04:09:50 -0800 (PST) Subject: Best way to convert number of minutes to hh:mm AM/PM? In-Reply-To: References: Message-ID: <6912a0e2-11ca-4c66-b989-ee78cfd853d4@googlegroups.com> Brilliant, thanks to all From andydtaylor at gmail.com Sat Mar 2 07:09:50 2013 From: andydtaylor at gmail.com (andydtaylor at gmail.com) Date: Sat, 2 Mar 2013 04:09:50 -0800 (PST) Subject: Best way to convert number of minutes to hh:mm AM/PM? In-Reply-To: References: Message-ID: <6912a0e2-11ca-4c66-b989-ee78cfd853d4@googlegroups.com> Brilliant, thanks to all From sarbjit1987 at gmail.com Sat Mar 2 01:24:31 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Fri, 1 Mar 2013 22:24:31 -0800 (PST) Subject: How to install development package on linux? Message-ID: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- ./configure ?prefix= --enable-shared Make ?i install But I am not able to find how to install development package from source code. Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. Thanks, Sarbjit From kwpolska at gmail.com Sat Mar 2 03:45:08 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sat, 2 Mar 2013 09:45:08 +0100 Subject: How to install development package on linux? In-Reply-To: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. > > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- > > ./configure ?prefix= --enable-shared > Make ?i install > > But I am not able to find how to install development package from source code. > > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. > > Thanks, > Sarbjit > -- > http://mail.python.org/mailman/listinfo/python-list Why do you use source tarballs? Your distro should provide nice binary packages for Python and mod_wsgi. And in case it doesn?t, your distro sucks and you should find a better one. The development things are usually installed by default by most things. Distributions offer them in -dev or -devel packages. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From sarbjit1987 at gmail.com Sat Mar 2 13:00:51 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 10:00:51 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Saturday, March 2, 2013 2:15:08 PM UTC+5:30, Kwpolska wrote: > On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: > > > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. > > > > > > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- > > > > > > ./configure ?prefix= --enable-shared > > > Make ?i install > > > > > > But I am not able to find how to install development package from source code. > > > > > > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. > > > > > > Thanks, > > > Sarbjit > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Why do you use source tarballs? Your distro should provide nice > > binary packages for Python and mod_wsgi. And in case it doesn?t, your > > distro sucks and you should find a better one. > > > > The development things are usually installed by default by most > > things. Distributions offer them in -dev or -devel packages. > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html I am using Red Hat 5, could you please give some pointers on how to install these packages? From sarbjit1987 at gmail.com Sat Mar 2 13:00:51 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 10:00:51 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Saturday, March 2, 2013 2:15:08 PM UTC+5:30, Kwpolska wrote: > On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: > > > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. > > > > > > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- > > > > > > ./configure ?prefix= --enable-shared > > > Make ?i install > > > > > > But I am not able to find how to install development package from source code. > > > > > > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. > > > > > > Thanks, > > > Sarbjit > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Why do you use source tarballs? Your distro should provide nice > > binary packages for Python and mod_wsgi. And in case it doesn?t, your > > distro sucks and you should find a better one. > > > > The development things are usually installed by default by most > > things. Distributions offer them in -dev or -devel packages. > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html I am using Red Hat 5, could you please give some pointers on how to install these packages? From kwpolska at gmail.com Sat Mar 2 14:52:50 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sat, 2 Mar 2013 20:52:50 +0100 Subject: Fwd: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 7:00 PM, Sarbjit singh wrote: > On Saturday, March 2, 2013 2:15:08 PM UTC+5:30, Kwpolska wrote: >> On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: >> >> > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. >> >> > >> >> > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- >> >> > >> >> > ./configure ?prefix= --enable-shared >> >> > Make ?i install >> >> > >> >> > But I am not able to find how to install development package from source code. >> >> > >> >> > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. >> >> > >> >> > Thanks, >> >> > Sarbjit >> >> > -- >> >> > http://mail.python.org/mailman/listinfo/python-list >> >> >> >> Why do you use source tarballs? Your distro should provide nice >> >> binary packages for Python and mod_wsgi. And in case it doesn?t, your >> >> distro sucks and you should find a better one. >> >> >> >> The development things are usually installed by default by most >> >> things. Distributions offer them in -dev or -devel packages. >> >> >> >> -- >> >> Kwpolska | GPG KEY: 5EAAEA16 >> >> stop html mail | always bottom-post >> >> http://asciiribbon.org | http://caliburn.nl/topposting.html > > I am using Red Hat 5, could you please give some pointers on how to install these packages? > -- > http://mail.python.org/mailman/listinfo/python-list Impossible, unless you: (a) build such packages yourself (Fedora .spec files may help you); or (b) upgrade to RHEL 6, which offers packages for python 2.6 and mod_wsgi; or (c) look for such packages on the Internet (you probably won?t find any). So, get back to compiling from source. Have you actually tried building those packages before asking? Because, according to the Arch Linux PKGBUILDs for python2 and mod_wsgi2, it doesn?t have any specific switches to enable anything ?devel-related? (also, Arch Linux doesn?t bother with the dumb -dev(el) packages, which make no sense in real life). -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From sarbjit1987 at gmail.com Sun Mar 3 01:14:01 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:14:01 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sunday, March 3, 2013 1:22:50 AM UTC+5:30, Kwpolska wrote: > On Sat, Mar 2, 2013 at 7:00 PM, Sarbjit singh wrote: > > > On Saturday, March 2, 2013 2:15:08 PM UTC+5:30, Kwpolska wrote: > > >> On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: > > >> > > >> > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. > > >> > > >> > > > >> > > >> > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- > > >> > > >> > > > >> > > >> > ./configure ?prefix= --enable-shared > > >> > > >> > Make ?i install > > >> > > >> > > > >> > > >> > But I am not able to find how to install development package from source code. > > >> > > >> > > > >> > > >> > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. > > >> > > >> > > > >> > > >> > Thanks, > > >> > > >> > Sarbjit > > >> > > >> > -- > > >> > > >> > http://mail.python.org/mailman/listinfo/python-list > > >> > > >> > > >> > > >> Why do you use source tarballs? Your distro should provide nice > > >> > > >> binary packages for Python and mod_wsgi. And in case it doesn?t, your > > >> > > >> distro sucks and you should find a better one. > > >> > > >> > > >> > > >> The development things are usually installed by default by most > > >> > > >> things. Distributions offer them in -dev or -devel packages. > > >> > > >> > > >> > > >> -- > > >> > > >> Kwpolska | GPG KEY: 5EAAEA16 > > >> > > >> stop html mail | always bottom-post > > >> > > >> http://asciiribbon.org | http://caliburn.nl/topposting.html > > > > > > I am using Red Hat 5, could you please give some pointers on how to install these packages? > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Impossible, unless you: > > (a) build such packages yourself (Fedora .spec files may help you); or > > (b) upgrade to RHEL 6, which offers packages for python 2.6 and mod_wsgi; or > > (c) look for such packages on the Internet (you probably won?t find any). > > > > So, get back to compiling from source. Have you actually tried > > building those packages before asking? Because, according to the Arch > > Linux PKGBUILDs for python2 and mod_wsgi2, it doesn?t have any > > specific switches to enable anything ?devel-related? (also, Arch Linux > > doesn?t bother with the dumb -dev(el) packages, which make no sense in > > real life). > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html Its not possible for me to switch to Red Hat6 at the moment. Yes, I did tried compiling these from the source code and got some errors. I am using Xaamp for linux and following the below link for configuring python/mod_wsgi :- http://www.apachefriends.org/f/viewtopic.php?f=17&t=42975 When I initially tried to compile mod_wsgi, I was getting errors which got resolved by using development package fro Xammp for linux. (Solution found on google) Now I am getting the following compiling errors:- ######################################################### mod_wsgi.c:14967: error: expected expression before ')' token mod_wsgi.c:14974: error: expected ';' before 'do' mod_wsgi.c:14979: error: expected ';' before '}' token mod_wsgi.c:14984: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:14989: error: expected expression before 'module' mod_wsgi.c: In function 'wsgi_allow_access': mod_wsgi.c:15003: error: 'PyObject' undeclared (first use in this function) mod_wsgi.c:15003: error: 'modules' undeclared (first use in this function) mod_wsgi.c:15004: error: expected expression before 'module' mod_wsgi.c:15051: error: 'Py_BEGIN_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15052: error: expected ';' before 'apr_thread_mutex_lock' mod_wsgi.c:15053: error: 'Py_END_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15056: error: expected ';' before 'modules' mod_wsgi.c:15057: error: expected identifier or '(' before '=' token mod_wsgi.c:15059: error: expected expression before 'module' mod_wsgi.c:15061: error: expected expression before 'module' mod_wsgi.c:15070: error: expected expression before 'module' mod_wsgi.c:15071: error: expected expression before 'module' mod_wsgi.c:15082: error: expected expression before 'module' mod_wsgi.c:15083: error: expected identifier or '(' before '=' token mod_wsgi.c:15089: error: expected expression before 'module' mod_wsgi.c:15090: error: expected identifier or '(' before '=' token mod_wsgi.c:15105: error: expected expression before 'module' mod_wsgi.c:15106: error: 'module_dict' undeclared (first use in this function) mod_wsgi.c:15107: error: 'object' undeclared (first use in this function) mod_wsgi.c:15109: error: expected expression before 'module' mod_wsgi.c:15113: error: 'vars' undeclared (first use in this function) mod_wsgi.c:15114: error: 'args' undeclared (first use in this function) mod_wsgi.c:15115: error: 'flag' undeclared (first use in this function) mod_wsgi.c:15116: error: 'method' undeclared (first use in this function) mod_wsgi.c:15133: error: 'Py_None' undeclared (first use in this function) mod_wsgi.c:15136: warning: implicit declaration of function 'PyBool_Check' mod_wsgi.c:15137: error: 'Py_True' undeclared (first use in this function) mod_wsgi.c:15142: error: expected ';' before 'do' mod_wsgi.c:15148: error: expected ';' before '}' token mod_wsgi.c:15161: error: 'AuthObject' has no member named 'r' mod_wsgi.c:15165: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15168: error: 'PyExc_AttributeError' undeclared (first use in this function) mod_wsgi.c:15170: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15183: error: expected expression before ')' token mod_wsgi.c:15190: error: expected ';' before 'do' mod_wsgi.c:15195: error: expected ';' before '}' token mod_wsgi.c:15200: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:15205: error: expected expression before 'module' mod_wsgi.c: In function 'wsgi_hook_check_user_id': mod_wsgi.c:15260: error: 'PyObject' undeclared (first use in this function) mod_wsgi.c:15260: error: 'modules' undeclared (first use in this function) mod_wsgi.c:15261: error: expected expression before 'module' mod_wsgi.c:15306: error: 'Py_BEGIN_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15307: error: expected ';' before 'apr_thread_mutex_lock' mod_wsgi.c:15308: error: 'Py_END_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15311: error: expected ';' before 'modules' mod_wsgi.c:15312: error: expected identifier or '(' before '=' token mod_wsgi.c:15314: error: expected expression before 'module' mod_wsgi.c:15316: error: expected expression before 'module' mod_wsgi.c:15325: error: expected expression before 'module' mod_wsgi.c:15326: error: expected expression before 'module' mod_wsgi.c:15337: error: expected expression before 'module' mod_wsgi.c:15338: error: expected identifier or '(' before '=' token mod_wsgi.c:15344: error: expected expression before 'module' mod_wsgi.c:15345: error: expected identifier or '(' before '=' token mod_wsgi.c:15360: error: expected expression before 'module' mod_wsgi.c:15361: error: 'module_dict' undeclared (first use in this function) mod_wsgi.c:15362: error: 'object' undeclared (first use in this function) mod_wsgi.c:15364: error: expected expression before 'module' mod_wsgi.c:15368: error: 'vars' undeclared (first use in this function) mod_wsgi.c:15369: error: 'args' undeclared (first use in this function) mod_wsgi.c:15370: error: 'result' undeclared (first use in this function) mod_wsgi.c:15371: error: 'method' undeclared (first use in this function) mod_wsgi.c:15388: error: 'Py_None' undeclared (first use in this function) mod_wsgi.c:15402: error: 'Py_True' undeclared (first use in this function) mod_wsgi.c:15405: error: 'Py_False' undeclared (first use in this function) mod_wsgi.c:15417: error: 'PyExc_TypeError' undeclared (first use in this function) mod_wsgi.c:15433: error: 'AuthObject' has no member named 'r' mod_wsgi.c:15437: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15440: error: 'PyExc_AttributeError' undeclared (first use in this function) mod_wsgi.c:15442: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15455: error: expected expression before ')' token mod_wsgi.c:15462: error: expected ';' before 'do' mod_wsgi.c:15467: error: expected ';' before '}' token mod_wsgi.c:15472: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:15477: error: expected expression before 'module' apxs:Error: Command failed with rc=65536 . make: *** [mod_wsgi.la] Error 1 ######################################################### I searched on google and found these errors could be due to missing python header files which would be available in development package. So I am struggling to make it work. Thanks, Sarbjit From sarbjit1987 at gmail.com Sun Mar 3 01:14:01 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:14:01 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sunday, March 3, 2013 1:22:50 AM UTC+5:30, Kwpolska wrote: > On Sat, Mar 2, 2013 at 7:00 PM, Sarbjit singh wrote: > > > On Saturday, March 2, 2013 2:15:08 PM UTC+5:30, Kwpolska wrote: > > >> On Sat, Mar 2, 2013 at 7:24 AM, Sarbjit singh wrote: > > >> > > >> > Sorry for this basic question but I am having problem compiling mod_wsgi on Linux. As per mod_wsgi package site, user must have python development package installed on system. > > >> > > >> > > > >> > > >> > I had installed Python2.7 on my Linux system from source code, using the following configuration few months back :- > > >> > > >> > > > >> > > >> > ./configure ?prefix= --enable-shared > > >> > > >> > Make ?i install > > >> > > >> > > > >> > > >> > But I am not able to find how to install development package from source code. > > >> > > >> > > > >> > > >> > Can some one please conform if I can install the development package from the same source code (Downloaded from Python Website for Unix) and please share the configuration switch for the same. > > >> > > >> > > > >> > > >> > Thanks, > > >> > > >> > Sarbjit > > >> > > >> > -- > > >> > > >> > http://mail.python.org/mailman/listinfo/python-list > > >> > > >> > > >> > > >> Why do you use source tarballs? Your distro should provide nice > > >> > > >> binary packages for Python and mod_wsgi. And in case it doesn?t, your > > >> > > >> distro sucks and you should find a better one. > > >> > > >> > > >> > > >> The development things are usually installed by default by most > > >> > > >> things. Distributions offer them in -dev or -devel packages. > > >> > > >> > > >> > > >> -- > > >> > > >> Kwpolska | GPG KEY: 5EAAEA16 > > >> > > >> stop html mail | always bottom-post > > >> > > >> http://asciiribbon.org | http://caliburn.nl/topposting.html > > > > > > I am using Red Hat 5, could you please give some pointers on how to install these packages? > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > Impossible, unless you: > > (a) build such packages yourself (Fedora .spec files may help you); or > > (b) upgrade to RHEL 6, which offers packages for python 2.6 and mod_wsgi; or > > (c) look for such packages on the Internet (you probably won?t find any). > > > > So, get back to compiling from source. Have you actually tried > > building those packages before asking? Because, according to the Arch > > Linux PKGBUILDs for python2 and mod_wsgi2, it doesn?t have any > > specific switches to enable anything ?devel-related? (also, Arch Linux > > doesn?t bother with the dumb -dev(el) packages, which make no sense in > > real life). > > > > -- > > Kwpolska | GPG KEY: 5EAAEA16 > > stop html mail | always bottom-post > > http://asciiribbon.org | http://caliburn.nl/topposting.html Its not possible for me to switch to Red Hat6 at the moment. Yes, I did tried compiling these from the source code and got some errors. I am using Xaamp for linux and following the below link for configuring python/mod_wsgi :- http://www.apachefriends.org/f/viewtopic.php?f=17&t=42975 When I initially tried to compile mod_wsgi, I was getting errors which got resolved by using development package fro Xammp for linux. (Solution found on google) Now I am getting the following compiling errors:- ######################################################### mod_wsgi.c:14967: error: expected expression before ')' token mod_wsgi.c:14974: error: expected ';' before 'do' mod_wsgi.c:14979: error: expected ';' before '}' token mod_wsgi.c:14984: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:14989: error: expected expression before 'module' mod_wsgi.c: In function 'wsgi_allow_access': mod_wsgi.c:15003: error: 'PyObject' undeclared (first use in this function) mod_wsgi.c:15003: error: 'modules' undeclared (first use in this function) mod_wsgi.c:15004: error: expected expression before 'module' mod_wsgi.c:15051: error: 'Py_BEGIN_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15052: error: expected ';' before 'apr_thread_mutex_lock' mod_wsgi.c:15053: error: 'Py_END_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15056: error: expected ';' before 'modules' mod_wsgi.c:15057: error: expected identifier or '(' before '=' token mod_wsgi.c:15059: error: expected expression before 'module' mod_wsgi.c:15061: error: expected expression before 'module' mod_wsgi.c:15070: error: expected expression before 'module' mod_wsgi.c:15071: error: expected expression before 'module' mod_wsgi.c:15082: error: expected expression before 'module' mod_wsgi.c:15083: error: expected identifier or '(' before '=' token mod_wsgi.c:15089: error: expected expression before 'module' mod_wsgi.c:15090: error: expected identifier or '(' before '=' token mod_wsgi.c:15105: error: expected expression before 'module' mod_wsgi.c:15106: error: 'module_dict' undeclared (first use in this function) mod_wsgi.c:15107: error: 'object' undeclared (first use in this function) mod_wsgi.c:15109: error: expected expression before 'module' mod_wsgi.c:15113: error: 'vars' undeclared (first use in this function) mod_wsgi.c:15114: error: 'args' undeclared (first use in this function) mod_wsgi.c:15115: error: 'flag' undeclared (first use in this function) mod_wsgi.c:15116: error: 'method' undeclared (first use in this function) mod_wsgi.c:15133: error: 'Py_None' undeclared (first use in this function) mod_wsgi.c:15136: warning: implicit declaration of function 'PyBool_Check' mod_wsgi.c:15137: error: 'Py_True' undeclared (first use in this function) mod_wsgi.c:15142: error: expected ';' before 'do' mod_wsgi.c:15148: error: expected ';' before '}' token mod_wsgi.c:15161: error: 'AuthObject' has no member named 'r' mod_wsgi.c:15165: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15168: error: 'PyExc_AttributeError' undeclared (first use in this function) mod_wsgi.c:15170: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15183: error: expected expression before ')' token mod_wsgi.c:15190: error: expected ';' before 'do' mod_wsgi.c:15195: error: expected ';' before '}' token mod_wsgi.c:15200: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:15205: error: expected expression before 'module' mod_wsgi.c: In function 'wsgi_hook_check_user_id': mod_wsgi.c:15260: error: 'PyObject' undeclared (first use in this function) mod_wsgi.c:15260: error: 'modules' undeclared (first use in this function) mod_wsgi.c:15261: error: expected expression before 'module' mod_wsgi.c:15306: error: 'Py_BEGIN_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15307: error: expected ';' before 'apr_thread_mutex_lock' mod_wsgi.c:15308: error: 'Py_END_ALLOW_THREADS' undeclared (first use in this function) mod_wsgi.c:15311: error: expected ';' before 'modules' mod_wsgi.c:15312: error: expected identifier or '(' before '=' token mod_wsgi.c:15314: error: expected expression before 'module' mod_wsgi.c:15316: error: expected expression before 'module' mod_wsgi.c:15325: error: expected expression before 'module' mod_wsgi.c:15326: error: expected expression before 'module' mod_wsgi.c:15337: error: expected expression before 'module' mod_wsgi.c:15338: error: expected identifier or '(' before '=' token mod_wsgi.c:15344: error: expected expression before 'module' mod_wsgi.c:15345: error: expected identifier or '(' before '=' token mod_wsgi.c:15360: error: expected expression before 'module' mod_wsgi.c:15361: error: 'module_dict' undeclared (first use in this function) mod_wsgi.c:15362: error: 'object' undeclared (first use in this function) mod_wsgi.c:15364: error: expected expression before 'module' mod_wsgi.c:15368: error: 'vars' undeclared (first use in this function) mod_wsgi.c:15369: error: 'args' undeclared (first use in this function) mod_wsgi.c:15370: error: 'result' undeclared (first use in this function) mod_wsgi.c:15371: error: 'method' undeclared (first use in this function) mod_wsgi.c:15388: error: 'Py_None' undeclared (first use in this function) mod_wsgi.c:15402: error: 'Py_True' undeclared (first use in this function) mod_wsgi.c:15405: error: 'Py_False' undeclared (first use in this function) mod_wsgi.c:15417: error: 'PyExc_TypeError' undeclared (first use in this function) mod_wsgi.c:15433: error: 'AuthObject' has no member named 'r' mod_wsgi.c:15437: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15440: error: 'PyExc_AttributeError' undeclared (first use in this function) mod_wsgi.c:15442: error: 'AuthObject' has no member named 'log' mod_wsgi.c:15455: error: expected expression before ')' token mod_wsgi.c:15462: error: expected ';' before 'do' mod_wsgi.c:15467: error: expected ';' before '}' token mod_wsgi.c:15472: error: too many arguments to function 'wsgi_log_python_error' mod_wsgi.c:15477: error: expected expression before 'module' apxs:Error: Command failed with rc=65536 . make: *** [mod_wsgi.la] Error 1 ######################################################### I searched on google and found these errors could be due to missing python header files which would be available in development package. So I am struggling to make it work. Thanks, Sarbjit From benjamin.kaplan at case.edu Sun Mar 3 01:23:50 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 2 Mar 2013 22:23:50 -0800 Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh wrote: > > I searched on google and found these errors could be due to missing python header files which would be available in development package. > > So I am struggling to make it work. A "development package" is meaningless when you aren't installing it from a package. Debian's binary packages don't include the header files, so they put them in a different package. Since you compiled from source, you already have the header files. Did you include the directory you installed Python into on your library and includes paths? From sarbjit1987 at gmail.com Sun Mar 3 01:39:46 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:39:46 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sunday, March 3, 2013 11:53:50 AM UTC+5:30, Benjamin Kaplan wrote: > On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh wrote: > > > > > > I searched on google and found these errors could be due to missing python header files which would be available in development package. > > > > > > So I am struggling to make it work. > > > > > > A "development package" is meaningless when you aren't installing it > > from a package. Debian's binary packages don't include the header > > files, so they put them in a different package. Since you compiled > > from source, you already have the header files. Did you include the > > directory you installed Python into on your library and includes > > paths? Yes, I configured the makefile for mod_wsgi as without any error : ./configure --prefix=/opt/lampp/ --with-apxs=/opt/lampp/bin/apxs --with-python=/opt/lampp/python/bin/python2.7 --with-mutex-dir=/opt/lampp/var/run/wsgi From sarbjit1987 at gmail.com Sun Mar 3 01:46:25 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:46:25 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: <6aa5366c-0292-46fc-afc0-057aba810276@googlegroups.com> On Sunday, March 3, 2013 12:09:46 PM UTC+5:30, Sarbjit singh wrote: > On Sunday, March 3, 2013 11:53:50 AM UTC+5:30, Benjamin Kaplan wrote: > > > On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh wrote: > > > > > > > > > > > > > > I searched on google and found these errors could be due to missing python header files which would be available in development package. > > > > > > > > > > > > > > So I am struggling to make it work. > > > > > > > > > > > > > > > > > > A "development package" is meaningless when you aren't installing it > > > > > > from a package. Debian's binary packages don't include the header > > > > > > files, so they put them in a different package. Since you compiled > > > > > > from source, you already have the header files. Did you include the > > > > > > directory you installed Python into on your library and includes > > > > > > paths? > > > > Yes, I configured the makefile for mod_wsgi as without any error : > > > > ./configure --prefix=/opt/lampp/ --with-apxs=/opt/lampp/bin/apxs --with-python=/opt/lampp/python/bin/python2.7 --with-mutex-dir=/opt/lampp/var/run/wsgi Also my LD_LIBRARY_PATH does have path as : /opt/lammp/python/lib Just one more point, while initially I was trying to compiling the mod_wsgi, I was getting error for "libpython2.7.1.0.so Shared library error". I resolved it by creating a soft link to this file in my /usr/lib and /usr/lib64. At that point also my LD_LIBRARY_PATH was having path for python lib but was resolved with soft link only. From sarbjit1987 at gmail.com Sun Mar 3 01:46:25 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:46:25 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: <6aa5366c-0292-46fc-afc0-057aba810276@googlegroups.com> On Sunday, March 3, 2013 12:09:46 PM UTC+5:30, Sarbjit singh wrote: > On Sunday, March 3, 2013 11:53:50 AM UTC+5:30, Benjamin Kaplan wrote: > > > On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh wrote: > > > > > > > > > > > > > > I searched on google and found these errors could be due to missing python header files which would be available in development package. > > > > > > > > > > > > > > So I am struggling to make it work. > > > > > > > > > > > > > > > > > > A "development package" is meaningless when you aren't installing it > > > > > > from a package. Debian's binary packages don't include the header > > > > > > files, so they put them in a different package. Since you compiled > > > > > > from source, you already have the header files. Did you include the > > > > > > directory you installed Python into on your library and includes > > > > > > paths? > > > > Yes, I configured the makefile for mod_wsgi as without any error : > > > > ./configure --prefix=/opt/lampp/ --with-apxs=/opt/lampp/bin/apxs --with-python=/opt/lampp/python/bin/python2.7 --with-mutex-dir=/opt/lampp/var/run/wsgi Also my LD_LIBRARY_PATH does have path as : /opt/lammp/python/lib Just one more point, while initially I was trying to compiling the mod_wsgi, I was getting error for "libpython2.7.1.0.so Shared library error". I resolved it by creating a soft link to this file in my /usr/lib and /usr/lib64. At that point also my LD_LIBRARY_PATH was having path for python lib but was resolved with soft link only. From sarbjit1987 at gmail.com Sun Mar 3 01:39:46 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sat, 2 Mar 2013 22:39:46 -0800 (PST) Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: On Sunday, March 3, 2013 11:53:50 AM UTC+5:30, Benjamin Kaplan wrote: > On Sat, Mar 2, 2013 at 10:14 PM, Sarbjit singh wrote: > > > > > > I searched on google and found these errors could be due to missing python header files which would be available in development package. > > > > > > So I am struggling to make it work. > > > > > > A "development package" is meaningless when you aren't installing it > > from a package. Debian's binary packages don't include the header > > files, so they put them in a different package. Since you compiled > > from source, you already have the header files. Did you include the > > directory you installed Python into on your library and includes > > paths? Yes, I configured the makefile for mod_wsgi as without any error : ./configure --prefix=/opt/lampp/ --with-apxs=/opt/lampp/bin/apxs --with-python=/opt/lampp/python/bin/python2.7 --with-mutex-dir=/opt/lampp/var/run/wsgi From torriem at gmail.com Sun Mar 3 11:26:40 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Mar 2013 09:26:40 -0700 Subject: How to install development package on linux? In-Reply-To: References: <76c6aca8-50da-42d3-82e9-2d9c74785570@googlegroups.com> Message-ID: <513379C0.2090207@gmail.com> On 03/02/2013 11:39 PM, Sarbjit singh wrote: > Yes, I configured the makefile for mod_wsgi as without any error : > ./configure --prefix=/opt/lampp/ --with-apxs=/opt/lampp/bin/apxs --with-python=/opt/lampp/python/bin/python2.7 --with-mutex-dir=/opt/lampp/var/run/wsgi This is not quite right. the --with-python option should point to the python install path, not the python binary itself. It probably should be: --with-python=/opt/lampp/python Presuming that's what you used as a prefix when you built and installed python 2.7. When installing from source code, there's no such thing as a "development package." Tarballs nominally install binaries, libraries, and header files, which is the equivalent of a Red Hat rpm plus the devel rpm. In other words when you did a "make install" everything you need to compile against python 2.7 is installed to the prefix you used. From hossamalagmy at gmail.com Sat Mar 2 02:49:49 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Fri, 1 Mar 2013 23:49:49 -0800 (PST) Subject: Vodafone Smart review Message-ID: Vodafone Smart review http://natigtas7ab.blogspot.com/2012/10/vodafone-smart-review.html From hossamalagmy at gmail.com Sat Mar 2 02:50:58 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Fri, 1 Mar 2013 23:50:58 -0800 (PST) Subject: LG Optimus Black review Message-ID: LG Optimus Black review http://natigtas7ab.blogspot.com/2012/10/lg-optimus-black-review.html From hossamalagmy at gmail.com Sat Mar 2 02:52:42 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Fri, 1 Mar 2013 23:52:42 -0800 (PST) Subject: Motorola Atrix review Message-ID: <44d9f96a-237f-4b06-af55-29980507b8e9@he10g2000vbb.googlegroups.com> Motorola Atrix review http://natigtas7ab.blogspot.com/2012/10/motorola-atrix-review.html From smsm_egy2000 at yahoo.com Sat Mar 2 02:56:20 2013 From: smsm_egy2000 at yahoo.com (alagmy) Date: Fri, 1 Mar 2013 23:56:20 -0800 (PST) Subject: Samsung Galaxy Mini Message-ID: <2217c2fd-f73d-4fd0-a114-6ad3448ca9d2@y9g2000vbb.googlegroups.com> Samsung Galaxy Mini http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-mini.html From geobases.dev at gmail.com Sat Mar 2 08:37:05 2013 From: geobases.dev at gmail.com (geobases.dev at gmail.com) Date: Sat, 2 Mar 2013 05:37:05 -0800 (PST) Subject: GeoBases V5 beta release Message-ID: <8d65be8c-b3ba-402c-81d1-3e3e1e09a752@googlegroups.com> Hello! We just released the new beta version of GeoBases. For those who do not know GeoBases, this project provides tools to play with geographical data. It also works with non-geographical data, except for map visualizations :). There are embedded data sources in the project, but you can easily play with your own data in addition to the available ones. After data loading, you can: - perform various types of queries (find this key, or find keys with this property) - make fuzzy searches based on string distance (find things roughly named like this) - make phonetic searches (find things sounding like this) - make geographical searches (find things next to this place) - get results on a map, or on a graph, or export it as csv data, or as a Python object A few highlights of this new version: - sub-indexes - join clauses - better zsh autocomplete - sources admin mode - beginner's mode - phonetic search - graph display Get the code from Github https://github.com/opentraveldata/geobases Get the latest news from https://twitter.com/GeoBasesDev/ If you like it, share it! From gialloporpora at gmail.com Sat Mar 2 12:02:14 2013 From: gialloporpora at gmail.com (gialloporpora) Date: Sat, 02 Mar 2013 18:02:14 +0100 Subject: Is it correct this way to inherit from a list? Message-ID: Hi all, I would like to inherit from the list native class. really I expected that was possible to use native list method without redefining them, for example the __repr__ method. I don't know if i have made something wrong, this is my code (I obmit customized methods that I have added): from os.path import exists class vector(list): def __init__(self, *args): self._list = list(args) self._index = 0 def __getitem__(self, key): return self._list[key] def __setitem__(self, key, value): self._list[key] = value def __len__(self): return len(self._list) def __iter__(self): return self def next(self): if self._index == len(self): self._index = 0 raise StopIteration next = self._index self._index += 1 return self[next Is it correct or it exists another way to inherit from list class? Sandro From __peter__ at web.de Sat Mar 2 12:19:29 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Mar 2013 18:19:29 +0100 Subject: Is it correct this way to inherit from a list? References: Message-ID: gialloporpora wrote: > I would like to inherit from the list native class. > really I expected that was possible to use native list method without > redefining them, for example the __repr__ method. > > I don't know if i have made something wrong, this is my code (I obmit > customized methods that I have added): > > from os.path import exists > > class vector(list): > def __getitem__(self, key): > return self._list[key] [and many more] > Is it correct or it exists another way to inherit from list class? Have you considered subclassing collections.MutableSequence instead? You cannot instantiate that class until you have overridden all its abstract methods. From ian.g.kelly at gmail.com Sat Mar 2 12:22:29 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Mar 2013 10:22:29 -0700 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: Message-ID: On Sat, Mar 2, 2013 at 10:02 AM, gialloporpora wrote: > Hi all, > I would like to inherit from the list native class. > really I expected that was possible to use native list method without > redefining them, for example the __repr__ method. > > I don't know if i have made something wrong, this is my code (I obmit > customized methods that I have added): > > from os.path import exists > > class vector(list): > def __init__(self, *args): > self._list = list(args) So here you have a list subclass, but instead of taking advantage of that is-a relationship, you're creating a secondary list from the arguments and attaching it to self._list in a has-a relationship. The net effect is that you actually have two separate list objects here, with some methods operating on the list itself and some operating on the attached list. Try this instead: class Vector(list): def __new__(cls, *args): return super(Vector, cls).__new__(cls, args) def __init__(self, *args): super(Vector, self).__init__(args) The __new__ method here will receive the args in the style that you want, and then pass them up the inheritance chain to the superclass constructor, which will then just do the right thing. The __init__ method is also overridden to match the modified argspec. The super().__init__() call is included for completeness; AFAIK it doesn't actually do anything. From ian.g.kelly at gmail.com Sat Mar 2 12:26:44 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Mar 2013 10:26:44 -0700 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: Message-ID: On Sat, Mar 2, 2013 at 10:22 AM, Ian Kelly wrote: > class Vector(list): > def __new__(cls, *args): > return super(Vector, cls).__new__(cls, args) > def __init__(self, *args): > super(Vector, self).__init__(args) > > The __new__ method here will receive the args in the style that you > want, and then pass them up the inheritance chain to the superclass > constructor, which will then just do the right thing. The __init__ > method is also overridden to match the modified argspec. The > super().__init__() call is included for completeness; AFAIK it doesn't > actually do anything. I retract that. On further testing, it is actually the __init__ method that initializes the list contents, not the __new__ method. So this is all you need: class Vector(list): def __init__(self, *args): super(Vector, self).__init__(args) From gialloporpora at gmail.com Sat Mar 2 21:33:18 2013 From: gialloporpora at gmail.com (gialloporpora) Date: Sun, 03 Mar 2013 03:33:18 +0100 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: Message-ID: Risposta al messaggio di Ian Kelly : > I retract that. On further testing, it is actually the __init__ > method that initializes the list contents, not the __new__ method. So > this is all you need: > > class Vector(list): > def __init__(self, *args): > super(Vector, self).__init__(args) Thanks, it works :-), it is simpler of my implementation, thank again. Sandro -- *gialloporpora: Il nuovo album degli Atoms for Peace (con Thom Yorke dei radiohead) disponibile live: http://t.co/3VgxNFrZ Un po' troppo elettronico per me * - http://bit.ly/ZmDCze Sto ascoltando: *Pink Floyd ? Us and Them * - http://bit.ly/ZmDC2m From rantingrickjohnson at gmail.com Sat Mar 2 12:46:36 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 2 Mar 2013 09:46:36 -0800 (PST) Subject: Is it correct this way to inherit from a list? In-Reply-To: References: Message-ID: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> On Saturday, March 2, 2013 11:02:14 AM UTC-6, gialloporpora wrote: > I would like to inherit from the list native class. really > I expected that was possible to use native list method > without redefining them, for example the __repr__ method. > > [...] > > class vector(list): > def __init__(self, *args): > self._list = list(args) > self._index = 0 Here is where you go wrong. First of all why would you inherit from "list" and then create a new list as attribute, that seems a bit silly huh? If you want your custom list to "inherit" all the pre-defined methods of the python list type, then do so. >>> class MyList(list): pass >>> ml = MyList() >>> dir(ml) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> ml [] >>> ml.append('cat') >>> ml ['cat'] >>> ml.extend(range(5)) >>> ml ['cat', 0, 1, 2, 3, 4] >>> ml.sort() >>> ml [0, 1, 2, 3, 4, 'cat'] >>> isinstance(ml, list) True Quacks like a list to me. In this case you did not need to call the superclass constructor explicitly; for example. class MyList(list): def __init__(self): list.__init__(self) ...is really a waste of time because you will not have any options to pass to the super. >>> ml2 = MyList2() >>> dir(ml2) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> ml2+[10,20,30] [10, 20, 30] >>> ml2 [] >>> ml2.append('salt') >>> ml2 ['salt'] >>> isinstance(ml2, list) True If however you wanted to create a custom Tkinter widget, you would then need to pass the options from the derived class __init__ method into the superclass __init__ method, like this: class MyButton(tk.Button): def __init__(self, master, **kw): tk.Button.__init__(self, master, **kw) mb = MyButton(rootWindow, text='PushMe', command=helloButton) What are you trying to achieve exactly? From gialloporpora at gmail.com Sat Mar 2 21:30:46 2013 From: gialloporpora at gmail.com (gialloporpora) Date: Sun, 03 Mar 2013 03:30:46 +0100 Subject: Is it correct this way to inherit from a list? In-Reply-To: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> References: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> Message-ID: Risposta al messaggio di Rick Johnson : > What are you trying to achieve exactly? I would like to implement a class (vector) to works with vectors, for example using scalar multiplication: a*v = [a*v1, a*vn] and a dual class for dual vector (the only method that I'll change is the __str__ method to print it as colun. Sandro -- *gialloporpora: Il nuovo album degli Atoms for Peace (con Thom Yorke dei radiohead) disponibile live: http://t.co/3VgxNFrZ Un po' troppo elettronico per me * - http://bit.ly/ZmDCze Sto ascoltando: *Pink Floyd ? Us and Them * - http://bit.ly/ZmDC2m From rosuav at gmail.com Sat Mar 2 22:18:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 14:18:59 +1100 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 1:30 PM, gialloporpora wrote: > Risposta al messaggio di Rick Johnson : > > >> What are you trying to achieve exactly? > > > > I would like to implement a class (vector) to works with vectors, for > example using scalar multiplication: > a*v = [a*v1, a*vn] > and a dual class for dual vector (the only method that I'll change is the > __str__ method to print it as colun. Have you looked at NumPy? I haven't used it myself, but I understand it's good for this sort of thing. ChrisA From cjw at ncf.ca Sun Mar 3 09:21:21 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 03 Mar 2013 09:21:21 -0500 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> Message-ID: On 02/03/2013 9:30 PM, gialloporpora wrote: > Risposta al messaggio di Rick Johnson : > >> What are you trying to achieve exactly? > > > I would like to implement a class (vector) to works with vectors, for > example using scalar multiplication: > a*v = [a*v1, a*vn] > and a dual class for dual vector (the only method that I'll change is > the __str__ method to print it as colun. > Sandro Numpy facilitates this sort of thing more efficiently than using a List. Colin W. From jason.swails at gmail.com Sun Mar 3 15:40:48 2013 From: jason.swails at gmail.com (Jason Swails) Date: Sun, 3 Mar 2013 15:40:48 -0500 Subject: Is it correct this way to inherit from a list? In-Reply-To: References: <1409c13b-60a6-4e87-a58c-52d5740e74d5@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 9:21 AM, Colin J. Williams wrote: > On 02/03/2013 9:30 PM, gialloporpora wrote: > >> Risposta al messaggio di Rick Johnson : >> >> What are you trying to achieve exactly? >>> >> >> >> I would like to implement a class (vector) to works with vectors, for >> example using scalar multiplication: >> a*v = [a*v1, a*vn] >> and a dual class for dual vector (the only method that I'll change is >> the __str__ method to print it as colun. >> Sandro >> > Numpy facilitates this sort of thing more efficiently than using a List. > As a couple people have already pointed out, numpy is the way to go for most scientific applications. You have also been given good advice regarding 'properly' inheriting from 'list' by calling the list.__init__ function. The only thing I'll add here is that you can inherit from array.array instead of list if you want a 'truly' numeric-vector without introducing numpy as a dependency. The advantage array.array has over list in this instance is that it is type-restrictive for member data (it has to be pre-declared and throws TypeError if you try to pass it a bad variable type). You can then proceed to override the __add__, __sub__, __mul__, and __div__ methods (and the in-place versions of these operators) to mimic vector operations. (By default, __add__ appends the rhs to the lhs and returns a copy of that for array.array and list). You can avoid all this work, however, and just use numpy.ndarray instead ;). Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From mamboknave at gmail.com Sat Mar 2 12:18:59 2013 From: mamboknave at gmail.com (mamboknave at gmail.com) Date: Sat, 2 Mar 2013 09:18:59 -0800 (PST) Subject: Sorting (deeply) nested lists Message-ID: I cannot resolve this on my own. Need help, please... nestedTuples = [ [ (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, L0t2e1, L0t2e2) ], [ (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, L1t2e2) ], [ (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, L2t2e1, L2t2e2) ] ] With LNtXeY I mean the element Y in the tuple X of the list N. How can I sort nestedTuples by, say, the 2nd element in the 2nd tuple of each list? The above should get sorted as : nestedTuples = [ [ (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, L1t2e2) ], [ (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, L2t2e1, L2t2e2) ], [ (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, L0t2e1, L0t2e2) ] ] Thanks so much!! From __peter__ at web.de Sat Mar 2 12:36:43 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Mar 2013 18:36:43 +0100 Subject: Sorting (deeply) nested lists References: Message-ID: mamboknave at gmail.com wrote: > I cannot resolve this on my own. Need help, please... > > nestedTuples = [ > [ (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, L0t2e1, L0t2e2) > [ ], (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, > [ L1t2e2) ], (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, > [ L2t2e1, L2t2e2) ] ] > > With LNtXeY I mean the element Y in the tuple X of the list N. > > How can I sort nestedTuples by, say, the 2nd element in the 2nd tuple of > each list? def getkey(item): return item[1][1] namedTuples.sort(key=getkey) You can also write this as namedTuples.sort(key=lambda item: item[1][1]) > The above should get sorted as : > > nestedTuples = [ > [ (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, L1t2e2) > [ ], (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, L2t2e1, > [ L2t2e2) ], (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, > [ L0t2e1, L0t2e2) ] ] From mamboknave at gmail.com Sat Mar 2 12:49:00 2013 From: mamboknave at gmail.com (mamboknave at gmail.com) Date: Sat, 2 Mar 2013 09:49:00 -0800 (PST) Subject: Sorting (deeply) nested lists In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 9:36:43 AM UTC-8, Peter Otten wrote: > > You can also write this as > > namedTuples.sort(key=lambda item: item[1][1]) > That's exactly what I did before and got "IndexError: list index out of range". So, I thought my lambda was wrong and posted here. Now, having seen you reply, I dug deeper and... of course I had IndexError: the list was horribly empty! Thanks so much for replying so quickly, Peter! From mamboknave at gmail.com Sat Mar 2 12:49:00 2013 From: mamboknave at gmail.com (mamboknave at gmail.com) Date: Sat, 2 Mar 2013 09:49:00 -0800 (PST) Subject: Sorting (deeply) nested lists In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 9:36:43 AM UTC-8, Peter Otten wrote: > > You can also write this as > > namedTuples.sort(key=lambda item: item[1][1]) > That's exactly what I did before and got "IndexError: list index out of range". So, I thought my lambda was wrong and posted here. Now, having seen you reply, I dug deeper and... of course I had IndexError: the list was horribly empty! Thanks so much for replying so quickly, Peter! From bob at mellowood.ca Sat Mar 2 12:40:11 2013 From: bob at mellowood.ca (bvdp) Date: Sat, 2 Mar 2013 09:40:11 -0800 (PST) Subject: Dealing with exceptions Message-ID: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: try: shutil.copy(s, os.path.join(usbpath, songname)) except ... now, I need to figure out just what exceptions to handle. Let's see: IOError that means that the disk is full or otherwise buggered. Better dump out of the loop. But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't figure it out. In this case, I can run the program an number of times and parse out the errors and write code to catch various things. But, I think I'm missing something completely. Guess what I'm looking for is a list of possible (probable?) errors for the shutil.copy() command. And, in a much bigger manual, for most other commands. Maybe I'm just venting about FAT32 filesystems :) From kwpolska at gmail.com Sat Mar 2 12:52:19 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sat, 2 Mar 2013 18:52:19 +0100 Subject: Dealing with exceptions In-Reply-To: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 6:40 PM, bvdp wrote: > Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. > > For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: > > try: > shutil.copy(s, os.path.join(usbpath, songname)) > except ... > > now, I need to figure out just what exceptions to handle. Let's see: > > IOError that means that the disk is full or otherwise buggered. Better dump out of the loop. > > But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't figure it out. > > In this case, I can run the program an number of times and parse out the errors and write code to catch various things. But, I think I'm missing something completely. Guess what I'm looking for is a list of possible (probable?) errors for the shutil.copy() command. And, in a much bigger manual, for most other commands. > > Maybe I'm just venting about FAT32 filesystems :) > > -- > http://mail.python.org/mailman/listinfo/python-list IOError and OSError should cover all copy problems, I think. Also, you can do `except:` for a catch-all, but it is discouraged unless you have REALLY good reasons to do this. And, most of the time, you don?t. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From ian.g.kelly at gmail.com Sat Mar 2 13:00:27 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Mar 2013 11:00:27 -0700 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 10:52 AM, Kwpolska wrote: > IOError and OSError should cover all copy problems, I think. And it may be worth pointing out here that as of Python 3.3, IOError is just a synonym for OSError. From ian.g.kelly at gmail.com Sat Mar 2 12:58:12 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Mar 2013 10:58:12 -0700 Subject: Dealing with exceptions In-Reply-To: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 10:40 AM, bvdp wrote: > Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. > > For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: > > try: > shutil.copy(s, os.path.join(usbpath, songname)) > except ... > > now, I need to figure out just what exceptions to handle. Let's see: > > IOError that means that the disk is full or otherwise buggered. Better dump out of the loop. > > But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't figure it out. OSError. In Python 3, I expect it would more specifically be a FileNotFoundError, which is a subclass of OSError. > In this case, I can run the program an number of times and parse out the errors and write code to catch various things. But, I think I'm missing something completely. Guess what I'm looking for is a list of possible (probable?) errors for the shutil.copy() command. And, in a much bigger manual, for most other commands. OSError will cover a wide swath of possible exceptions here. From breamoreboy at yahoo.co.uk Sat Mar 2 14:18:16 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Mar 2013 19:18:16 +0000 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On 02/03/2013 17:58, Ian Kelly wrote: > On Sat, Mar 2, 2013 at 10:40 AM, bvdp wrote: >> Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. >> >> For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: >> >> try: >> shutil.copy(s, os.path.join(usbpath, songname)) >> except ... >> >> now, I need to figure out just what exceptions to handle. Let's see: >> >> IOError that means that the disk is full or otherwise buggered. Better dump out of the loop. >> >> But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't figure it out. > > OSError. In Python 3, I expect it would more specifically be a > FileNotFoundError, which is a subclass of OSError. This wasn't introduced until Python 3.3 see http://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy > >> In this case, I can run the program an number of times and parse out the errors and write code to catch various things. But, I think I'm missing something completely. Guess what I'm looking for is a list of possible (probable?) errors for the shutil.copy() command. And, in a much bigger manual, for most other commands. > > OSError will cover a wide swath of possible exceptions here. > -- Cheers. Mark Lawrence From rosuav at gmail.com Sat Mar 2 13:21:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 05:21:09 +1100 Subject: Dealing with exceptions In-Reply-To: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 4:40 AM, bvdp wrote: > For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: > > try: > shutil.copy(s, os.path.join(usbpath, songname)) > except ... > > now, I need to figure out just what exceptions to handle. Here's a bit of a left-field thought: Maybe none of them. What are you actually doing when you get an exception? Can you plausibly recover? If not - that is, if you're going to abort the whole operation anyway - then save yourself the trouble of writing the try/catch, and just let the exception propagate up (to the console, if nowhere else). On the other hand, if you want to simply report the error and continue on (meaning you get as many songs copied as possible), then do what others have recommended and catch OSError. ChrisA From jeanpierreda at gmail.com Sat Mar 2 14:27:37 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 2 Mar 2013 14:27:37 -0500 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sat, Mar 2, 2013 at 1:21 PM, Chris Angelico wrote: >> now, I need to figure out just what exceptions to handle. > > Here's a bit of a left-field thought: Maybe none of them. > > What are you actually doing when you get an exception? Can you > plausibly recover? If not - that is, if you're going to abort the > whole operation anyway - then save yourself the trouble of writing the > try/catch, and just let the exception propagate up (to the console, if > nowhere else). He can't know if he should handle the errors if he doesn't know what those errors are. Thus the question. -- Devin From bob at mellowood.ca Sat Mar 2 14:35:13 2013 From: bob at mellowood.ca (bvdp) Date: Sat, 2 Mar 2013 11:35:13 -0800 (PST) Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: > > IOError and OSError should cover all copy problems, I think. How do you know that? I can figure it out as well by running the program, but I'd like to make the determination of what to catch when I'm writing the code. From bob at mellowood.ca Sat Mar 2 14:35:13 2013 From: bob at mellowood.ca (bvdp) Date: Sat, 2 Mar 2013 11:35:13 -0800 (PST) Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: > > IOError and OSError should cover all copy problems, I think. How do you know that? I can figure it out as well by running the program, but I'd like to make the determination of what to catch when I'm writing the code. From steve+comp.lang.python at pearwood.info Sat Mar 2 20:41:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 01:41:20 GMT Subject: Dealing with exceptions References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: <5132aa40$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 11:35:13 -0800, bvdp wrote: >> IOError and OSError should cover all copy problems, I think. > > How do you know that? I can figure it out as well by running the > program, but I'd like to make the determination of what to catch when > I'm writing the code. In my experience, I would say: 20% by reading the documentation, 20% by experience, and 60% by experimentation at the interactive interpreter. Generally if you read the docs, you will get some idea of the exceptions you can expect to get. E.g. the docs for open claim: "Raise IOError upon failure." (call "help(open)" in the interactive interpreter). Experience and experimentation come into it in the (unfortunately very common case) where the docs don't describe the exceptions you can expect. For the specific case of IOError and OSError, another very useful skill is googling for the specific errno you can test for: try: something() except IOError as e: if e.errno == whatever: do_this() else: raise In Python 3.3, this becomes much nicer with individual exceptions for the most common errnos. -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 2 19:41:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2013 00:41:09 GMT Subject: Dealing with exceptions References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: <51329c25$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 02 Mar 2013 18:52:19 +0100, Kwpolska wrote: > Also, you can do `except:` for a catch-all, but it is discouraged unless > you have REALLY good reasons to do this. And, most of the time, you > don?t. `except Exception` is to be much preferred over a bare except. It excludes KeyboardInterruptError (the user hits Ctrl-C) and SystemExit, which you normally either want to let through, or handle separately. But yes, in general, only catch the minimum you *know* you need to catch and can deal with. Anything else is a bug in your code that needs to be fixed, and you can't fix it if you never see the exception. -- Steven From rosuav at gmail.com Sat Mar 2 20:04:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 12:04:02 +1100 Subject: Dealing with exceptions In-Reply-To: <51329c25$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> <51329c25$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 3, 2013 at 11:41 AM, Steven D'Aprano wrote: > But yes, in general, only catch the minimum you *know* you need to catch > and can deal with. Anything else is a bug in your code that needs to be > fixed, and you can't fix it if you never see the exception. With the exception (if you'll excuse the expression) of "framework" systems, where there's a distinct separation between "inside" and "outside". Often then, the "outside" will catch any exception thrown by the "inside" and deal with it in some generic way (for instance, a web server might log the details and return HTTP 500 to the client, then go back and handle the next request). Effectively, this is doing the job of the top-level exception handler: log the exception (to the console) and terminate. ChrisA From nobody at nowhere.com Sun Mar 3 18:01:48 2013 From: nobody at nowhere.com (Nobody) Date: Sun, 03 Mar 2013 23:01:48 +0000 Subject: Dealing with exceptions References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sat, 02 Mar 2013 18:52:19 +0100, Kwpolska wrote: > Also, you can do `except:` for a catch-all, but it is discouraged unless > you have REALLY good reasons to do this. And, most of the time, you > don?t. Most of the time you probably want to catch either Exception (which excludes GeneratorExit, KeyboardInterrupt and SystemExit) or StandardError (which excludes the above pluse warnings and StopIteration). Only in specific circumstances can you reasonably go finer than that, partly due to the set of exceptions a method may throw seldom being documented, and partly due to duck typing; a parameter which is intended to be a file object could realistically be any object which supports the appropriate methods (e.g. .read()), and there's no guarantee that those methods will have the same set of possible exceptions as a real file object. From bob at mellowood.ca Sat Mar 2 14:39:34 2013 From: bob at mellowood.ca (bvdp) Date: Sat, 2 Mar 2013 11:39:34 -0800 (PST) Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: > > Here's a bit of a left-field thought: Maybe none of them. > Not far left at all :) > > What are you actually doing when you get an exception? Can you > > plausibly recover? If not - that is, if you're going to abort the > > whole operation anyway - then save yourself the trouble of writing the > > try/catch, and just let the exception propagate up (to the console, if > > nowhere else). > My first cut of the program did exactly that. Just abort the whole thing, figuring that the disk was full or buggered. What I ran into was that half way through the process I ended up with a filename which the FAT32 didn't like. So, my brain-dead idea was to catch those (and ignore them) and continue on. But then I have to distinguish between a bad filename and "real" errors. But, you are probably correct if you say I should check the filename first :) Is there a module for that? From bob at mellowood.ca Sat Mar 2 14:39:34 2013 From: bob at mellowood.ca (bvdp) Date: Sat, 2 Mar 2013 11:39:34 -0800 (PST) Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: > > Here's a bit of a left-field thought: Maybe none of them. > Not far left at all :) > > What are you actually doing when you get an exception? Can you > > plausibly recover? If not - that is, if you're going to abort the > > whole operation anyway - then save yourself the trouble of writing the > > try/catch, and just let the exception propagate up (to the console, if > > nowhere else). > My first cut of the program did exactly that. Just abort the whole thing, figuring that the disk was full or buggered. What I ran into was that half way through the process I ended up with a filename which the FAT32 didn't like. So, my brain-dead idea was to catch those (and ignore them) and continue on. But then I have to distinguish between a bad filename and "real" errors. But, you are probably correct if you say I should check the filename first :) Is there a module for that? From rantingrickjohnson at gmail.com Sat Mar 2 14:43:05 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 2 Mar 2013 11:43:05 -0800 (PST) Subject: Dealing with exceptions In-Reply-To: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: <7001fdcc-21b8-478c-a073-2466386dfe49@googlegroups.com> On Saturday, March 2, 2013 11:40:11 AM UTC-6, bvdp wrote: > Every time I write a program with exception handling (and > I suppose that includes just about every program I write!) > I need to scratch my brain when I create try blocks. > > For example, I'm writing a little program do copy specific > files to a USB stick. To do the actual copy I'm using: > > try: > shutil.copy(s, os.path.join(usbpath, songname)) > except ... > > now, I need to figure out just what exceptions to handle. > Let's see: > > IOError that means that the disk is full or otherwise > buggered. Better dump out of the loop. > > But, I know there can be other errors as well. Doing some > tests, I know that certain filenames are invalid (I think > a "?" or unicode char is invalid when writing to a FAT32 > filesystem). And, so what exception is that? Without > actually creating the error, I can't figure it out. Well how can you expect an error to be thrown without creating the scenario that will throw one? *wink* > In this case, I can run the program an number of times and > parse out the errors and write code to catch various > things. But, I think I'm missing something completely. > Guess what I'm looking for is a list of possible > (probable?) errors for the shutil.copy() command. And, in > a much bigger manual, for most other commands. No. What you are doing is *misunderstanding* that well written methods must follow the values of: "doing one thing and doing it well" In the case of "shutil.copy", that "one thing" is "coping files"; but that "one thing" does NOT include: * resolving file paths * validating file path chars on an OS by OS basis * ensuring disc space is adequate * etc... Methods that take inputs, like in this case: "src" and "dst" file paths, should not be responsible for the validity of the inputs. It is the responsibility of the caller to validate these inputs PRIOR to injecting them into the method. But even *IF* a convincing argument could be made for methods to validate inputs, then at what point do we draw the line? How many foolish samples of the possible permutation set should we consider? Should we inform the user of such foolish usage as: shutil.copy(src=1, dst=2, follow_symlinks=isinstance) shutil.copy(src='cat', dst='hat', follow_symlinks=list) Now whilst these example are quite absurd, they are in-fact possibilities that must be considered *IF* we intend to follow your "wish" until it's logical conclusion. From tjreedy at udel.edu Sat Mar 2 16:23:37 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Mar 2013 16:23:37 -0500 Subject: Dealing with exceptions In-Reply-To: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On 3/2/2013 12:40 PM, bvdp wrote: > But, I know there can be other errors as well. Doing some tests, I > know that certain filenames are invalid (I think a "?" or unicode > char is invalid when writing to a FAT32 filesystem). And, so what > exception is that? Without actually creating the error, I can't > figure it out. So use the interactive interpreter (or idle, or ipython) and create the error. You should always have it open when editing. Using less time that it took you to write the above. 3.3, win7, (idle) >>> open('sdjhfjshdfkjsh') Traceback (most recent call last): File "", line 1, in open('sdjhfjshdfkjsh') FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' Now, does shutil pass on FileNotFoundError? I will let you experiment. There are error conditions that are hard to generate, but a bad file name is not one of them. -- Terry Jan Reedy From rosuav at gmail.com Sat Mar 2 17:16:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 09:16:51 +1100 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: >>>> open('sdjhfjshdfkjsh') > Traceback (most recent call last): > File "", line 1, in > open('sdjhfjshdfkjsh') > FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' > > Now, does shutil pass on FileNotFoundError? I will let you experiment. > > There are error conditions that are hard to generate, but a bad file name is > not one of them. That's actually a perfectly valid file name, but one that doesn't happen to have a corresponding file. However, the same technique will work with the OP's description of "a filename which the FAT32 didn't like" too. ChrisA From tjreedy at udel.edu Sat Mar 2 18:08:48 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Mar 2013 18:08:48 -0500 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On 3/2/2013 5:16 PM, Chris Angelico wrote: > On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: >>>>> open('sdjhfjshdfkjsh') >> Traceback (most recent call last): >> File "", line 1, in >> open('sdjhfjshdfkjsh') >> FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' >> >> Now, does shutil pass on FileNotFoundError? I will let you experiment. >> >> There are error conditions that are hard to generate, but a bad file name is >> not one of them. > > That's actually a perfectly valid file name, but one that doesn't > happen to have a corresponding file. However, the same technique will > work with the OP's description of "a filename which the FAT32 didn't > like" too. Yeah, that gives a different error and message. >>> open('a~`!@#$%^&*()_-+={[}]|\<,>.?/') Traceback (most recent call last): File "", line 1, in open('a~`!@#$%^&*()_-+={[}]|\<,>.?/') OSError: [Errno 22] Invalid argument: 'a~`!@#$%^&*()_-+={[}]|\\<,>.?/' -- Terry Jan Reedy From rosuav at gmail.com Sat Mar 2 18:17:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 10:17:55 +1100 Subject: Dealing with exceptions In-Reply-To: References: <707df78f-9a67-4ce1-8dd3-095c75a7f7da@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 10:08 AM, Terry Reedy wrote: > On 3/2/2013 5:16 PM, Chris Angelico wrote: >> >> On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: >>>>>> >>>>>> open('sdjhfjshdfkjsh') >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> open('sdjhfjshdfkjsh') >>> FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' >>> >>> Now, does shutil pass on FileNotFoundError? I will let you experiment. >>> >>> There are error conditions that are hard to generate, but a bad file name >>> is >>> not one of them. >> >> >> That's actually a perfectly valid file name, but one that doesn't >> happen to have a corresponding file. However, the same technique will >> work with the OP's description of "a filename which the FAT32 didn't >> like" too. > > > Yeah, that gives a different error and message. >>>> open('a~`!@#$%^&*()_-+={[}]|\<,>.?/') > > Traceback (most recent call last): > File "", line 1, in > open('a~`!@#$%^&*()_-+={[}]|\<,>.?/') > OSError: [Errno 22] Invalid argument: 'a~`!@#$%^&*()_-+={[}]|\\<,>.?/' That should be: OSError: Profanity not permitted on respectable file systems ChrisA From hossamalagmy at gmail.com Sat Mar 2 13:18:20 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sat, 2 Mar 2013 10:18:20 -0800 (PST) Subject: =?windows-1256?B?1ebRIHdoaXRlIExHIG5leHVzIDQgZWd5cHQg5O3f09MgNCDH4cPI?= =?windows-1256?B?7dY=?= Message-ID: <48cd6e0a-94be-471b-aa4b-e007514d43fe@h9g2000vbk.googlegroups.com> ??? white LG nexus 4 egypt ????? 4 ?????? http://natigtas7ab.blogspot.com/2013/02/white-lg-nexus-4-egypt-4.html From enidoku at gmail.com Sat Mar 2 16:47:38 2013 From: enidoku at gmail.com (enidoku at gmail.com) Date: Sat, 2 Mar 2013 13:47:38 -0800 (PST) Subject: Tk MouseWheel Support In-Reply-To: <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> References: <5scin656p88uun6pug6ri4084t6796mjbk@4ax.com> <4D793619.9000905@aim.com> <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> Message-ID: that code and other mousewheel code arent working on my pc running windows 7 32bit python 2.6 and Mouse USB whats the solution ? From breamoreboy at yahoo.co.uk Sat Mar 2 18:01:53 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 02 Mar 2013 23:01:53 +0000 Subject: Tk MouseWheel Support In-Reply-To: References: <5scin656p88uun6pug6ri4084t6796mjbk@4ax.com> <4D793619.9000905@aim.com> <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> Message-ID: On 02/03/2013 21:47, enidoku at gmail.com wrote: > that code and other mousewheel code arent working on my pc > > running windows 7 32bit python 2.6 and Mouse USB > > whats the solution ? > Post something that we can read, or do I give up on Thunderbird? :) -- Cheers. Mark Lawrence From rosuav at gmail.com Sat Mar 2 18:08:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2013 10:08:50 +1100 Subject: Tk MouseWheel Support In-Reply-To: References: <5scin656p88uun6pug6ri4084t6796mjbk@4ax.com> <4D793619.9000905@aim.com> <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 10:01 AM, Mark Lawrence wrote: > On 02/03/2013 21:47, enidoku at gmail.com wrote: >> >> that code and other mousewheel code arent working on my pc >> >> running windows 7 32bit python 2.6 and Mouse USB >> >> whats the solution ? >> > > Post something that we can read, or do I give up on Thunderbird? :) I don't think Thunderbird's at fault here, unless it damaged the original post itself. Is that a known bug? "Reading posts in Thunderbird while the moon is in its first quarter and pigs are flying overhead causes the OP to lose 40 points of apparent IQ"? ChrisA From davea at davea.name Sat Mar 2 18:13:21 2013 From: davea at davea.name (Dave Angel) Date: Sat, 02 Mar 2013 18:13:21 -0500 Subject: Tk MouseWheel Support In-Reply-To: References: <5scin656p88uun6pug6ri4084t6796mjbk@4ax.com> <4D793619.9000905@aim.com> <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> Message-ID: <51328791.8070106@davea.name> On 03/02/2013 06:01 PM, Mark Lawrence wrote: > On 02/03/2013 21:47, enidoku at gmail.com wrote: >> that code and other mousewheel code arent working on my pc >> >> running windows 7 32bit python 2.6 and Mouse USB >> >> whats the solution ? >> > > Post something that we can read, or do I give up on Thunderbird? :) > That enidoku person was replying to a two-year old thread. If you want to see the thread, check out: http://www.velocityreviews.com/forums/t744913-tk-mousewheel-support.html -- DaveA From tjreedy at udel.edu Sat Mar 2 18:14:31 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Mar 2013 18:14:31 -0500 Subject: Tk MouseWheel Support In-Reply-To: References: <5scin656p88uun6pug6ri4084t6796mjbk@4ax.com> <4D793619.9000905@aim.com> <81332d16-1309-4146-bf0f-7a8a6e4b9220@17g2000prr.googlegroups.com> Message-ID: On 3/2/2013 6:01 PM, Mark Lawrence wrote: > On 02/03/2013 21:47, enidoku at gmail.com wrote: >> that code and other mousewheel code arent working on my pc >> running windows 7 32bit python 2.6 and Mouse USB >> whats the solution ? > Post something that we can read, or do I give up on Thunderbird? :) In tbird, temporarily switching from view/threads/unread to view/threads/all will expose older posts retained on your system, but enidoku appears to be replying to a post more than 180 days old (my retention period for this group). So more info is needed. -- Terry Jan Reedy From juancarlo.anez at gmail.com Sat Mar 2 20:35:23 2013 From: juancarlo.anez at gmail.com (juancarlo.anez at gmail.com) Date: Sat, 2 Mar 2013 17:35:23 -0800 (PST) Subject: RLock IO bound? Message-ID: <43fc67b0-5846-4aad-8563-dbb3fad2caaa@googlegroups.com> Hello, I have a set of processes that bring any number of cores to 100% use when unsynchronized (they take independent jobs from a queue). As soon as I add an RLock to handle shared access to a file-system directory, the CPU utilization drops to 60%. I'm not talking about overall speed here, but about processes that were CPU bound and suddenly become bound to something else with RLock. Any explanations? Cheers, -- Juancarlo From cs at zip.com.au Sun Mar 3 01:27:56 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 3 Mar 2013 17:27:56 +1100 Subject: RLock IO bound? In-Reply-To: <43fc67b0-5846-4aad-8563-dbb3fad2caaa@googlegroups.com> References: <43fc67b0-5846-4aad-8563-dbb3fad2caaa@googlegroups.com> Message-ID: <20130303062756.GA7313@cskk.homeip.net> On 02Mar2013 17:35, juancarlo.anez at gmail.com wrote: | I have a set of processes that bring any number of cores to 100% | use when unsynchronized (they take independent jobs from a queue). | | As soon as I add an RLock to handle shared access to a file-system | directory, the CPU utilization drops to 60%. | | I'm not talking about overall speed here, but about processes | that were CPU bound and suddenly become bound to something else | with RLock. Shrug. If your threads do some I/O and now block where they would have overlapped then suddenly your threads can't do compute all the time. Ergo, less CPU utilisation. Without more detail nobody can say where your particular bottleneck lies, but I would be very very surprised if the RLock was the bottleneck; what you're doing _inside_ the RLock is the bottleneck. -- Cameron Simpson My computer always does exactly what I tell it to do but sometimes I have trouble finding out what it was that I told it to do. - Dick Wexelblat From agardner210 at gmail.com Sat Mar 2 20:56:31 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sat, 2 Mar 2013 17:56:31 -0800 (PST) Subject: Pygame mouse cursor load/unload Message-ID: I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: Main class: http://pastebin.com/HSQzX6h2 Main file (where the problem lies): http://pastebin.com/67p97RsJ If the links yield nothing, please let me know (agardner210 at gmail.com) From ian.g.kelly at gmail.com Sat Mar 2 22:08:18 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Mar 2013 20:08:18 -0700 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Sat, Mar 2, 2013 at 6:56 PM, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: Your mouse motion code draws the paddle in the new position, waits 1/10th of a second, and then draws over it again with the "invisible" paddle. Thus, approximately 1/10th of a second after you stop moving the mouse, it disappears. Mouse motion events are probably not the best way to do this. You can instead just capture the current position of the mouse on every frame and use that instead. I replaced your main loop with the following: paddle_pos = (0, 0) clock = pygame.time.Clock() while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() # Erase the paddle from the old mouse position. screen.blit(bpaddle, paddle_pos) # Redraw the net before the paddle so that the paddle can appear over it. pygame.draw.line(screen, game.lineColor, game.net1, game.net2, game.netWidth) # Get the new mouse position. paddle_pos = pygame.mouse.get_pos() # Draw the paddle at the new mouse position. screen.blit(beeper, paddle_pos) # Update the screen if it's double-buffered. pygame.display.update() # Finally, let the CPU idle until it's time for the next frame. # 50 here means that it will sleep long enough to achieve 50 FPS. clock.tick(50) And I think you will find that this does what you want. A couple more observations while I'm at it. Generally there is no need to be calling pygame.display.update() multiple times per frame. Just draw everything that you need, and then call it once at the end of the loop, as I have shown above. Also, the shebang line only does anything if it's the very first line in the file, so it would need to appear before the module docstring to do anything useful. From agardner210 at gmail.com Sat Mar 2 22:52:00 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sat, 2 Mar 2013 19:52:00 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <4010f9c7-7a1a-4168-ac32-841d7d8ba486@googlegroups.com> On Saturday, March 2, 2013 9:08:18 PM UTC-6, Ian wrote: > On Sat, Mar 2, 2013 at 6:56 PM, Alex Gardner wrote: > > > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Your mouse motion code draws the paddle in the new position, waits > > 1/10th of a second, and then draws over it again with the "invisible" > > paddle. Thus, approximately 1/10th of a second after you stop moving > > the mouse, it disappears. > > > > Mouse motion events are probably not the best way to do this. You can > > instead just capture the current position of the mouse on every frame > > and use that instead. I replaced your main loop with the following: > > > > paddle_pos = (0, 0) > > clock = pygame.time.Clock() > > > > while True: > > for event in pygame.event.get(): > > if event.type == QUIT: > > sys.exit() > > > > # Erase the paddle from the old mouse position. > > screen.blit(bpaddle, paddle_pos) > > # Redraw the net before the paddle so that the paddle can appear over it. > > pygame.draw.line(screen, game.lineColor, game.net1, game.net2, > > game.netWidth) > > # Get the new mouse position. > > paddle_pos = pygame.mouse.get_pos() > > # Draw the paddle at the new mouse position. > > screen.blit(beeper, paddle_pos) > > # Update the screen if it's double-buffered. > > pygame.display.update() > > # Finally, let the CPU idle until it's time for the next frame. > > # 50 here means that it will sleep long enough to achieve 50 FPS. > > clock.tick(50) > > > > And I think you will find that this does what you want. > > > > A couple more observations while I'm at it. Generally there is no > > need to be calling pygame.display.update() multiple times per frame. > > Just draw everything that you need, and then call it once at the end > > of the loop, as I have shown above. Also, the shebang line only does > > anything if it's the very first line in the file, so it would need to > > appear before the module docstring to do anything useful. Thank you very much, Ian. I understand the code and have learned from it. If I were more knowledgeable in python I wouldn't have had to ask; I am learning as I go with this project. Again, thank you :) From agardner210 at gmail.com Sat Mar 2 22:52:00 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sat, 2 Mar 2013 19:52:00 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <4010f9c7-7a1a-4168-ac32-841d7d8ba486@googlegroups.com> On Saturday, March 2, 2013 9:08:18 PM UTC-6, Ian wrote: > On Sat, Mar 2, 2013 at 6:56 PM, Alex Gardner wrote: > > > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Your mouse motion code draws the paddle in the new position, waits > > 1/10th of a second, and then draws over it again with the "invisible" > > paddle. Thus, approximately 1/10th of a second after you stop moving > > the mouse, it disappears. > > > > Mouse motion events are probably not the best way to do this. You can > > instead just capture the current position of the mouse on every frame > > and use that instead. I replaced your main loop with the following: > > > > paddle_pos = (0, 0) > > clock = pygame.time.Clock() > > > > while True: > > for event in pygame.event.get(): > > if event.type == QUIT: > > sys.exit() > > > > # Erase the paddle from the old mouse position. > > screen.blit(bpaddle, paddle_pos) > > # Redraw the net before the paddle so that the paddle can appear over it. > > pygame.draw.line(screen, game.lineColor, game.net1, game.net2, > > game.netWidth) > > # Get the new mouse position. > > paddle_pos = pygame.mouse.get_pos() > > # Draw the paddle at the new mouse position. > > screen.blit(beeper, paddle_pos) > > # Update the screen if it's double-buffered. > > pygame.display.update() > > # Finally, let the CPU idle until it's time for the next frame. > > # 50 here means that it will sleep long enough to achieve 50 FPS. > > clock.tick(50) > > > > And I think you will find that this does what you want. > > > > A couple more observations while I'm at it. Generally there is no > > need to be calling pygame.display.update() multiple times per frame. > > Just draw everything that you need, and then call it once at the end > > of the loop, as I have shown above. Also, the shebang line only does > > anything if it's the very first line in the file, so it would need to > > appear before the module docstring to do anything useful. Thank you very much, Ian. I understand the code and have learned from it. If I were more knowledgeable in python I wouldn't have had to ask; I am learning as I go with this project. Again, thank you :) From agardner210 at gmail.com Sun Mar 3 17:04:07 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sun, 3 Mar 2013 14:04:07 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <4294807e-4798-4eb1-873d-7ea169c08fc7@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) I have a new problem :(. I want to restrict the paddle to a certain plane. I have it working but when the paddle reaches the limit it locks up. I have no idea how I can redraw it back in the plane. I am using the code that Ian provided (thank you so much). I was thinking of making an else to redraw the paddle using the same code, but part of me thinks that it would be rather sloppy. if (0,0) <= paddle_pos <= (300,300): paddle_pos = pygame.mouse.get_pos() screen.blit(beeper, paddle_pos) pygame.display.update() clock.tick(50) From agardner210 at gmail.com Sun Mar 3 17:09:52 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sun, 3 Mar 2013 14:09:52 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <9c352284-08c4-439e-b324-caffa3718429@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) I have a new problem that I'm dealing with. I want to restrict the paddle to a certain plane. When the paddle reaches the boundary, it locks up. I am using the code that Ian provided earlier (thank you so much). Here is what I have so far: if (0,0) <= paddle_pos <= (300,300): paddle_pos = pygame.mouse.get_pos() screen.blit(beeper, paddle_pos) pygame.display.update() clock.tick(50) I tried making an else statement and copying Ian's code in it, but I don't think that it would work. I have tried to fix this myself; this is my second GUI program that I have ever made.... please forgive me if I seem needy. From ian.g.kelly at gmail.com Sun Mar 3 18:47:08 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Mar 2013 16:47:08 -0700 Subject: Pygame mouse cursor load/unload In-Reply-To: <9c352284-08c4-439e-b324-caffa3718429@googlegroups.com> References: <9c352284-08c4-439e-b324-caffa3718429@googlegroups.com> Message-ID: On Sun, Mar 3, 2013 at 3:09 PM, Alex Gardner wrote: > if (0,0) <= paddle_pos <= (300,300): This doesn't do what you think it does. Tuples are compared lexicographically, not element-wise. So (250, 350) < (300, 300), but (350, 250) > (300, 300). > paddle_pos = pygame.mouse.get_pos() > screen.blit(beeper, paddle_pos) > pygame.display.update() > clock.tick(50) You're updating paddle_pos inside the if block. Once paddle_pos falls outside that range, the if block won't trigger, and paddle_pos will no longer be updated, so it will never fall inside that range again. pygame has a Rect class for rectangle logic that can solve both of these problems for you. Given: paddle_rect = beeper.get_rect() bounds_rect = pygame.Rect(0, 0, 300, 300) your position update code then becomes: paddle_rect.center = pygame.mouse.get_pos() paddle_rect.clamp_ip(bounds_rect) Note that paddle_rect can replace paddle_pos entirely. The code: screen.blit(beeper, paddle_pos) simply becomes: screen.blit(beeper, paddle_rect) From agardner210 at gmail.com Sat Mar 9 19:20:50 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sat, 9 Mar 2013 16:20:50 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <45fee47a-1e4d-4a38-b368-3e95d128d854@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > . > If the links yield nothing, please let me know (agardner210 at gmail.com) I followed your advice, but now I have a drawing problem. I simply tried rewriting the paddle with a black one, but its failing. I would like to pester you fine folks one last time. The code is here: http://pastebin.com/gVPPJYWs I really appreciate your help and am learning from your advice. Thank you so much, Alex From agardner210 at gmail.com Sat Mar 9 19:25:30 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sat, 9 Mar 2013 16:25:30 -0800 (PST) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) I would like to bother you fine folks one last time! There are drawing problems that I am running into. The paddle keeps on moving but it doesn't rewrite the black paddle. This is a problem because the paddle just keeps leaving a green trail. The code is here: http://pastebin.com/gVPPJYWs I feel as though I am missing something... From ian.g.kelly at gmail.com Sun Mar 10 15:23:29 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Mar 2013 13:23:29 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Sat, Mar 9, 2013 at 5:25 PM, Alex Gardner wrote: > On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: >> I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: >> >> >> >> Main class: http://pastebin.com/HSQzX6h2 >> >> Main file (where the problem lies): http://pastebin.com/67p97RsJ >> >> >> >> If the links yield nothing, please let me know (agardner210 at gmail.com) > > I would like to bother you fine folks one last time! There are drawing problems that I am running into. The paddle keeps on moving but it doesn't rewrite the black paddle. This is a problem because the paddle just keeps leaving a green trail. The code is here: http://pastebin.com/gVPPJYWs > > I feel as though I am missing something... You get the streaking because the first blanking operation only ever blanks at (0, 0), and the second one blanks at the new paddle position, not the previous position. You don't need two separate rects to keep track of where the paddle is. blank_rect and b_bounds_rect are entirely unnecessary, so get rid of them. The line "screen.blit(bpaddle, paddle_pos)" should be replaced with "screen.blit(bpaddle, paddle_rect)", because paddle_rect is what you're using to track the paddle location. Since paddle_pos is not being updated, the former would always draw the blank paddle in the upper-left corner. This should also be the only place where you're blanking the paddle, so get rid of the other one. You also don't need the if statement at all. The clamping operation already ensures that the paddle is bounded to the region (0, 0, 300, 300). Once that's gone, you no longer need paddle_pos at all, so you can delete that as well. From agardner210 at gmail.com Sun Mar 10 18:25:51 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Sun, 10 Mar 2013 15:25:51 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <8d5299d0-dcf2-4f16-985c-d1f4a5e1ac69@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) Now the cursor isn't moving at all! while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() screen.blit(bpaddle, paddle_rect) # Draw the net pygame.draw.line(screen, game.lineColor, game.net1, game.net2, game.netWidth) paddle_rect.clamp_ip(bounds_rect) screen.blit(beeper, paddle_rect) clock.tick(50) pygame.display.update() From ian.g.kelly at gmail.com Sun Mar 10 21:26:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Mar 2013 19:26:48 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: <8d5299d0-dcf2-4f16-985c-d1f4a5e1ac69@googlegroups.com> References: <8d5299d0-dcf2-4f16-985c-d1f4a5e1ac69@googlegroups.com> Message-ID: On Sun, Mar 10, 2013 at 4:25 PM, Alex Gardner wrote: > Now the cursor isn't moving at all! > > while True: > for event in pygame.event.get(): > if event.type == QUIT: > sys.exit() > > screen.blit(bpaddle, paddle_rect) > # Draw the net > pygame.draw.line(screen, game.lineColor, game.net1, game.net2, game.netWidth) > > paddle_rect.clamp_ip(bounds_rect) > screen.blit(beeper, paddle_rect) > > clock.tick(50) > > pygame.display.update() You deleted the line where you update the paddle_rect from the current mouse position. From agardner210 at gmail.com Mon Mar 11 12:57:49 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 11 Mar 2013 09:57:49 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <32c01b7e-a118-44f3-a79c-8ca7bc0916cf@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) I added the blank paddle and now the green one is just gone..... I feel like such a newbie >< From agardner210 at gmail.com Mon Mar 11 13:00:37 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 11 Mar 2013 10:00:37 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: <32c01b7e-a118-44f3-a79c-8ca7bc0916cf@googlegroups.com> References: <32c01b7e-a118-44f3-a79c-8ca7bc0916cf@googlegroups.com> Message-ID: On Monday, March 11, 2013 11:57:49 AM UTC-5, Alex Gardner wrote: > On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > > > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > > > > > > > > > Main class: http://pastebin.com/HSQzX6h2 > > > > > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > > > > > > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) > > > I added the blank paddle and now the green one is just gone..... I feel like such a newbie >< screen.blit(bpaddle, paddle_rect) From agardner210 at gmail.com Mon Mar 11 13:04:05 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 11 Mar 2013 10:04:05 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: <32c01b7e-a118-44f3-a79c-8ca7bc0916cf@googlegroups.com> Message-ID: <6c7e41eb-57a1-4a05-84ca-1285813100ce@googlegroups.com> On Monday, March 11, 2013 12:00:37 PM UTC-5, Alex Gardner wrote: > On Monday, March 11, 2013 11:57:49 AM UTC-5, Alex Gardner wrote: > > > On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > > > > > > > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > > > > > > > > > > > > > > > > > > > > > > > > > Main class: http://pastebin.com/HSQzX6h2 > > > > > > > > > > > > > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > > > > > > > > > > > > > > > > > > > > > > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) > > > > > > > > > > > > > I added the blank paddle after the green one and now the green one is just gone..... I feel like such a newbie >< > screen.blit(bpaddle, paddle_rect) From ian.g.kelly at gmail.com Mon Mar 11 13:24:05 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Mar 2013 11:24:05 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: References: <32c01b7e-a118-44f3-a79c-8ca7bc0916cf@googlegroups.com> Message-ID: On Mon, Mar 11, 2013 at 11:00 AM, Alex Gardner wrote: > I added the blank paddle and now the green one is just gone..... I feel like such a newbie >< > > > screen.blit(bpaddle, paddle_rect) We're not psychic, so you'll need to post the current code if you want any suggestions on how to fix it. From agardner210 at gmail.com Mon Mar 11 13:33:21 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 11 Mar 2013 10:33:21 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <5cd72005-e3c3-4ab7-850c-5c2e55e74353@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) My bad! http://pastebin.com/yuvpT7bH From ian.g.kelly at gmail.com Mon Mar 11 14:01:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Mar 2013 12:01:48 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: <5cd72005-e3c3-4ab7-850c-5c2e55e74353@googlegroups.com> References: <5cd72005-e3c3-4ab7-850c-5c2e55e74353@googlegroups.com> Message-ID: On Mon, Mar 11, 2013 at 11:33 AM, Alex Gardner wrote: > My bad! http://pastebin.com/yuvpT7bH You're still drawing the blank paddle in two different places. One of those places is immediately after you draw the paddle, which undoes the work you just did in drawing it. That's why you're not seeing the paddle. You're also still not updating the paddle_rect from the current mouse position, so if you fix the above issue you will find that the paddle still will not move. You should restore the "paddle_rect.center = pygame.mouse.get_pos()" line that you deleted prior to the line that clamps it. Finally, you currently have the "clock.tick()" call before the "pygame.display.update()" call, which makes no sense. You're doing your drawing, asking pygame to sleep for 20 milliseconds, and only then updating the display. You want to update the display before the clock.tick() so that the user can actually see the most recent frame during those 20 milliseconds. From agardner210 at gmail.com Mon Mar 11 16:43:29 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 11 Mar 2013 13:43:29 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) I tried to append what you told me to. Now it appears that I have a syntax error! I checked my indentations and they look fine to me, but I get this error: paddle_pos = pygame.mouse.get_pos() ^ IndentationError: unindent does not match any outer indentation level I added "paddle_rect.center = pygame.mouse.get_pos()" and removed the double blank paddles. I have no idea if it works though because of the parse error! New code: http://pastebin.com/maqWCdNB From python at mrabarnett.plus.com Mon Mar 11 16:54:02 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 11 Mar 2013 20:54:02 +0000 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <513E446A.1000503@mrabarnett.plus.com> On 11/03/2013 20:43, Alex Gardner wrote: > On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: >> I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: >> >> >> >> Main class: http://pastebin.com/HSQzX6h2 >> >> Main file (where the problem lies): http://pastebin.com/67p97RsJ >> >> >> >> If the links yield nothing, please let me know (agardner210 at gmail.com) > I tried to append what you told me to. Now it appears that I have a syntax error! I checked my indentations and they look fine to me, but I get this error: > > paddle_pos = pygame.mouse.get_pos() > ^ > IndentationError: unindent does not match any outer indentation level > > I added "paddle_rect.center = pygame.mouse.get_pos()" and removed the double blank paddles. I have no idea if it works though because of the parse error! New code: http://pastebin.com/maqWCdNB > It's complaining because the preceding 'for' loop is indented more that that line. From ian.g.kelly at gmail.com Mon Mar 11 17:23:19 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Mar 2013 15:23:19 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Mon, Mar 11, 2013 at 2:43 PM, Alex Gardner wrote: > I tried to append what you told me to. Now it appears that I have a syntax error! I checked my indentations and they look fine to me, but I get this error: > > paddle_pos = pygame.mouse.get_pos() > ^ > IndentationError: unindent does not match any outer indentation level The "for" statement and the statement quoted above should both be at the same indentation level. If you look at the code, the "for" statement is indented 7 spaces whereas the other statement is indented 4 spaces. You need to make them equal. > I added "paddle_rect.center = pygame.mouse.get_pos()" and removed the double blank paddles. I have no idea if it works though because of the parse error! New code: http://pastebin.com/maqWCdNB It won't. You've removed both the position-clamping code and the clock tick code entirely. Why did you do that? You've also gone from having two separate lines drawing bpaddle and one line drawing beeper, to having two separate lines drawing beeper, and not drawing bpaddle at all. I think that you need to step back from this and try to understand better the logical flow that you're trying to implement here. Once you understand what it is that you're trying to accomplish, then you can set it down in code. The overall flow should look like this: while True: Try to implement each of those things as a discrete unit, and think hard about what operations need to be done and in what order to accomplish each of those things. It might help you conceptually to split the first three off into separate functions that each do one specific piece of the above, and then implement each of those functions thinking only about what that particular function needs to do. To provide a concrete example of what I am talking about, consider replacing your main loop with this: state = SomeClassRepresentingTheGameState() while True: # checks for a QUIT event process_events(state) # moves the ball and paddles, updates scores, etc. update_game(state) # clears the old state from the display and draws the current state onto it draw_game(state) pygame.display.update() clock.tick(50) And then separately implement all three of those functions, thinking only about how each function needs to interact with the state and what pygame calls it needs to make in order to accomplish its specific task. Right now the state object would only contain your paddle_rect, but later you will presumably have more state to add (e.g. the players' scores, the position and velocity of the ball, etc.), so it will be useful then to have a single object you can pass around to contain those. From agardner210 at gmail.com Tue Mar 12 19:33:24 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Tue, 12 Mar 2013 16:33:24 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) Sorry but im back to square one. My paddle isn't showing up at all! http://pastebin.com/PB5L8Th0 From ian.g.kelly at gmail.com Tue Mar 12 23:00:43 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Mar 2013 21:00:43 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Tue, Mar 12, 2013 at 5:33 PM, Alex Gardner wrote: > Sorry but im back to square one. My paddle isn't showing up at all! http://pastebin.com/PB5L8Th0 paddle_rect.center = pygame.mouse.get_pos() This updates the paddle position. screen.blit(beeper, paddle_rect) This draws the paddle at that position. screen.blit(bpaddle, paddle_rect) This draws the blank paddle at that same position. Try to think about why this results in the paddle not showing up. If this is for a class, I think you should spend some quality time with the TA rather than continue to throw non-functional code at this list, which is clearly getting you nowhere. From agardner210 at gmail.com Thu Mar 14 18:16:10 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Thu, 14 Mar 2013 15:16:10 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) It's all working now with one exception. I just want to arrange the paddle to the right side. I managed to do just that, but it won't move freely vertically. I am not fully aware of the arguments of pygame.Rect(). Here is what I am using: bounds_rect = pygame.Rect(880,200,0,500) Again, it all works minus the vertcal movement. The full code (keep in mind it works fine now) is http://pastebin.com/xAAda30e I thank you all (esp. Ian) for this help. I broke down and remade the code and behold it works (with this exception). Oh, Ian, this isn't a class assignment; it's a personal project to help me in the process of learning python. From ian.g.kelly at gmail.com Thu Mar 14 18:31:20 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Mar 2013 16:31:20 -0600 Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Thu, Mar 14, 2013 at 4:16 PM, Alex Gardner wrote: > It's all working now with one exception. I just want to arrange the paddle to the right side. I managed to do just that, but it won't move freely vertically. I am not fully aware of the arguments of pygame.Rect(). I recommend you read the docs, then: http://www.pygame.org/docs/ref/rect.html In particular, the clamp method documentation states: If the rectangle is too large to fit inside, it is centered inside the argument Rect, but its size is not changed. This is the case because your bounds_rect has width 0. I suggest changing the width of the bounds_rect to be equal to the width of the paddle. From agardner210 at gmail.com Thu Mar 14 18:56:08 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Thu, 14 Mar 2013 15:56:08 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <586f74eb-aa7d-4859-91d8-4e21f91f4c61@googlegroups.com> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) The docs helped (never knew they were there!) and its all safe and sound for now. Thanks :) From agardner210 at gmail.com Mon Mar 18 16:24:57 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 18 Mar 2013 13:24:57 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > Main class: http://pastebin.com/HSQzX6h2 > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) All is okay save for one thing! I joined the ball and the p1 paddle in the same program. Both of the images flicker to some extent. The paddle itself rarely shows up. I am not quite sure where / when to flip the display :( [ http://pastebin.com/xzMwa85X ] From agardner210 at gmail.com Mon Mar 18 19:05:58 2013 From: agardner210 at gmail.com (Alex Gardner) Date: Mon, 18 Mar 2013 16:05:58 -0700 (PDT) Subject: Pygame mouse cursor load/unload In-Reply-To: References: Message-ID: <96cd9bcb-e510-4d43-a597-fc4e84e62b7a@googlegroups.com> On Monday, March 18, 2013 3:24:57 PM UTC-5, Alex Gardner wrote: > On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote: > > > I am in the process of making a pong game in python using the pygame library. My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving. The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor. Perhaps my code would best explain my problem. I will take help in any way that I can. Here are the links that contain my code: > > > > > > > > > > > > Main class: http://pastebin.com/HSQzX6h2 > > > > > > Main file (where the problem lies): http://pastebin.com/67p97RsJ > > > > > > > > > > > > If the links yield nothing, please let me know (agardner210 at gmail.com) > > All is okay save for one thing! I joined the ball and the p1 paddle in the same program. Both of the images flicker to some extent. The paddle itself rarely shows up. I am not quite sure where / when to flip the display :( [ http://pastebin.com/i1GbT6JB ] From yomnasalah91 at gmail.com Sat Mar 2 22:06:53 2013 From: yomnasalah91 at gmail.com (yomnasalah91 at gmail.com) Date: Sat, 2 Mar 2013 19:06:53 -0800 (PST) Subject: Question about Tashaphyne package in python Message-ID: <0d0a40de-052c-49df-b43e-dff935071b49@googlegroups.com> I have a Python code that take an Arabic word and get the root and also remove diacritics, but i I have a problem with the output. For example : when the input is "???????" the output is:"???" which is right answer but when the input is "????" the output is:"?", and when the input is "????" the output is " ??". This is my code: # -*- coding=utf-8 -*- import re from arabic_const import * import Tashaphyne from Tashaphyne import * import enum from enum import Enum search_type=Enum('unvoc_word','voc_word','root_word') HARAKAT_pat = re.compile(ur"[" + u"".join([FATHATAN, DAMMATAN, KASRATAN, FATHA, DAMMA, KASRA, SUKUN, SHADDA]) + u"]") HAMZAT_pat = re.compile(ur"[" + u"".join([WAW_HAMZA, YEH_HAMZA]) + u"]"); ALEFAT_pat = re.compile(ur"[" + u"".join([ALEF_MADDA, ALEF_HAMZA_ABOVE, ALEF_HAMZA_BELOW, HAMZA_ABOVE, HAMZA_BELOW]) + u"]"); LAMALEFAT_pat = re.compile(ur"[" + u"".join([LAM_ALEF, LAM_ALEF_HAMZA_ABOVE, LAM_ALEF_HAMZA_BELOW, LAM_ALEF_MADDA_ABOVE]) + u"]"); #-------------------------------------- def strip_tashkeel(w): "strip vowel from a word and return a result word" return HARAKAT_pat.sub('', w) #strip tatweel from a word and return a result word #-------------------------------------- def strip_tatweel(w): "strip tatweel from a word and return a result word" return re.sub(ur'[%s]' % TATWEEL, '', w) #-------------------------------------- def normalize_hamza(w): "strip vowel from a word and return a result word" w = ALEFAT_pat.sub(ALEF, w) return HAMZAT_pat.sub(HAMZA, w) #-------------------------------------- def normalize_lamalef(w): "strip vowel from a word and return a result word" return LAMALEFAT_pat.sub(u'%s%s' % (LAM, ALEF), w) #-------------------------------------- def normalize_spellerrors(w): "strip vowel from a word and return a result word" w = re.sub(ur'[%s]' % TEH_MARBUTA, HEH, w) return re.sub(ur'[%s]' % ALEF_MAKSURA, YEH, w) def guess_stem(self,word): """ Detetect affixed letters based or phonetic root composition. In Arabic language, there are some letters which can't be adjacent in a root. This function return True, if the word is valid, else, return False @param word: the word. @type word: unicode. @return: word with a '-' to indicate the stemming position. @rtype: unicode """ # certain roots are forbiden in arabic #exprimed in letters sequences # but this sequence can be used for affixation #then we can guess that this letters are affixed # #treat one prefixe letter # we strip harkat and shadda word=ar_strip_marks(word); prefixes_letters=(TEH, MEEM,LAM,WAW,BEH, KAF,FEH,HAMZA,YEH,NOON) prefixes_forbiden={ ALEF_HAMZA_ABOVE:(ALEF_HAMZA_ABOVE,ZAH,AIN,GHAIN), BEH:(BEH,FEH,MEEM), TEH:(THEH,DAL,THAL,ZAIN,SHEEN,SAD,DAD,TAH,ZAH), FEH:(BEH,FEH,MEEM), KAF:(JEEM,DAD,TAH,ZAH,QAF,KAF), LAM:(REH,SHEEN,LAM,NOON), MEEM:(BEH,FEH,MEEM), NOON:(REH,LAM,NOON), WAW:(WAW,YEH), YEH:(THEH,JEEM,HAH,KHAH,THAL,ZAIN,SHEEN,SAD,DAD,TAH,ZAH,GHAIN,KAF,HEH,YEH), } word_guess=word; if len(word)>=2: c1=word[0]; c2=word[1]; # if c1 in prefixes_letters and (c1 in prefixes_forbiden.keys() and c2 in prefixes_forbiden[c1]): if prefixes_forbiden.has_key(c1) and c2 in prefixes_forbiden[c1]: word_guess=u"%s-%s"%(c1,word[1:]) if len(word_guess)>=4: c1=word_guess[2]; c2=word_guess[3]; if c1 in prefixes_letters and ( c2 in prefixes_forbiden[c1]): word_guess=u"%s-%s"%(c1,word_guess[2:]) # treat two suffixe letters bisuffixes_letters=(KAF+MEEM,KAF+NOON,HEH+MEEM,HEH+NOON) bisuffixes_forbiden={ HEH+MEEM:(ALEF_HAMZA_ABOVE,HAMZA,WAW_HAMZA,YEH_HAMZA,BEH,THEH,HAH, KHAH, SAD, DAD, TAH,ZAH,AIN,GHAIN,HEH,YEH), KAF+MEEM:(ALEF_HAMZA_ABOVE,HAMZA,WAW_HAMZA,YEH_HAMZA,BEH,THEH,JEEM, KHAH,ZAIN,SEEN, SHEEN,DAD, TAH,ZAH,GHAIN, FEH, QAF,KAF, LAM, NOON, HEH,YEH), HEH+NOON:(ALEF_HAMZA_ABOVE,HAMZA,WAW_HAMZA,YEH_HAMZA,BEH,THEH,JEEM,HAH, KHAH, SAD, DAD, TAH,ZAH,AIN,GHAIN,HEH,YEH), KAF+NOON:(ALEF_HAMZA_ABOVE,HAMZA,WAW_HAMZA,YEH_HAMZA,BEH,THEH,JEEM,HAH, KHAH,THAL,SHEEN,DAD, TAH,ZAH,AIN, GHAIN, QAF,KAF, NOON, HEH,YEH), } ## word_guess=word; word=word_guess; if len(word)>=3: bc_last=word[-2:]; bc_blast=word[-3:-2] if bc_last in bisuffixes_letters: if bc_blast in bisuffixes_forbiden[bc_last]: word_guess=u"%s-%s"%(word[:-2],bc_last) # treat one suffixe letters suffixes_letters=(KAF,TEH,HEH) suffixes_forbiden={ TEH:(THEH,JEEM,DAL,THAL,ZAIN,SHEEN,TAH,ZAH), KAF:(THEH,JEEM,KHAH, THAL,TAH,ZAH,GHAIN,QAF), HEH:(TEH,HAH,KHAH,DAL,REH,SEEN,SHEEN,SAD,ZAH,AIN,GHAIN), } word=word_guess; c_last=word[-1:]; c_blast=word[-2:-1] if c_last in suffixes_letters: if c_blast in suffixes_forbiden[c_last]: word_guess=u"%s-%s"%(word[:-1],c_last) return word_guess; def normalize_text(word,searchtype): word = strip_tashkeel(word) print word word = strip_tatweel(word) print word word = normalize_lamalef(word) print word word = normalize_hamza(word) print word word = normalize_spellerrors(word) print word if searchtype==search_type.root_word.index: """ArListem=ArabicLightStemmer() stem=ArListem.lightStem(word) word=ArListem.get_stem() print word w=ArListem.get_prefix() print w word=ArListem.get_root()""" word=guess_stem(word,w) print word return word From python at mrabarnett.plus.com Sun Mar 3 14:01:30 2013 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 03 Mar 2013 19:01:30 +0000 Subject: Question about Tashaphyne package in python In-Reply-To: <0d0a40de-052c-49df-b43e-dff935071b49@googlegroups.com> References: <0d0a40de-052c-49df-b43e-dff935071b49@googlegroups.com> Message-ID: <51339E0A.6060102@mrabarnett.plus.com> On 2013-03-03 03:06, yomnasalah91 at gmail.com wrote: > I have a Python code that take an Arabic word and get the root and also remove diacritics, but i I have a problem with the output. For example : when the input is "???????" the output is:"???" which is right answer but when the input is "????" the output is:"?", and when the input is "????" the output is " ??". > > This is my code: > > # -*- coding=utf-8 -*- > > import re > from arabic_const import * > import Tashaphyne > from Tashaphyne import * > import enum > from enum import Enum > search_type=Enum('unvoc_word','voc_word','root_word') > > HARAKAT_pat = re.compile(ur"[" + u"".join([FATHATAN, DAMMATAN, KASRATAN, FATHA, DAMMA, KASRA, SUKUN, SHADDA]) + u"]") > HAMZAT_pat = re.compile(ur"[" + u"".join([WAW_HAMZA, YEH_HAMZA]) + u"]"); > ALEFAT_pat = re.compile(ur"[" + u"".join([ALEF_MADDA, ALEF_HAMZA_ABOVE, ALEF_HAMZA_BELOW, HAMZA_ABOVE, HAMZA_BELOW]) + u"]"); > LAMALEFAT_pat = re.compile(ur"[" + u"".join([LAM_ALEF, LAM_ALEF_HAMZA_ABOVE, LAM_ALEF_HAMZA_BELOW, LAM_ALEF_MADDA_ABOVE]) + u"]"); > [snip] When you're using Unicode with re in Python 2, you should include the re.UNICODE flag. For example: HARAKAT_pat = re.compile(ur"[" + u"".join([FATHATAN, DAMMATAN, KASRATAN, FATHA, DAMMA, KASRA, SUKUN, SHADDA]) + u"]", flags=re.UNICODE) or: HARAKAT_pat = re.compile(ur"(?u)[" + u"".join([FATHATAN, DAMMATAN, KASRATAN, FATHA, DAMMA, KASRA, SUKUN, SHADDA]) + u"]") I don't know whether that will make a difference in this case because I don't know Tashaphyne or Arabic. From sarbjit1987 at gmail.com Sun Mar 3 09:18:00 2013 From: sarbjit1987 at gmail.com (Sarbjit singh) Date: Sun, 3 Mar 2013 06:18:00 -0800 (PST) Subject: Python in web development Message-ID: Hello All, I have been using Python as a scripting language for my office tasks. Now I have been thinking of using (and learning as well) for web development. For my tasks, I need to perform some tasks and report on the web. Now I have no experience of web development with Python. So, I want to conform first whether Python is best for web development. Python is my personal choice for my automation works and I want to extend it for web development. REQUIREMENT: I need to develop a html form which would take user input and perform some operations (generate intermediate files) and report result on web. >> Some guys in my organization are using Perl for this purpose and thus I could get the setup for free.But I want to learn and use Python as substitute for Perl. (PHP could also be an option. I have worked on PHP once for handling the form data.) So my questions are:- 1. Can I use Python (I want to use personally :)) over PHP/Perl? 2. If Yes, I want to know the modules that I should learn for achieving my requirement. I searched internet and found Python provides CGI, Django etc. I don't much about Django/CGI, please suggest which module I should learn and use. Thanks Sarbjit From bex.lewis at gmail.com Sun Mar 3 09:50:56 2013 From: bex.lewis at gmail.com (becky_lewis) Date: Sun, 3 Mar 2013 06:50:56 -0800 (PST) Subject: Python in web development In-Reply-To: References: Message-ID: <6f076125-558c-424d-802e-6b80bf4d0e1f@googlegroups.com> 1) Python is absolutely fine for web development. It's just as good, if not better than PHP or Perl for this sort of work (that's my opinion anyway). 2) I've used Django quite extensively and it can certainly handle your requirements. You might want to have a look at Flask (http://flask.pocoo.org/) as it's not quite as heavy as Django so would possibly suit your needs a little better. On Sunday, March 3, 2013 2:18:00 PM UTC, Sarbjit singh wrote: > Hello All, > > > > I have been using Python as a scripting language for my office tasks. Now I have been thinking of using (and learning as well) for web development. For my tasks, I need to perform some tasks and report on the web. Now I have no experience of web development with Python. So, I want to conform first whether Python is best for web development. Python is my personal choice for my automation works and I want to extend it for web development. > > > > REQUIREMENT: > > I need to develop a html form which would take user input and perform some operations (generate intermediate files) and report result on web. > > > > >> Some guys in my organization are using Perl for this purpose and thus I could get the setup for free.But I want to learn and use Python as substitute for Perl. (PHP could also be an option. I have worked on PHP once for handling the form data.) > > > > So my questions are:- > > > > 1. Can I use Python (I want to use personally :)) over PHP/Perl? > > > > 2. If Yes, I want to know the modules that I should learn for achieving my requirement. I searched internet and found Python provides CGI, Django etc. > > > > I don't much about Django/CGI, please suggest which module I should learn and use. > > > > Thanks > > Sarbjit From torriem at gmail.com Sun Mar 3 11:19:16 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 03 Mar 2013 09:19:16 -0700 Subject: Python in web development In-Reply-To: References: Message-ID: <51337804.6020204@gmail.com> On 03/03/2013 07:18 AM, Sarbjit singh wrote: > 1. Can I use Python (I want to use personally :)) over PHP/Perl? Yes of course. > 2. If Yes, I want to know the modules that I should learn for > achieving my requirement. I searched internet and found Python > provides CGI, Django etc. > > I don't much about Django/CGI, please suggest which module I should > learn and use. There are literally dozens of frameworks you can use. You could use straight CGI if you wanted, but I recommend a framework with a decent templating engine for HTML code generation. Anyway, a list--not exhaustive--of frameworks can be found here: http://wiki.python.org/moin/WebFrameworks Django is one of the most popular. Web2Py is another. Though they might seem overkill, it's well worth it to use them and learn them. They both have good documentation. So start there at their individual sites. From hermanmu at gmail.com Sun Mar 3 12:20:02 2013 From: hermanmu at gmail.com (Michael Herman) Date: Sun, 3 Mar 2013 09:20:02 -0800 Subject: Python in web development In-Reply-To: References: Message-ID: If Python is your personal choice, then it's the *best* for you. If you are literally just going to be processing an HTML form, then CGI is your best bet. However, if you think this functionally will grow, then it's worth learning a web framework. I would go with a micro framework. bottle.py is a perfect starting point. I am a huge Flask fan, but it's a little higher level. I have tutorials here for Flask - http://www.youtube.com/playlist?list=PLLjmbh6XPGK5pM1QJ8I1ccdGiCTHa1IC8 Also, check out realpythonfortheweb.com for more tutorials. Good luck! :) On Sun, Mar 3, 2013 at 6:18 AM, Sarbjit singh wrote: > > Hello All, > > I have been using Python as a scripting language for my office tasks. Now > I have been thinking of using (and learning as well) for web development. > For my tasks, I need to perform some tasks and report on the web. Now I have > no experience of web development with Python. So, I want to conform first > whether Python is best for web development. Python is my personal choice for > my automation works and I want to extend it for web development. > > REQUIREMENT: > I need to develop a html form which would take user input and perform some > operations (generate intermediate files) and report result on web. > > >> Some guys in my organization are using Perl for this purpose and thus I > >> could get the setup for free.But I want to learn and use Python as > >> substitute for Perl. (PHP could also be an option. I have worked on PHP once > >> for handling the form data.) > > So my questions are:- > > 1. Can I use Python (I want to use personally :)) over PHP/Perl? > > 2. If Yes, I want to know the modules that I should learn for achieving my > requirement. I searched internet and found Python provides CGI, Django etc. > > I don't much about Django/CGI, please suggest which module I should learn > and use. > > Thanks > Sarbjit > -- > http://mail.python.org/mailman/listinfo/python-list From roy at panix.com Sun Mar 3 14:34:52 2013 From: roy at panix.com (Roy Smith) Date: Sun, 03 Mar 2013 14:34:52 -0500 Subject: Python in web development References: Message-ID: In article , Sarbjit singh wrote: > Hello All, > > I have been using Python as a scripting language for my office tasks. Now I > have been thinking of using (and learning as well) for web development. For > my tasks, I need to perform some tasks and report on the web. Now I have no > experience of web development with Python. So, I want to conform first > whether Python is best for web development. Python is my personal choice for > my automation works and I want to extend it for web development. > > REQUIREMENT: > I need to develop a html form which would take user input and perform some > operations (generate intermediate files) and report result on web. It's got a bit of a steep learning curve, but django might be what you're looking for. I would start with the tutorial: https://docs.djangoproject.com/en/1.5/intro/tutorial01/ and eventually work your way to class-based views and forms: https://docs.djangoproject.com/en/1.5/topics/class-based-views/generic-ed iting/ From tavares at fe.up.pt Sun Mar 3 12:14:18 2013 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Sun, 3 Mar 2013 09:14:18 -0800 (PST) Subject: IV ECCOMAS Thematic Conference VipIMAGE 2013: CALL FOR CONTRIBUTIONS Message-ID: <5f5e5d5c-bddf-4f66-8107-a8e941b51631@googlegroups.com> Dear Colleague, We are pleased to invite you to the International Conference VipIMAGE 2013 - IV ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING (www.fe.up.pt/~vipimage) to be held October 14-16, 2013, in Melia Madeira Mare Hotel, Madeira Island, Funchal, Portugal. Possible Topics (not limited to) ? Signal and Image Processing ? Computational Vision ? Medical Imaging ? Physics of Medical Imaging ? Tracking and Analysis of Movement ? Simulation and Modeling ? Image Acquisition ? Industrial Applications ? Shape Reconstruction ? Objects Segmentation, Matching, Simulation ? Data Interpolation, Registration, Acquisition and Compression ? 3D Vision ? Virtual Reality ? Visual Inspection ? Software Development for Image Processing and Analysis ? Computer Aided Diagnosis, Surgery, Therapy, and Treatment ? Computational Bioimaging and Visualization ? Telemedicine Systems and their Applications Invited Lecturers ? Daniel Rueckert - Imperial College London, UK ? Dimitris N. Metaxas - Rutgers University, USA ? Durval C. Costa - Champalimaud Foundation, Portugal ? James S Duncan - Yale School of Medicine, USA ? Milan Sonka - The University of Iowa, USA ? Richard Bowden - University of Surrey, UK Thematic Sessions Proposals to organize Thematic Session under the auspicious of VipIMAGE 2013 are welcome. The organizers of the selected thematic sessions will be included in the conference scientific committee and will have a reduced registration fee. Additionally, they will be responsible for the dissemination of their thematic session, may invite expertise researchers to have invited keynotes during their session and will participate in the review process of the submitted contributions. Proposals for Thematic Sessions should be submitted by email to the conference co-chairs (tavares at fe.up.pt, rnatal at fe.up.pt) until March 1, 2013. Confirmed thematic session: ?Imaging of Biological Flows: trends and challenges? Publications Proceedings: The proceedings book will be published by the Taylor & Francis Group (www.balkema.nl/instructions.asp) and indexed by Thomson Reuters Conference Proceedings Citation Index, IET Inspect and Elsevier Scopus. Springer Book: A book with 20 invited works from the ones presented in the conference will be published by Springer under the book series ?Lecture Notes in Computational Vision and Biomechanics? (www.springer.com/series/8910). Journal Publication: A dedicated special issue of the Taylor & Francis International Journal ?Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization? (www.tandfonline.com/tciv) will be published with extended versions of the best works presented in the conference. Important dates ? Deadline for Thematic Session Proposals: March 1, 2013 ? Deadline for Extended Abstracts: April 15, 2013 ? Authors Notification: May 1, 2013 ? Deadline for Lectures and Papers: July 1, 2013 We are looking forward to see you in Funchal next October. Kind regards, Jo?o Manuel R. S. Tavares Renato Natal Jorge (conference co-chairs) PS. For further details please have a look in the conference website at: www.fe.up.pt/~vipimage, or the facebook page at: www.facebook.com/pages/Vipimage/237980719665456 From hossamalagmy at gmail.com Sun Mar 3 12:32:44 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sun, 3 Mar 2013 09:32:44 -0800 (PST) Subject: =?windows-1256?B?x9PK3crHwSDl4SDTytTH0d8g3ewgx+HH5MrOxw==?= =?windows-1256?B?yMfKIMfhyNHh48fk7eUgx+Hex8/j5SDjzOHTIMfh5OY=?= =?windows-1256?B?x8g=?= Message-ID: <43439950-98e2-442e-8d10-15c5aaf2c7da@14g2000vbr.googlegroups.com> ??????? ?? ?????? ?? ?????????? ?????????? ??????? ???? ?????? https://www.facebook.com/permalink.php?story_fbid=542812542426361&id=299719160065550 facebook https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fnatigtas7ab.blogspot.com%2F2013%2F03%2Fblog-post_7369.html%23.UTOIFr8OJp8.facebook twitter https://twitter.com/intent/tweet?text=%D8%A7%D8%B3%D8%AA%D9%81%D8%AA%D8%A7%D8%A1+%D9%87%D9%84+%D8%B3%D8%AA%D8%B4%D8%A7%D8%B1%D9%83+%D9%81%D9%89+%D8%A7%D9%84%D8%A7%D9%86%D8%AA%D8%AE%D8%A7%D8%A8%D8%A7%D8%AA+%D8%A7%D9%84%D8%A8%D8%B1%D9%84%D9%85%D8%A7%D9%86%D9%8A%D9%87+%D8%A7%D9%84%D9%82%D8%A7%D8%AF%D9%85%D9%87+%D9%85%D8%AC%D9%84%D8%B3+%D8%A7%D9%84%D9%86%D9%88%D8%A7%D8%A8+~+%D9%86%D8%AA%D8%A7%D8%A6%D8%AC+%D8%A7%D9%84%D8%A5%D9%85%D8%AA%D8%AD%D8%A7%D9%86%D8%A7%D8%AA+%D9%84%D9%84%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA+%D9%88%D8%A7%D9%84%D8%AC%D8%A7%D9%85%D8%B9%D8%A7%D8%AA&url=http%3A%2F%2Fnatigtas7ab.blogspot.com%2F2013%2F03%2Fblog-post_7369.html%23.UTOIGTZk_ew.twitter&related= From roy at panix.com Sun Mar 3 16:56:16 2013 From: roy at panix.com (Roy Smith) Date: Sun, 03 Mar 2013 16:56:16 -0500 Subject: How to prevent tests from running against production? Message-ID: Our deploy/configuration system includes credentials for connecting to a database. We have one production database, and a variety of clones of that in our test and development environments. We've got a large body of tests, written with a combination of unittest and nose. Many of our tests do things which shouldn't be done against the production database. I'd like to set things up so anytime any test code gets run, a check is made to see which database you're connected to and if you're connect to production, the test refuses to run. It's easy to write a check like that in setup(), but that only gets called if you remember to write a setup() method (or inherit from something that does). I'm looking for something that runs completely automatically. I don't want somebody to be able to write something which causes damage that nose can discover and run when you're connected to the wrong database. From rridge at csclub.uwaterloo.ca Sun Mar 3 23:30:02 2013 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 03 Mar 2013 23:30:02 -0500 Subject: How to prevent tests from running against production? References: Message-ID: Roy Smith wrote: >Our deploy/configuration system includes credentials for connecting to a >database. We have one production database, and a variety of clones of >that in our test and development environments. Having your tests use credentials that don't work in the production environment would seem to be the obvious solution. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From steve+comp.lang.python at pearwood.info Mon Mar 4 02:05:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2013 07:05:19 GMT Subject: How to prevent tests from running against production? References: Message-ID: <513447af$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 03 Mar 2013 16:56:16 -0500, Roy Smith wrote: > Our deploy/configuration system includes credentials for connecting to a > database. We have one production database, and a variety of clones of > that in our test and development environments. > > We've got a large body of tests, written with a combination of unittest > and nose. Many of our tests do things which shouldn't be done against > the production database. I'd like to set things up so anytime any test > code gets run, a check is made to see which database you're connected to > and if you're connect to production, the test refuses to run. Test code is just code, so in general you can't guarantee to idiot-proof your tests. Anyone can write a function, called by one of the tests, which connects directly to the production database and does whatever they want. But I assume you're not worried about malice. One solution: create a single module, used by all tests, that handles connection to the database. Simply don't have your connection module connect to the database you don't want it to connect to. Since all tests go through that module for connections, you can enforce whatever access rules you like. For added security, you should ensure that the production database does not accept the same credentials as the test databases. Another solution: instead of calling unittest.TestCase directly, write your own subclass, then have all your tests use that: class MyTestCase(unittest.TestCase): def __init__(self, *args, **kwargs): if DATABASE == 'Production': import webbrowser webbrowser.open("http://i.imgur.com/y7Hm9.jpg", new=1) raise RuntimeError("don't use production database") super(MyTestCase, self).__init__(*args, **kwargs) For added paranoia (and/or debugging fun), consider monkey-patching unittest and/or nose. -- Steven From yomnasalah91 at gmail.com Mon Mar 4 04:37:42 2013 From: yomnasalah91 at gmail.com (yomnasalah91 at gmail.com) Date: Mon, 4 Mar 2013 01:37:42 -0800 (PST) Subject: Encoding problem in python Message-ID: I have a problem with encoding in python 27 shell. when i write this in the python shell: w=u'??????' It gives me the following error: Unsupported characters in input any help? From gandalf at shopzeus.com Mon Mar 4 04:57:41 2013 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 04 Mar 2013 10:57:41 +0100 Subject: Encoding problem in python In-Reply-To: References: Message-ID: <51347015.1060103@shopzeus.com> On 2013-03-04 10:37, yomnasalah91 at gmail.com wrote: > I have a problem with encoding in python 27 shell. > > when i write this in the python shell: > > w=u'??????' > > It gives me the following error: > > Unsupported characters in input > > any help? Maybe it is not Python related. Did you get an exception? Can you send a full traceback? I suspect that the error comes from your terminal, and not Python. Please make sure that your terminal supports UTF-8 encoding. Alternatively, try creating a file with this content: # -*- encoding: UTF-8 -*- w=u'??????' Save it as UTF-8 encoded file "test.py" (with an UTF-8 compatible editor, for example Geany) and run it as a command: python test.py If it works then it is sure that the problem is with your terminal. It will be an OS limitation, not Python's limitation. Best, Laszlo From steve+comp.lang.python at pearwood.info Mon Mar 4 05:18:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2013 10:18:33 GMT Subject: Encoding problem in python References: Message-ID: <513474f9$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 04 Mar 2013 01:37:42 -0800, yomnasalah91 wrote: > I have a problem with encoding in python 27 shell. > > when i write this in the python shell: > > w=u'??????' > > It gives me the following error: > > Unsupported characters in input > > any help? Firstly, please show the COMPLETE error, including the full traceback. Python errors look like (for example): py> x = ord(100) Traceback (most recent call last): File "", line 1, in TypeError: ord() expected string of length 1, but int found Copy and paste the complete traceback. Secondly, please describe your environment: - What operating system and version are you using? Linux, Windows, Mac OS, something else? Which version or distro? - Which console or terminal application? E.g. cmd.exe (Windows), konsole, xterm, something else? - Which shell? E.g. the standard Python interpreter, IDLE, bpython, something else? My guess is that this is not a Python problem, but an issue with your console. You should always have your console set to use UTF-8, if possible. I expect that your console is set to use a different encoding. In that case, see if you can change it to UTF-8. For example, using Gnome Terminal on Linux, I can do this: py> w = u'??????' py> print w ?????? and it works fine, but if I change the encoding to WINDOWS-1252 using the "Set character encoding" menu command, the terminal will not allow me to paste the string into the terminal. -- Steven From vlastimil.brom at gmail.com Mon Mar 4 08:39:39 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 4 Mar 2013 14:39:39 +0100 Subject: Encoding problem in python In-Reply-To: References: Message-ID: 2013/3/4 : > I have a problem with encoding in python 27 shell. > > when i write this in the python shell: > > w=u'??????' > > It gives me the following error: > > Unsupported characters in input > > any help? > -- > http://mail.python.org/mailman/listinfo/python-list Hi, I guess, you are using the built-in IDLE shell with python 2.7 and this is a specific limitation of its handling of some unicode characters (in some builds and OSes - "narrow"-unicode, Windows, most likely?) and its specific error message - not the usual python traceback mentioned in other posts). If it is viable, using python 3.3 instead would solve this problem for IDLE: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> w='??????' >>> w '??????' (note the missing "u" in unicode literal before the starting quotation mark, which would be the usual usage in python 3, but python 3.3 also silently ignores u"..." for compatibility.) >>> w=u'??????' >>> w '??????' >>> If python 2.7 is required, another shell is probably needed (unless I am missing some option to make IDLE work for this input); e.g. the following works in pyshell - part of the wxpython GUI library http://www.wxpython.org/ >>> w=u'??????' >>> w u'\u0627\u0644\u0639\u0631\u0628\u0649' >>> print w ?????? >>> hth, vbr From vgnulinux at gmail.com Mon Mar 4 05:37:13 2013 From: vgnulinux at gmail.com (VGNU Linux) Date: Mon, 4 Mar 2013 16:07:13 +0530 Subject: Python SUDS issue Message-ID: Hi Guys, I am pretty new to web services. After some googling found that python suds is a suitable module to create web service client. I am trying to create a client but its giving me an error which is quite confusing for me. Here is my code: from suds.client import Client wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' client = Client(wsdlurl) print client And following is the error that occurs on trying to print client. Traceback (most recent call last): File "trysuds.py", line 3, in client = Client(wsdlurl) File "C:\Python25\Lib\site-packages\suds\client.py", line 112, in __init__ self.wsdl = reader.open(url) File "C:\Python25\Lib\site-packages\suds\reader.py", line 152, in open d = self.fn(url, self.options) File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 159, in __init__ self.build_schema() File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 220, in build_schema self.schema = container.load(self.options) File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 95, in load child.dereference() File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 323, in dereference midx, deps = x.dependencies() File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in dependencies raise TypeNotFound(self.ref) suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, http://www.payback.net/lmsglobal/xsd/v1/types, )' Appreciate your help. Thanks in advance, VGNU -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Mon Mar 4 08:15:06 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 4 Mar 2013 08:15:06 -0500 Subject: Python SUDS issue In-Reply-To: References: Message-ID: On Mon, Mar 4, 2013 at 5:37 AM, VGNU Linux wrote: > Hi Guys, > I am pretty new to web services. > After some googling found that python suds is a suitable module to create > web service client. I am trying to create a client but its giving me an > error which is quite confusing for me. > > Here is my code: > from suds.client import Client > wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' > What happens when you type this in your browser: https://46.51.221.138/PBExternalServices/v1/soap?wsdl > client = Client(wsdlurl) > print client > > And following is the error that occurs on trying to print client. > Traceback (most recent call last): > File "trysuds.py", line 3, in > client = Client(wsdlurl) > File "C:\Python25\Lib\site-packages\suds\client.py", line 112, in > __init__ > self.wsdl = reader.open(url) > File "C:\Python25\Lib\site-packages\suds\reader.py", line 152, in open > d = self.fn(url, self.options) > File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 159, in __init__ > self.build_schema() > File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 220, in > build_schema > self.schema = container.load(self.options) > File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 95, in load > child.dereference() > File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 323, in > dereference > midx, deps = x.dependencies() > File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in > dependencies > raise TypeNotFound(self.ref) > suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, > http://www.payback.net/lmsglobal/xsd/v1/types, )' > > Appreciate your help. > Thanks in advance, > VGNU > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vgnulinux at gmail.com Tue Mar 5 00:02:15 2013 From: vgnulinux at gmail.com (VGNU Linux) Date: Tue, 5 Mar 2013 10:32:15 +0530 Subject: Python SUDS issue In-Reply-To: References: Message-ID: Hi, Typing URL in the browser displays document tree as a web page. Is it right or there is something wrong with it ? Regards, VGNU On Mon, Mar 4, 2013 at 6:45 PM, Joel Goldstick wrote: > > > > On Mon, Mar 4, 2013 at 5:37 AM, VGNU Linux wrote: > >> Hi Guys, >> I am pretty new to web services. >> After some googling found that python suds is a suitable module to create >> web service client. I am trying to create a client but its giving me an >> error which is quite confusing for me. >> >> Here is my code: >> from suds.client import Client >> wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' >> > > > What happens when you type this in your browser: > https://46.51.221.138/PBExternalServices/v1/soap?wsdl > > >> client = Client(wsdlurl) >> print client >> >> And following is the error that occurs on trying to print client. >> Traceback (most recent call last): >> File "trysuds.py", line 3, in >> client = Client(wsdlurl) >> File "C:\Python25\Lib\site-packages\suds\client.py", line 112, in >> __init__ >> self.wsdl = reader.open(url) >> File "C:\Python25\Lib\site-packages\suds\reader.py", line 152, in open >> d = self.fn(url, self.options) >> File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 159, in __init__ >> self.build_schema() >> File "C:\Python25\Lib\site-packages\suds\wsdl.py", line 220, in >> build_schema >> self.schema = container.load(self.options) >> File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 95, in >> load >> child.dereference() >> File "C:\Python25\Lib\site-packages\suds\xsd\schema.py", line 323, in >> dereference >> midx, deps = x.dependencies() >> File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in >> dependencies >> raise TypeNotFound(self.ref) >> suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, >> http://www.payback.net/lmsglobal/xsd/v1/types, )' >> >> Appreciate your help. >> Thanks in advance, >> VGNU >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Joel Goldstick > http://joelgoldstick.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Tue Mar 5 02:16:28 2013 From: dieter at handshake.de (dieter) Date: Tue, 05 Mar 2013 08:16:28 +0100 Subject: Python SUDS issue References: Message-ID: <87d2vejoz7.fsf@handshake.de> VGNU Linux writes: > ... > Here is my code: > from suds.client import Client > wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' > client = Client(wsdlurl) > print client > > And following is the error that occurs on trying to print client. > Traceback (most recent call last): > ... > dereference > midx, deps = x.dependencies() > File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in > dependencies > raise TypeNotFound(self.ref) > suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, > http://www.payback.net/lmsglobal/xsd/v1/types, )' Looks like a bug in the "WSDL" description of the web service. It seems to reference a type "GetAccountBalanceFaultResponse" associated with the namespace "http://www.payback.net/lmsglobal/xsd/v1/types", but "suds" cannot find the type. Maybe an "import" is missing in the "WSDL" description. From vgnulinux at gmail.com Wed Mar 6 23:37:56 2013 From: vgnulinux at gmail.com (VGNU Linux) Date: Thu, 7 Mar 2013 10:07:56 +0530 Subject: Python SUDS issue In-Reply-To: <87d2vejoz7.fsf@handshake.de> References: <87d2vejoz7.fsf@handshake.de> Message-ID: Hi Guys, Not aware what "import" here is and what it will do. But going through some google search result page found that there is something called doctor in suds. so tried changing code and it did fix the issue. suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, http://www.payback.net/lmsglobal/xsd/v1/types, )' Here is what i changed. from suds.client import Client from suds.xsd.doctor import Import, ImportDoctor from suds.sax.element import Element wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' schemaurl = 'http://www.payback.net/lmsglobal/xsd/v1/types' schemaimport = Import(schemaurl) schemadoctor = ImportDoctor(schemaimport) client = Client(url=wsdlurl,doctor=schemadoctor) print client Printing client now lists all the methods and types associated with the service. But again stuck as on executing a method response = client.service.GetAccountBalance(authtype) replies with the error. ValueError: unknown url type: {endpoint address} Totally confused as what is wrong going on here. Appreciate your help. Regards, VGNU On Tue, Mar 5, 2013 at 12:46 PM, dieter wrote: > VGNU Linux writes: > > > ... > > Here is my code: > > from suds.client import Client > > wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' > > client = Client(wsdlurl) > > print client > > > > And following is the error that occurs on trying to print client. > > Traceback (most recent call last): > > ... > > dereference > > midx, deps = x.dependencies() > > File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in > > dependencies > > raise TypeNotFound(self.ref) > > suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, > > http://www.payback.net/lmsglobal/xsd/v1/types, )' > > Looks like a bug in the "WSDL" description of the web service. > It seems to reference a type "GetAccountBalanceFaultResponse" > associated with the namespace " > http://www.payback.net/lmsglobal/xsd/v1/types", > but "suds" cannot find the type. > > Maybe an "import" is missing in the "WSDL" description. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Thu Mar 7 01:55:43 2013 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 7 Mar 2013 07:55:43 +0100 Subject: Python SUDS issue In-Reply-To: References: <87d2vejoz7.fsf@handshake.de> Message-ID: <20792.14831.500019.777776@localhost.localdomain> VGNU Linux wrote at 2013-3-7 10:07 +0530: >Not aware what "import" here is and what it will do. XML-schema has an "import" facility to modularize schema descriptions. It is very similar to the "import" facilities you know from Python (and a lot of other languages) -- and has very similar purpose. > ... >Here is what i changed. >from suds.client import Client >from suds.xsd.doctor import Import, ImportDoctor >from suds.sax.element import Element > >wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' >schemaurl = 'http://www.payback.net/lmsglobal/xsd/v1/types' >schemaimport = Import(schemaurl) >schemadoctor = ImportDoctor(schemaimport) >client = Client(url=wsdlurl,doctor=schemadoctor) >print client > >Printing client now lists all the methods and types associated with the >service. >But again stuck as on executing a method >response = client.service.GetAccountBalance(authtype) >replies with the error. >ValueError: unknown url type: {endpoint address} > >Totally confused as what is wrong going on here. Again, this looks like a bug in the WSDL description of the web service. To understand the problem better, you should look at the corresponding traceback (as always). It will tell you where the "ValueError" comes from. At the corresponding code location, you should learn whether "{endpoint address}" is the literal value of the bad url or an indication given by "suds" where it has found the bad url. In the first case, search the WSDL for "endpoint address" - and then get it fixed. In the second case, the bad value likely comes from the "location" attribute of a "soap:address" element below "wsdl:service" (again in your WSDL). Again, get it fixed, then. -- Dieter From vgnulinux at gmail.com Fri Mar 15 05:12:37 2013 From: vgnulinux at gmail.com (VGNU Linux) Date: Fri, 15 Mar 2013 14:42:37 +0530 Subject: Python SUDS issue In-Reply-To: References: <87d2vejoz7.fsf@handshake.de> Message-ID: Able to fix issue by including 'location' as parameter in client constructor arguments. client = Client(url=wsdlurl,doctor=schemadoctor, location=' https://46.51.221.138/PBExternalServices/v1/soap?wsdl') Thanks for helping me out. Regards, VGNU On Thu, Mar 7, 2013 at 10:07 AM, VGNU Linux wrote: > Hi Guys, > Not aware what "import" here is and what it will do. > But going through some google search result page found that there is > something called doctor in suds. > so tried changing code and it did fix the issue. > suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, > http://www.payback.net/lmsglobal/xsd/v1/types, )' > > Here is what i changed. > from suds.client import Client > from suds.xsd.doctor import Import, ImportDoctor > from suds.sax.element import Element > > wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' > schemaurl = 'http://www.payback.net/lmsglobal/xsd/v1/types' > schemaimport = Import(schemaurl) > schemadoctor = ImportDoctor(schemaimport) > client = Client(url=wsdlurl,doctor=schemadoctor) > print client > > Printing client now lists all the methods and types associated with the > service. > But again stuck as on executing a method > response = client.service.GetAccountBalance(authtype) > replies with the error. > ValueError: unknown url type: {endpoint address} > > Totally confused as what is wrong going on here. > > Appreciate your help. > Regards, > VGNU > > > On Tue, Mar 5, 2013 at 12:46 PM, dieter wrote: > >> VGNU Linux writes: >> >> > ... >> > Here is my code: >> > from suds.client import Client >> > wsdlurl = 'https://46.51.221.138/PBExternalServices/v1/soap?wsdl' >> > client = Client(wsdlurl) >> > print client >> > >> > And following is the error that occurs on trying to print client. >> > Traceback (most recent call last): >> > ... >> > dereference >> > midx, deps = x.dependencies() >> > File "C:\Python25\Lib\site-packages\suds\xsd\sxbasic.py", line 469, in >> > dependencies >> > raise TypeNotFound(self.ref) >> > suds.TypeNotFound: Type not found: '(GetAccountBalanceFaultResponse, >> > http://www.payback.net/lmsglobal/xsd/v1/types, )' >> >> Looks like a bug in the "WSDL" description of the web service. >> It seems to reference a type "GetAccountBalanceFaultResponse" >> associated with the namespace " >> http://www.payback.net/lmsglobal/xsd/v1/types", >> but "suds" cannot find the type. >> >> Maybe an "import" is missing in the "WSDL" description. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roshen.sethna at gmail.com Mon Mar 4 07:18:20 2013 From: roshen.sethna at gmail.com (newtopython) Date: Mon, 4 Mar 2013 04:18:20 -0800 (PST) Subject: Question on for loop Message-ID: Hi all, I'm super new to python, just fyi. In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values in the lettersGuessed list that aren't in secretWord. What this code is doing is only checking the first character of secretWord and then returning True or False. How do I get it to iterate through ALL of the characters of secretWord? for character in secretWord: if character not in lettersGuessed: return True return False Thanks! Ro From kirotawa at gmail.com Mon Mar 4 07:59:40 2013 From: kirotawa at gmail.com (leo kirotawa) Date: Mon, 4 Mar 2013 09:59:40 -0300 Subject: Question on for loop In-Reply-To: References: Message-ID: In fact this code is already doing what you want, but if the second character, by example, is not in secrectWord it'll jump out of the for and return. If you want that interact through the all characters and maybe count how many them are in the secrectWord, just take of the return there or do some list comprehension like: [ r for r in secrecWord if r in lettersGuessed] . []'s On Mon, Mar 4, 2013 at 9:18 AM, newtopython wrote: > Hi all, > > I'm super new to python, just fyi. > > In the piece of code below, secretWord is a string and lettersGuessed is a > list. I'm trying to find out if ALL the characters of secretWord are > included in lettersGuessed, even if there are additional values in the > lettersGuessed list that aren't in secretWord. > > What this code is doing is only checking the first character of secretWord > and then returning True or False. How do I get it to iterate through ALL of > the characters of secretWord? > > for character in secretWord: > if character not in lettersGuessed: > return True > return False > > Thanks! > > Ro > -- > http://mail.python.org/mailman/listinfo/python-list > -- Le?nidas S. Barbosa (Kirotawa) Engenheiro de Software - IBM (LTC - Linux Technology Center) MsC Sistemas e Computa??o Bacharel em Ci?ncias da Computa??o. blog nerd: corecode.wordpress.com/ User linux : #480879 "Mais s?bio ? aquele que sabe que n?o sabe" (S?crates) "smile and wave" - =D + o/ (Penguins of Madagascar) ????????? ??????????????. -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Mon Mar 4 08:04:58 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 4 Mar 2013 08:04:58 -0500 Subject: Question on for loop In-Reply-To: References: Message-ID: On Mon, Mar 4, 2013 at 7:18 AM, newtopython wrote: > Hi all, > > I'm super new to python, just fyi. > Welcome. Next time write a better subject line, and be sure the code you post is actually the code you are running. Provide the results you want and what you get. Provide the traceback if there is one > > In the piece of code below, secretWord is a string and lettersGuessed is a > list. I'm trying to find out if ALL the characters of secretWord are > included in lettersGuessed, even if there are additional values in the > lettersGuessed list that aren't in secretWord. > > What this code is doing is only checking the first character of secretWord > and then returning True or False. How do I get it to iterate through ALL of > the characters of secretWord? > > for character in secretWord: > if character not in lettersGuessed: > I am guessing that the next two lines are actually indented in your script so I am changing them here return True > return False > > The first time your if block is checked it will return True or False. Since you haven't shown this code in a function, as written it won't run at all. Your question makes no sense. What would it mean to look through each character and return True or False? What would make the result True? All matches, some matches? > Thanks! > > Ro > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Mar 4 08:36:45 2013 From: davea at davea.name (Dave Angel) Date: Mon, 04 Mar 2013 08:36:45 -0500 Subject: Question on for loop In-Reply-To: References: Message-ID: <5134A36D.7010606@davea.name> On 03/04/2013 07:18 AM, newtopython wrote: > Hi all, > > I'm super new to python, just fyi. Welcome to the Python list. > > In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values in the lettersGuessed list that aren't in secretWord. > > What this code is doing is only checking the first character of secretWord and then returning True or False. How do I get it to iterate through ALL of the characters of secretWord? > > for character in secretWord: > if character not in lettersGuessed: > return True > return False > Please post a complete sample when possible, and make sure you copy/paste it, not just retype it and hope. As written, it'll throw an exception when return is encountered. But before that, it'll complain about the indentation of the return True. Perhaps you have something like: def has_some_behavior(secretWord, lettersGuessed): for character in secretWord: if character not in lettersGuessed: return True return False If so, please copy the whole thing from your code, and explain just how you call it (what arguments are passed), what it returned, and what's wrong with that behavior. -- DaveA From bryan.devaney at gmail.com Mon Mar 4 09:34:13 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Mon, 4 Mar 2013 06:34:13 -0800 (PST) Subject: Question on for loop In-Reply-To: References: Message-ID: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> > if character not in lettersGuessed: > > return True > > return False assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work. It is however more work than is needed. If you made secretword a list,you could just set(secretword)&set(lettersguessed) and check the result is equal to secretword. From ian.g.kelly at gmail.com Mon Mar 4 11:37:11 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Mar 2013 09:37:11 -0700 Subject: Question on for loop In-Reply-To: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> References: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> Message-ID: On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney wrote: >> if character not in lettersGuessed: >> >> return True >> >> return False > > assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work. > > It is however more work than is needed. > > If you made secretword a list,you could just > > set(secretword)&set(lettersguessed) > > and check the result is equal to secretword. Check the result is equal to set(secretword), I think you mean. set(secretword).issubset(set(lettersguessed)) might be slightly more efficient, since it would not need to build and return an intersection set. One might also just do: all(letter in lettersguessed for letter in secretword) Which will be efficient if lettersguessed is already a set. From bryan.devaney at gmail.com Tue Mar 5 06:12:47 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Tue, 5 Mar 2013 03:12:47 -0800 (PST) Subject: Question on for loop In-Reply-To: References: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> Message-ID: On Monday, March 4, 2013 4:37:11 PM UTC, Ian wrote: > On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney wrote: > > >> if character not in lettersGuessed: > > >> > > >> return True > > >> > > >> return False > > > > > > assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work. > > > > > > It is however more work than is needed. > > > > > > If you made secretword a list,you could just > > > > > > set(secretword)&set(lettersguessed) > > > > > > and check the result is equal to secretword. > > > > Check the result is equal to set(secretword), I think you mean. > > > > set(secretword).issubset(set(lettersguessed)) > > > > might be slightly more efficient, since it would not need to build and > > return an intersection set. > > > > One might also just do: > > > > all(letter in lettersguessed for letter in secretword) > > > > Which will be efficient if lettersguessed is already a set. You are correct. sorry for the misleading answer, was digging through old shell scripts all day yesterday and brain was obviously not not the better for it. From bryan.devaney at gmail.com Tue Mar 5 06:12:47 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Tue, 5 Mar 2013 03:12:47 -0800 (PST) Subject: Question on for loop In-Reply-To: References: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> Message-ID: On Monday, March 4, 2013 4:37:11 PM UTC, Ian wrote: > On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney wrote: > > >> if character not in lettersGuessed: > > >> > > >> return True > > >> > > >> return False > > > > > > assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work. > > > > > > It is however more work than is needed. > > > > > > If you made secretword a list,you could just > > > > > > set(secretword)&set(lettersguessed) > > > > > > and check the result is equal to secretword. > > > > Check the result is equal to set(secretword), I think you mean. > > > > set(secretword).issubset(set(lettersguessed)) > > > > might be slightly more efficient, since it would not need to build and > > return an intersection set. > > > > One might also just do: > > > > all(letter in lettersguessed for letter in secretword) > > > > Which will be efficient if lettersguessed is already a set. You are correct. sorry for the misleading answer, was digging through old shell scripts all day yesterday and brain was obviously not not the better for it. From rantingrickjohnson at gmail.com Mon Mar 4 10:41:33 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Mar 2013 07:41:33 -0800 (PST) Subject: Question on for loop In-Reply-To: References: Message-ID: On Monday, March 4, 2013 6:18:20 AM UTC-6, newtopython wrote: [Note: Post has be logically re-arranged for your comprehensive pleasures] > for character in secretWord: > if character not in lettersGuessed: > return True > return False > > What this code is doing is only checking the first > character of secretWord and then returning True or False. > How do I get it to iterate through ALL of the characters > of secretWord? Your code is a fine example of: "attempting to solve too many problems at the same time". If you are having trouble understanding how to iterate over a sequence, then why would you complicate that learning experience by injecting other unsolved problems into the mix? First, solve the iteration problem. Then expand. ## START INTERACTIVE SESSION ## py> s = 'multiplicity' py> for char in s: ... print char m u l t i p l i c i t y ## END INTERACTIVE SESSION ## Now, we have a simple base from which to build! > In the piece of code [ABOVE], secretWord is a string and > lettersGuessed is a list. I'm trying to find out if ALL > the characters of secretWord are included in > lettersGuessed, even if there are additional values in the > lettersGuessed list that aren't in secretWord. First, step away from your interpreter! Now, grab a pen and paper and write down the steps required to compare two sequences in real life. 1. Create a list of "letters guessed" and a string representing the "secret word". secretWord = 'multiplicity' lettersGuessed = 'aeiouy' 2. For each letter in "secretWord", look in "lettersGuessed" and see if you can find the letter, then make a note of your findings. If the letter is in IN both sequences, write "[letter]=True", if not, write "[letter]=False". However, this algorithm is rather naive. What happens if one or both list contain the same letter numerous times (f.e. "multiplicity" has 3 "i" chars)? Do we want the user to provide a guess for all three "i" chars, or will just a single guess al la "price is right" will do the trick? Also, do we care about the "char order"? Or are we merely allowing the user to guess all the letters of the word in ANY order (that seems to be your intent here!)? In any event i am not going to just "gift wrap" and answer for you. There are many methods of solving this problem, some are elegant, some or not elegant, some use built-in functions, some use list comprehensions, and some could just use a for loop and a single built-in function. I would highly suggest that you figure this out using the latter. Until you can achieve this, forget about list comprehension or any advanced stuff. But most importantly: Build your code in small incremental steps and solve ONE issue at a time. This is the path of a wise problem solver. From ricaraoz at gmail.com Mon Mar 4 08:21:42 2013 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Mon, 04 Mar 2013 10:21:42 -0300 Subject: Question on for loop In-Reply-To: References: Message-ID: <51349FE6.8050700@gmail.com> El 04/03/13 09:18, newtopython escribi?: > Hi all, > > I'm super new to python, just fyi. > > In the piece of code below, secretWord is a string and lettersGuessed is a list. I'm trying to find out if ALL the characters of secretWord are included in lettersGuessed, even if there are additional values in the lettersGuessed list that aren't in secretWord. > > What this code is doing is only checking the first character of secretWord and then returning True or False. How do I get it to iterate through ALL of the characters of secretWord? > > for character in secretWord: > if character not in lettersGuessed: > return True > return False > > Thanks! > > Ro Indent the "return True" line so that it is inside the if clause. From tomas.kotal at gmail.com Mon Mar 4 09:31:41 2013 From: tomas.kotal at gmail.com (Tomas Kotal) Date: Mon, 4 Mar 2013 06:31:41 -0800 (PST) Subject: Different behavior with multiprocessing Message-ID: Hi all. Recently I discovered a strange behavior with multiprocessing library and call to function os.system (a different behavior under Linux and Windows to be more specific). I have this simple testing script: ############################################ import sys import os from multiprocessing import Process def do_fork(cmd): ret = os.system(cmd) # print result of call print ret os._exit(ret) if __name__ == "__main__": cmds = [ "dir", "xy" ] procs = [] for cmd in cmds: proc = Process(target=do_fork, args=(cmd, )) proc.start() procs.append( proc ) for proc in procs: proc.join() print "exitcode: %d" % proc.exitcode print "ok" ############################################ This script just starts 2 processes. Each process executes one command in system shell and exits setting it's exit code same as exit code of a system call. There are 2 commands: "dir" (which works fine on Windows and Linux) and "xy" (which is supposed to fail under both systems). The strange thing is that when I run this script under Windows I get this output: 0 1 exitcode: 0 exitcode: 1 ok The first 0 and 1 are results of os.system call which are printed from child processes. Rest of lines are printed from main process. This is expected output. But when I run same script on Linux, what I get is this: 0 32512 exitcode: 0 exitcode: 0 ok Although the second command fails and returns exit code 32512, the exit code from process in parent process gives me 0. I tried to change the script to use fork() instead of Process but the result was same. Can anybody explain me what's the problem here? (I use Python 2.6 on both Windows and Linux machines) From rosuav at gmail.com Mon Mar 4 09:58:54 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2013 01:58:54 +1100 Subject: Different behavior with multiprocessing In-Reply-To: References: Message-ID: On Tue, Mar 5, 2013 at 1:31 AM, Tomas Kotal wrote: > But when I run same script on Linux, what I get is this: > > 0 > 32512 Under Unix, the return value from os.system() encodes more than one piece of information: http://docs.python.org/2/library/os.html#os.system http://docs.python.org/2/library/os.html#os.wait 32512 is 127*256, meaning that the shell exited with return code 127 when given an unrecognized command. ChrisA From tomas.kotal at gmail.com Mon Mar 4 10:12:02 2013 From: tomas.kotal at gmail.com (Tomas Kotal) Date: Mon, 4 Mar 2013 07:12:02 -0800 (PST) Subject: Different behavior with multiprocessing In-Reply-To: References: Message-ID: > Under Unix, the return value from os.system() encodes more than one > > piece of information: > > > > http://docs.python.org/2/library/os.html#os.system > > http://docs.python.org/2/library/os.html#os.wait > > > > 32512 is 127*256, meaning that the shell exited with return code 127 > > when given an unrecognized command. > > > > ChrisA Well the point is not the difference between return values of os.system under Windows and Linux. The point is that I set the exist code of child process with os._exit() which works fine on Windows but on Linux the process.exitcode returns always 0. What is very strange is, that if I set return code to some other value, like: ... os._exit( len(cmd) ) ... Then I got exit codes 3 and 2 under Linux, which is correct. But when I do something like this: ... ret = os.system(cmd) print ret # this print real value, like 32512 os._exit(ret) # exitcode of this child process will be 0 on Linux ... It doesn't work, which seems very strange to me. From tomas.kotal at gmail.com Mon Mar 4 10:12:02 2013 From: tomas.kotal at gmail.com (Tomas Kotal) Date: Mon, 4 Mar 2013 07:12:02 -0800 (PST) Subject: Different behavior with multiprocessing In-Reply-To: References: Message-ID: > Under Unix, the return value from os.system() encodes more than one > > piece of information: > > > > http://docs.python.org/2/library/os.html#os.system > > http://docs.python.org/2/library/os.html#os.wait > > > > 32512 is 127*256, meaning that the shell exited with return code 127 > > when given an unrecognized command. > > > > ChrisA Well the point is not the difference between return values of os.system under Windows and Linux. The point is that I set the exist code of child process with os._exit() which works fine on Windows but on Linux the process.exitcode returns always 0. What is very strange is, that if I set return code to some other value, like: ... os._exit( len(cmd) ) ... Then I got exit codes 3 and 2 under Linux, which is correct. But when I do something like this: ... ret = os.system(cmd) print ret # this print real value, like 32512 os._exit(ret) # exitcode of this child process will be 0 on Linux ... It doesn't work, which seems very strange to me. From tomas.kotal at gmail.com Mon Mar 4 10:35:02 2013 From: tomas.kotal at gmail.com (Tomas Kotal) Date: Mon, 4 Mar 2013 07:35:02 -0800 (PST) Subject: Different behavior with multiprocessing In-Reply-To: References: Message-ID: Dne pond?l?, 4. b?ezna 2013 15:31:41 UTC+1 Tomas Kotal napsal(a): > Hi all. > > > > Recently I discovered a strange behavior with multiprocessing library and call to function os.system (a different behavior under Linux and Windows to be more specific). I have this simple testing script: > > > > ############################################ > > import sys > > import os > > from multiprocessing import Process > > > > def do_fork(cmd): > > ret = os.system(cmd) > > # print result of call > > print ret > > os._exit(ret) > > > > if __name__ == "__main__": > > cmds = [ "dir", "xy" ] > > > > procs = [] > > for cmd in cmds: > > proc = Process(target=do_fork, args=(cmd, )) > > proc.start() > > procs.append( proc ) > > > > for proc in procs: > > proc.join() > > print "exitcode: %d" % proc.exitcode > > > > print "ok" > > ############################################ > > > > This script just starts 2 processes. Each process executes one command in system shell and exits setting it's exit code same as exit code of a system call. There are 2 commands: "dir" (which works fine on Windows and Linux) and "xy" (which is supposed to fail under both systems). The strange thing is that when I run this script under Windows I get this output: > > > > 0 > > 1 > > exitcode: 0 > > exitcode: 1 > > ok > > > > The first 0 and 1 are results of os.system call which are printed from child processes. Rest of lines are printed from main process. This is expected output. > > > > But when I run same script on Linux, what I get is this: > > > > 0 > > 32512 > > exitcode: 0 > > exitcode: 0 > > ok > > > > Although the second command fails and returns exit code 32512, the exit code from process in parent process gives me 0. I tried to change the script to use fork() instead of Process but the result was same. > > > > Can anybody explain me what's the problem here? > > > > (I use Python 2.6 on both Windows and Linux machines) Seems like I found the problem: os._exit probably takes as parametr unsigned char, so it uses as error code whatever value it gets modulo 256: os._exit(1) # process.exitcode == 1 os._exit(255) # process.exitcode == 255 os._exit(256) # process.exitcode == 0 os._exit(257) # process.exitcode == 1 os._exit(32512) # process.exitcode == 0 So on Linux it's necesary to call something like this: os._exit( os.system(cmd) >> 8 ) Because the first byte of return value on Linux is number of signal which kills the process and the second one is actual exit code. http://docs.python.org/2/library/os.html#os.wait From rosuav at gmail.com Mon Mar 4 10:44:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2013 02:44:44 +1100 Subject: Different behavior with multiprocessing In-Reply-To: References: Message-ID: On Tue, Mar 5, 2013 at 2:35 AM, Tomas Kotal wrote: > Seems like I found the problem: os._exit probably takes as parametr unsigned char, so it uses as error code whatever value it gets modulo 256: > > os._exit(1) # process.exitcode == 1 > os._exit(255) # process.exitcode == 255 > os._exit(256) # process.exitcode == 0 > os._exit(257) # process.exitcode == 1 > os._exit(32512) # process.exitcode == 0 > > So on Linux it's necesary to call something like this: > os._exit( os.system(cmd) >> 8 ) > > Because the first byte of return value on Linux is number of signal which kills the process and the second one is actual exit code. Yep. I had a reply part-written but you beat me to it! That is indeed what you need if you want to chain return values. However, why are you using os._exit? Check out the note here: http://docs.python.org/2/library/os.html#os._exit ChrisA From sylvain.thenault at logilab.fr Mon Mar 4 10:11:42 2013 From: sylvain.thenault at logilab.fr (Sylvain =?utf-8?B?VGjDqW5hdWx0?=) Date: Mon, 4 Mar 2013 16:11:42 +0100 Subject: fixed broken links for the latest pylint/astng release Message-ID: <20130304151142.GL2512@logilab.fr> Hi there, last week I announced the latest and greatest pylint/astng release but didn't noticed at that time that the download links on our web site were broken, and that the upload to pypi failed. This is now fixed, for those who tried during the mean time. Sorry for the convenience, -- Sylvain Th?nault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42) Formations Python, Debian, M?th. Agiles: http://www.logilab.fr/formations D?veloppement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org From nikos.gr33k at gmail.com Mon Mar 4 10:14:00 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 4 Mar 2013 07:14:00 -0800 (PST) Subject: Embedding a for inside an html template for substitution Message-ID: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> Hello pythonistas! I'am tryign to populate a table with dictionary keys and values: Foe that iam using an html template and the questions is what i should write inside 'files.html' so then then the python script populate the table.
    SuperHost - Economy
    ????? ??? ?????: 1 GB
    ??????? ?????? ?????????: 1 GB
    Control Panel: cPanel 11 & Fantastico Deluxe
    Domains: 1
    Subdomains: 1
    FTP Accounts: 1
    Emails (POP3): 2
    WebMail: [ RoundCube|Horde|Squirrel ]: ???
    Mysql Databases: 2
    Instead of writing the above html data inside my html template how would i write it with a for that then will be substituted by the python script? can you please write an example for me that user "files.html" and gets populates by "files.py" ? i want os ee how it lloks like please! Thank you. From torriem at gmail.com Mon Mar 4 10:59:34 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 04 Mar 2013 08:59:34 -0700 Subject: Embedding a for inside an html template for substitution In-Reply-To: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> Message-ID: <5134C4E6.1080704@gmail.com> On 03/04/2013 08:14 AM, Ferrous Cranus wrote: > Instead of writing the above html data inside my html template how > would i write it with a for that then will be substituted by the > python script? What templating system are you using? Django's? > can you please write an example for me that user "files.html" and > gets populates by "files.py" ? If you're using a CGI script, just use a normal python for loop and print out the stuff you want using this kind of notation: for x in xrange(4): print "{0}".format(x) Another alternative is to make your own templating system. Have it load and parse the html file (maybe using one of the xml or html parsers), and substitude some sort of field marker for data. But that is re-inventing the wheel. http://wiki.python.org/moin/Templating From nikos.gr33k at gmail.com Mon Mar 4 12:22:38 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 4 Mar 2013 09:22:38 -0800 (PST) Subject: Embedding a for inside an html template for substitution In-Reply-To: References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> Message-ID: <6ce88927-ed2f-4045-a23c-033f18cb332a@googlegroups.com> ?? ???????, 4 ??????? 2013 5:59:34 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 03/04/2013 08:14 AM, Ferrous Cranus wrote: > > > Instead of writing the above html data inside my html template how > > > would i write it with a for that then will be substituted by the > > > python script? > > > > What templating system are you using? Django's? > > > > > can you please write an example for me that user "files.html" and > > > gets populates by "files.py" ? > > > > If you're using a CGI script, just use a normal python for loop and > > print out the stuff you want using this kind of notation: > > > > for x in xrange(4): > > print "{0}".format(x) > > > > > > Another alternative is to make your own templating system. Have it load > > and parse the html file (maybe using one of the xml or html parsers), > > and substitude some sort of field marker for data. But that is > > re-inventing the wheel. > > > > http://wiki.python.org/moin/Templating Firstly thank you for your answer, but iam a bit confised. can i just put the liens you provided me inside "files.html" and thwy will work? Thats pure pythjon code! for x in xrange(4): print "{0}".format(x) wont html complain? From nikos.gr33k at gmail.com Mon Mar 4 12:22:38 2013 From: nikos.gr33k at gmail.com (Ferrous Cranus) Date: Mon, 4 Mar 2013 09:22:38 -0800 (PST) Subject: Embedding a for inside an html template for substitution In-Reply-To: References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> Message-ID: <6ce88927-ed2f-4045-a23c-033f18cb332a@googlegroups.com> ?? ???????, 4 ??????? 2013 5:59:34 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 03/04/2013 08:14 AM, Ferrous Cranus wrote: > > > Instead of writing the above html data inside my html template how > > > would i write it with a for that then will be substituted by the > > > python script? > > > > What templating system are you using? Django's? > > > > > can you please write an example for me that user "files.html" and > > > gets populates by "files.py" ? > > > > If you're using a CGI script, just use a normal python for loop and > > print out the stuff you want using this kind of notation: > > > > for x in xrange(4): > > print "{0}".format(x) > > > > > > Another alternative is to make your own templating system. Have it load > > and parse the html file (maybe using one of the xml or html parsers), > > and substitude some sort of field marker for data. But that is > > re-inventing the wheel. > > > > http://wiki.python.org/moin/Templating Firstly thank you for your answer, but iam a bit confised. can i just put the liens you provided me inside "files.html" and thwy will work? Thats pure pythjon code! for x in xrange(4): print "{0}".format(x) wont html complain? From torriem at gmail.com Mon Mar 4 22:56:14 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 04 Mar 2013 20:56:14 -0700 Subject: Embedding a for inside an html template for substitution In-Reply-To: <5134FEB5.4090104@gmail.com> References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> <6ce88927-ed2f-4045-a23c-033f18cb332a@googlegroups.com> <5134FEB5.4090104@gmail.com> Message-ID: <51356CDE.6050706@gmail.com> On 03/04/2013 01:06 PM, Ferrous Cranus wrote: > What do you advise me to do? > Generate html via python code like print '''stuf......''' or use an > html templating system? > Up until now i was using the first method and i though it would be a > nice idea to seperate design from code. > > But please also provide me a simple example of 'files.html' and > 'files.py' so i can understand how does the templating system you > mentioned work. Was it Django?! Just generating html code is simple, but it does become a bit messy over time. Check out that link in my previous e-mail to a list of python templating engines. Choose one and try it. No I cannot provide any example code. I haven't used any of these systems; I'm just googling for you. Most of them come with examples anyway. Check out, among others: http://www.cheetahtemplate.org/docs/users_guide_html/ And actually this one uses cheetah to do static pages (not a full-blown web app): http://www.ivy.fr/tahchee/ I do recommend you at least take a look at Django. It may be overkill for your needs. It does contain a templating engine, but it also contains a whole lot more useful things for doing web-based applications. Here's the link in case you missed it: http://wiki.python.org/moin/Templating From r.koebler at yahoo.de Tue Mar 5 12:16:43 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Tue, 5 Mar 2013 18:16:43 +0100 Subject: Embedding a for inside an html template for substitution In-Reply-To: <51356CDE.6050706@gmail.com> References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> <6ce88927-ed2f-4045-a23c-033f18cb332a@googlegroups.com> <5134FEB5.4090104@gmail.com> <51356CDE.6050706@gmail.com> Message-ID: <20130305171642.GA12469@localhost> Hi, On Mon, Mar 04, 2013 at 09:22:38AM -0800, Ferrous Cranus wrote: > can i just put the liens you provided me inside "files.html" and thwy > will work? > > Thats pure pythjon code! There are several template-engines where you more or less include python-code into the template, e.g.: empy, mako, pyratemp On Mon, Mar 04, 2013 at 08:56:14PM -0700, Michael Torrie wrote: > Check out that link in my previous e-mail to a list of python templating > engines. Choose one and try it. No I cannot provide any example code. Here's an example for pyratemp (where I'm the author ;)): files.html:
    @!title!@
    @!e!@
    files.py: import pyratemp t = pyratemp.Template(filename="files.html") result = t(title="title ...", mylist=["entry 1", "entry 2", "entry 3"]) print result.encode("ascii", 'xmlcharrefreplace') On Mon, Mar 04, 2013 at 08:56:14PM -0700, Michael Torrie wrote: > I do recommend you at least take a look at Django. It may be overkill > for your needs. It does contain a templating engine, Last time I tried, the template-engine of Django did not work on its own. If you need Django-like templates without Django, you can use Jinja. And if you need a real sandbox (so that you can use untrusted templates), I would recommend Jinja. Roland From nagia.retsina at gmail.com Tue Mar 5 02:46:53 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Mon, 4 Mar 2013 23:46:53 -0800 (PST) Subject: Embedding a for inside an html template for substitution In-Reply-To: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> References: <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com> Message-ID: ?? ???????, 4 ??????? 2013 5:14:00 ?.?. UTC+2, ? ??????? ????? ???33? ??????: > Hello pythonistas! > > > > I'am tryign to populate a table with dictionary keys and values: > > > > Foe that iam using an html template and the questions is what i should write inside 'files.html' so then then the python script populate the table. > > > > > > > > > > > > > > > > > > > > > > > > > >
    SuperHost - Economy
    ????? ??? ?????: 1 GB
    ??????? ?????? ?????????: 1 GB
    Control Panel: cPanel 11 & Fantastico Deluxe
    Domains: 1
    Subdomains: 1
    FTP Accounts: 1
    Emails (POP3): 2
    WebMail: [ RoundCube|Horde|Squirrel ]: ???
    Mysql Databases: 2
    > > > > Instead of writing the above html data inside my html template how would i write it with a for that then will be substituted by the python script? > > > > can you please write an example for me that user "files.html" and gets populates by "files.py" ? > > > > i want os ee how it lloks like please! > > > > Thank you. Thank you Michael, i have decided to use cheetahtemplate. It seems nice and simple, djanfo indeed is an overkill for me needs. From ari.brandeis.king at gmail.com Mon Mar 4 13:22:07 2013 From: ari.brandeis.king at gmail.com (Ari King) Date: Mon, 4 Mar 2013 10:22:07 -0800 (PST) Subject: How to Nest Structs? Message-ID: Hi, I'm trying to nest the "info_header", "info_body", and "info_trailer" structs (see below) into a "data_packet" struct. Does anyone know how I can/should accomplish this? Thanks. batch_header_format = struct.Struct('!c2h') info_header_format = struct.Struct('!2hl') mkt_status_format = struct.Struct('!c') info_trailer_format = struct.Struct('!hc') mkt_session_codes = [b'PO',b'PC',b'CO',b'CC',b'CK',b'CL'] mkt_type = [b'N',b'S',b'O',b'A',b'C',b'G'] batch_header = batch_header_format.pack(b'1',1,1024) total_size = info_header_format.size + mkt_status_format.size + info_trailer_format.size # Combine following into data struct. info_header = info_header_format.pack(int(binascii.hexlify(mkt_session_codes[random.randint(0,5)])), total_size, 124) info_body = mkt_status_format.pack(mkt_type[random.randint(0,5)]) info_trailer = info_trailer_format.pack(0, b'\r') -Ari From web at cjhanks.name Mon Mar 4 17:29:01 2013 From: web at cjhanks.name (web at cjhanks.name) Date: Mon, 4 Mar 2013 14:29:01 -0800 (PST) Subject: How to Nest Structs? In-Reply-To: References: Message-ID: Try unpacking the nested struct as a fixed width string and then unpacking the string. Then unpack the string On Monday, March 4, 2013 10:22:07 AM UTC-8, Ari King wrote: > Hi, > > > > I'm trying to nest the "info_header", "info_body", and "info_trailer" structs (see below) into a "data_packet" struct. Does anyone know how I can/should accomplish this? Thanks. > > > > batch_header_format = struct.Struct('!c2h') > > info_header_format = struct.Struct('!2hl') > > mkt_status_format = struct.Struct('!c') > > info_trailer_format = struct.Struct('!hc') > > > > mkt_session_codes = [b'PO',b'PC',b'CO',b'CC',b'CK',b'CL'] > > mkt_type = [b'N',b'S',b'O',b'A',b'C',b'G'] > > > > batch_header = batch_header_format.pack(b'1',1,1024) > > > > total_size = info_header_format.size + mkt_status_format.size + info_trailer_format.size > > > > # Combine following into data struct. > > info_header = info_header_format.pack(int(binascii.hexlify(mkt_session_codes[random.randint(0,5)])), total_size, 124) > > info_body = mkt_status_format.pack(mkt_type[random.randint(0,5)]) > > info_trailer = info_trailer_format.pack(0, b'\r') > > > > -Ari From p at google-groups-2013.dobrogost.net Mon Mar 4 13:54:19 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Mon, 4 Mar 2013 10:54:19 -0800 (PST) Subject: How to create a temporary file that can be read by a subprocess? Message-ID: <1237033c-1428-4dfe-8760-0183f24ff9af@googlegroups.com> I've just read this interesting question titled "How to create a temporary file that can be read by a subprocess?" (http://stackoverflow.com/q/15169101/95735). Provided there is a method to make _named_ temporary file being readable by other processes on Windows, the CPython implementation should do just this, no? Right now it doesn't. What do you think? From maroso at libero.it Mon Mar 4 14:06:57 2013 From: maroso at libero.it (io) Date: 04 Mar 2013 19:06:57 GMT Subject: Python script not working on windows 7 but works fine on linux Message-ID: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> The following scripts are working fine on linux but, using the same version, can't work on windows because i receive the following message: Script: import json import urllib import csv url = "http://bitcoincharts.com/t/markets.json" response = urllib.urlopen(url); data = json.loads(response.read()) f = open("/home/io/btc_trading/markets.csv","wb") c = csv.writer(f) #apre un file di testo e legge il contenuto del file inserendolo in una stringa esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r') esclusioni = [] for line in esclusioni_file: esclusioni.append(line.strip()) #print(esclusioni) # write headers c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"]) for d in data : if d["currency"] <> "SLL": #esclude la valuta di secondlife SLL if d["bid"] is not None and d["ask"] is not None: if d["symbol"] not in esclusioni: #print d["symbol"] c.writerow([str(d["currency"]),str(d["symbol"]),str(d ["bid"]),str(d["ask"]),str(d["currency_volume"])]) #esclusioni.close() Windows error : Traceback (most recent call last): File "C:\btc_trading\scripts \import_json_2_csv_from_web_and_exclusions.py", line 10, in f = open("/home/io/btc_trading/markets.csv","wb") IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/ markets.csv' >>> From iandouglas736 at gmail.com Mon Mar 4 14:20:28 2013 From: iandouglas736 at gmail.com (ian douglas) Date: Mon, 04 Mar 2013 11:20:28 -0800 Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <5134F3FC.3020708@gmail.com> On 03/04/2013 11:06 AM, io wrote: > esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r') > > Windows error : > > Traceback (most recent call last): > File "C:\btc_trading\scripts > \import_json_2_csv_from_web_and_exclusions.py", line 10, in > f = open("/home/io/btc_trading/markets.csv","wb") > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/ > markets.csv' The error tells you everything you need to know: the file system has no path/file called "/home/io/btc_trading/markets.csv" I imagine your CSV file lives in a different location on your Windows 7 system (which also uses back-slashes '\' instead of forward-slashes '/', so you'll need to maybe do a try/except around the open() call to open a Windows path like open("c:\\users\\io\\Documents\\markets.csv") or whatever. OR you'll need to do some OS detection ahead of time to set the file path properly. From tjreedy at udel.edu Mon Mar 4 16:19:45 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Mar 2013 16:19:45 -0500 Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: <5134F3FC.3020708@gmail.com> References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> <5134F3FC.3020708@gmail.com> Message-ID: On 3/4/2013 2:20 PM, ian douglas wrote: > I imagine your CSV file lives in a different location on your Windows 7 > system (which also uses back-slashes '\' instead of forward-slashes '/', Forward slashes work fine on Windows except for invoking the executable at a Command Prompt command line, where '/' marks an option. >>> open('/programs/python33/python.exe') <_io.TextIOWrapper name='/programs/python33/python.exe' mode='r' encoding='cp1252'> -- Terry Jan Reedy From auriocus at gmx.de Mon Mar 4 14:20:35 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 04 Mar 2013 20:20:35 +0100 Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: Am 04.03.13 20:06, schrieb io: > The following scripts are working fine on linux but, using the same > version, can't work on windows because i receive the following message: > snip > f = open("/home/io/btc_trading/markets.csv","wb") > Windows error : > > Traceback (most recent call last): > File "C:\btc_trading\scripts > \import_json_2_csv_from_web_and_exclusions.py", line 10, in > f = open("/home/io/btc_trading/markets.csv","wb") > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/ > markets.csv' >>>> Are you actually reading that error message? You have an absolute path in script! This /home/io... would something like C:/btc_trading/... on Windows. This is not a Python question, it is a Linux/Windows question. Ask your local IT guy. Christian From maroso at libero.it Mon Mar 4 14:58:41 2013 From: maroso at libero.it (io) Date: 04 Mar 2013 19:58:41 GMT Subject: Python script not working on windows 7 but works fine on linux References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <5134fcf1$0$40360$4fafbaef@reader1.news.tin.it> Thanks, .... btw ...i'm the IT guy! I was missing the double slash as dougas suggested!++Thanks anyway. From news4 at mystrobl.de Mon Mar 4 14:30:13 2013 From: news4 at mystrobl.de (Wolfgang Strobl) Date: Mon, 04 Mar 2013 20:30:13 +0100 Subject: Python script not working on windows 7 but works fine on linux References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <5et9j855qil8rv1sc518fcqmdlubef18sf@4ax.com> io : >The following scripts are working fine on linux but, using the same >version, can't work on windows because i receive the following message: Thats because there is No such file or directory: '/home/io/btc_trading/ on that Windows PC. -- Wir danken f?r die Beachtung aller Sicherheitsbestimmungen From maroso at libero.it Mon Mar 4 14:59:49 2013 From: maroso at libero.it (io) Date: 04 Mar 2013 19:59:49 GMT Subject: Python script not working on windows 7 but works fine on linux References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <5134fd35$0$40360$4fafbaef@reader1.news.tin.it> Genius! The code i posted was an example. My real code was c:\btc_trading .... i was just missing the double slashes! Thanks , thankyou very much. :-) From rosuav at gmail.com Mon Mar 4 15:56:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2013 07:56:27 +1100 Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: <5134fd35$0$40360$4fafbaef@reader1.news.tin.it> References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> <5134fd35$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: On Tue, Mar 5, 2013 at 6:59 AM, io wrote: > Genius! > > The code i posted was an example. > My real code was c:\btc_trading .... > > i was just missing the double slashes! > > Thanks , thankyou very much. > > :-) Even on Windows, you can use / as a directory separator. This generally saves you the trouble of switching to \\ for everything; though still, absolute paths are often wrong. But at least you can use relative paths safely! ChrisA From steve+comp.lang.python at pearwood.info Mon Mar 4 20:58:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Mar 2013 01:58:42 GMT Subject: Python script not working on windows 7 but works fine on linux References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: <51355152$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 04 Mar 2013 11:20:28 -0800, ian douglas wrote: > The error tells you everything you need to know: the file system has no > path/file called "/home/io/btc_trading/markets.csv" > > I imagine your CSV file lives in a different location on your Windows 7 > system (which also uses back-slashes '\' instead of forward-slashes '/', Windows understands forward slashes in paths too. You can make your code (almost) platform-independent, and avoid a lot of problems with unescaped backslashes, by always using forward slashes in paths. -- Steven From bahamutzero8825 at gmail.com Mon Mar 4 21:25:44 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 04 Mar 2013 20:25:44 -0600 Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: <51355152$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> <51355152$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513557A8.809@gmail.com> On 2013.03.04 19:58, Steven D'Aprano wrote: > Windows understands forward slashes in paths too. You can make your code > (almost) platform-independent, and avoid a lot of problems with unescaped > backslashes, by always using forward slashes in paths. Or use os.path.join, the entire purpose of which is to create suitable paths dynamically. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From dihedral88888 at googlemail.com Mon Mar 4 21:58:58 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 4 Mar 2013 18:58:58 -0800 (PST) Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: On Tuesday, March 5, 2013 3:20:28 AM UTC+8, ian douglas wrote: > On 03/04/2013 11:06 AM, io wrote: > > > esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r') > > > > > > Windows error : > > > > > > Traceback (most recent call last): > > > File "C:\btc_trading\scripts > > > \import_json_2_csv_from_web_and_exclusions.py", line 10, in > > > f = open("/home/io/btc_trading/markets.csv","wb") > > > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/ > > > markets.csv' > > > > The error tells you everything you need to know: the file system has no > > path/file called "/home/io/btc_trading/markets.csv" > > > > I imagine your CSV file lives in a different location on your Windows 7 > > system (which also uses back-slashes '\' instead of forward-slashes '/', > > so you'll need to maybe do a try/except around the open() call to open a > > Windows path like open("c:\\users\\io\\Documents\\markets.csv") or > > whatever. OR you'll need to do some OS detection ahead of time to set > > the file path properly. Well, I'll suggest an old trick I did long time ago to resolve the platform dependent problem in python. Just write a generator as a buffered input method to work under some file of some OS correctly first, then you can pass the generator which is tested rigorously to act properly in the function or the object which will use the generator to sip up the data to perform jobs. From dihedral88888 at googlemail.com Mon Mar 4 21:58:58 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 4 Mar 2013 18:58:58 -0800 (PST) Subject: Python script not working on windows 7 but works fine on linux In-Reply-To: References: <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> Message-ID: On Tuesday, March 5, 2013 3:20:28 AM UTC+8, ian douglas wrote: > On 03/04/2013 11:06 AM, io wrote: > > > esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r') > > > > > > Windows error : > > > > > > Traceback (most recent call last): > > > File "C:\btc_trading\scripts > > > \import_json_2_csv_from_web_and_exclusions.py", line 10, in > > > f = open("/home/io/btc_trading/markets.csv","wb") > > > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/ > > > markets.csv' > > > > The error tells you everything you need to know: the file system has no > > path/file called "/home/io/btc_trading/markets.csv" > > > > I imagine your CSV file lives in a different location on your Windows 7 > > system (which also uses back-slashes '\' instead of forward-slashes '/', > > so you'll need to maybe do a try/except around the open() call to open a > > Windows path like open("c:\\users\\io\\Documents\\markets.csv") or > > whatever. OR you'll need to do some OS detection ahead of time to set > > the file path properly. Well, I'll suggest an old trick I did long time ago to resolve the platform dependent problem in python. Just write a generator as a buffered input method to work under some file of some OS correctly first, then you can pass the generator which is tested rigorously to act properly in the function or the object which will use the generator to sip up the data to perform jobs. From hossamalagmy at gmail.com Mon Mar 4 17:35:56 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Mon, 4 Mar 2013 14:35:56 -0800 (PST) Subject: =?windows-1256?B?3e3TIMjm3yBmYWNlYm9vaw==?= Message-ID: ??? ??? facebook https://www.facebook.com/pages/%D9%86%D8%AA%D8%A7%D8%A6%D8%AC-%D8%A7%D9%84%D8%A7%D9%85%D8%AA%D8%AD%D8%A7%D9%86%D8%A7%D8%AA-%D9%88%D8%A7%D9%84%D8%AC%D8%A7%D9%85%D8%B9%D8%A7%D8%AA-%D9%88%D8%A7%D8%AC%D8%AA%D9%85%D8%A7%D8%B9%D9%8A%D8%A7%D8%AA/299719160065550?ref=hl From waveclaira at gmail.com Mon Mar 4 22:40:46 2013 From: waveclaira at gmail.com (Claira) Date: Mon, 4 Mar 2013 21:40:46 -0600 Subject: ** UPDATE ** ~ The Perfect Guide To Actionable Programming & Thank You ~ Message-ID: Thanks for the few answers, though those few were very Helpful. The problem was that some people (even after 4 or more years of university), especially including almost all beginners, do not know how to start building something that does something helpful for soceity and everyone around them -- and this is yet to be resolved. I read a whole bunch of reviews of the learning resources I linked to last month. Here's one I Love -- "There should be exaggerated claims of ultimate learning outcomes without evidence"[1] My response, attached with the answers below for reference: When wonderful talents do things like kickstarter.com/projects/1369857650/real-python-for-web-development-featuring-web2py-- I wonder about what is even more significant -- "Is it effective? Does it solve the problem?" When I (and others far newer than me) have a serious problem like this, you know, we care very much for accurate and reliable data. When people say "Learn Python the Hardway is probably the best resource you listed.. [and] you *will *learn the material.." when clearly it doesn't meet standards: "I have seeen plenty of stackoverflow and student questions about it. In short, it's horrible." I start to wonder about the reliability of their judgement, and how partial they really are. Even if "A friend of mine wrote the course" is not factor we care about. Maybe hardway was the highest Quality resource out of those (I personally liked the MIT videos from what I've seen). So maybe, but best in the room with a low ceiling isn't very good. I try really really hard not to touch objects of low quality (<4.9 stars) http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106 I've been trying to learn programming for 8 years, so I'm a great canidiate. So Michael, I would gladly give you any feedback on the usability of your product anytime you ask :) [1] http://blog.oreillyschool.com/2011/12/my-thoughts-on-codecademy.html On Thu, Feb 21, 2013 at 11:32 AM, Philipp Hagemeister wrote: > > http://learnpythonthehardway.org/book/ > I have never used that myself, but I have seeen plenty of stackoverflow > and student questions about it. In short, it's horrible. > > The book mostly consists of basic Python programs, and beginners often > fail to grasp even the most basic structures demonstrated, mainly > because they're not explained. The book has some of the easy-to-approach > informality of, say, the Head First ones, but fails to contain the the > actual explanations for it. > > (And I have no idea why one would start with Python 2.x, given that > everything's strange in there - instead of relying on the intuitive > grasp that both "a" and "?" are single character strings, and that print > is a function like any other, they have to work with a lot of magic and > hand-waving) > > - Philipp > On Thu, Feb 21, 2013 at 11:10 AM, Mark Janssen wrote: > Sorry, I gave you the wrong book (a different Lutz book). The correct > title is _Programming Python_, by Mark Lutz. It's like 1600 pages and > is application focused. > > Cheers! > mark > On Thu, Feb 21, 2013 at 7:40 AM, Michael Herman wrote: > Hi Claira, > > I understand how hard it can be. Learn Python the Hardway is probably the > best resource you listed. It's a bit unorganized, but you *will *learn > the material if you go through all the exercises and homework problems. > > That said, the author does dive into some areas that are not really > necessary for beginners, which is a problem with most Python books. Check > out http://www.realpython.com/. It's one of the best resources out there. > A friend of mine wrote the course. Right now, I am in the process of > writing a companion course called Real Python for the Web, where you learn > how to develop websites. So, you would start with the first course to learn > the syntax and then you could move onto the second course to learn web > development. > > The Kickstarter is live for the second course - http://kck.st/VQj8hq > > There is a special right now where you can get both courses for $25 on the > Kickstarter. Plus, once I hit $15k, which should be in the next few days, I > will hit a stretch goal for making video tutorials for the first course. > > Anyway, sorry to plug my product - but I feel your pain, which is why Real > Python was developed in the first place: Less syntax and theory, more > coding and learning. Learning by doing. > > Let me know if you have any more questions. > > Best, > > Michael > > On Thu, Feb 21, 2013 at 2:08 AM, Claira wrote: > >> The problem: I've done reading (like on quora), and it seems lots of >> beginners (and I know first-hand for me), and even for those that have done >> 4 years at university -- that they say they don't know how to build >> something after all the theory and stuff. Even though I'm not going to be a >> programmer, in the future, there may be something that would need >> programming, so learning what's needed is a good thing. For example, I >> thought you could just wave leapmotion.com and it just works, but it's >> still 2013. On quora, they say that you need to code for it to actually do >> things. Could someone who is good at it rank these sources (or provide a >> good one) on how well they solve the problem? >> >> http://learnpythonthehardway.org/book/ >> http://girldevelopit.com/materials >> https://developers.google.com/edu/python/ >> https://www.edx.org/courses/BerkeleyX/CS169.1x/ >> https://www.udacity.com/course/cs101 >> https://www.udacity.com/course/cs262 >> http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/ >> https://www.khanacademy.org/cs/tutorials/programming-basics >> http://www.codecademy.com/tracks/python >> http://www.learnpython.org >> >> I got rid of a whole bunch that I thought were really really bad like >> http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6 >> >> Really bored really fast. I'm not sure what helpful things I'll like to >> build anymore ='( >> >> I'm not subscribed to the list anymore (can't keep up with it, and don't >> understand anything). Please cc me :) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fruiz at twitter.com Tue Mar 5 01:48:51 2013 From: fruiz at twitter.com (Lowly Minion) Date: Mon, 4 Mar 2013 22:48:51 -0800 (PST) Subject: Pythonic way for retrieving value for a nested dictionary. Message-ID: <4a0888ba-396b-4b6e-af3e-7560962d6750@googlegroups.com> For a typical dict: i.e. d = { '1': 'a', '2', 'b' } I might use something like: d.get('1', None) To get the value of 1. What would be the most pythonic way of getting a nested value of a dictionary within a list: some_list = [{ 'item': { 'letter': 'b', 'word': 'bar' }}, { 'item': { 'letter': 'c', 'word': 'charcoal' }}] Currently I am looping through the list as such: for item in some_list: print item['item']['letter'] One other method explored was: item.get('item').get('letter') Is a double get the best way? Doesn't seem right to me. Thank you in advance for your help From davea at davea.name Tue Mar 5 02:20:51 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 02:20:51 -0500 Subject: Pythonic way for retrieving value for a nested dictionary. In-Reply-To: <4a0888ba-396b-4b6e-af3e-7560962d6750@googlegroups.com> References: <4a0888ba-396b-4b6e-af3e-7560962d6750@googlegroups.com> Message-ID: <51359CD3.7090107@davea.name> On 03/05/2013 01:48 AM, Lowly Minion wrote: > For a typical dict: > > i.e. > d = { '1': 'a', '2', 'b' } > > I might use something like: > > d.get('1', None) > > To get the value of 1. > > What would be the most pythonic way of getting a nested value of a dictionary within a list: > > some_list = [{ 'item': { 'letter': 'b', > 'word': 'bar' }}, > { 'item': { 'letter': 'c', > 'word': 'charcoal' }}] > > Currently I am looping through the list as such: > > for item in some_list: > print item['item']['letter'] > > One other method explored was: > item.get('item').get('letter') > > Is a double get the best way? Doesn't seem right to me. > > Thank you in advance for your help > I'm not sure what the puzzle is. Use [key] if you know the key exists, and use get( key, default) if you don't. But be aware that if the first key doesn't exist, then the default had better be a dict (rather than something like None), or the second lookup will throw an exception, even if you use get. One other possibility, depending on just what you're doing with the data, is to wrap it in a try/catch. However, if you know exactly what the keys are, perhaps you should use a namedtuple instead of a dict. -- DaveA From nikos.gr33k at gmail.com Tue Mar 5 04:00:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 01:00:00 -0800 (PST) Subject: Downloading a file form a displayed table Message-ID: # ================================================================================================================= # display download button for each file and downlaod it on click # ================================================================================================================= if form.getvalue('show') == 'files': print ( "

    " ) print ( "" ) path = "/data/files/" for filename in os.walk(path): print ''' print( "" ) % filename ''' sys.exit(0) ======================== I use the above code to tidplay a filenames table so the user cna download a displayed button style lookign file but its not printing anything for me just an emptry table '/data/files' has 5 files in it but its not showing any. I dont see what iam doign wrong From davea at davea.name Tue Mar 5 04:45:09 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 04:45:09 -0500 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: <5135BEA5.902@davea.name> On 03/05/2013 04:00 AM, ????? ???33? wrote: > # ================================================================================================================= > # display download button for each file and downlaod it on click > # ================================================================================================================= > if form.getvalue('show') == 'files': > > print ( "

    " ) > print ( "
    " ) > > path = "/data/files/" > > for filename in os.walk(path): > print ''' > > print( "" ) % filename > > ''' > > sys.exit(0) > > ======================== > > I use the above code to tidplay a filenames table so the user cna download a displayed button style lookign file but its not printing anything for me just an emptry table > > '/data/files' has 5 files in it but its not showing any. > I dont see what iam doign wrong > It would be useful to actually specifying the context of this fragment of code. Presumably it's running on a web server somewhere, and you're expecting the filenames to somehow show up on a browser. Which OS and which version of Python for that server, and what brand and version of browser? Have you considered closing the table, and ending the body of the page? Have you looked at the result with View->Source in your browser? -- DaveA From nikos.gr33k at gmail.com Tue Mar 5 04:48:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 01:48:47 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: ?? ?????, 5 ??????? 2013 11:45:09 ?.?. UTC+2, ? ??????? Dave Angel ??????: > It would be useful to actually specifying the context of this fragment > > of code. Presumably it's running on a web server somewhere, and you're > > expecting the filenames to somehow show up on a browser. Which OS and > > which version of Python for that server, and what brand and version of > > browser? > > > > Have you considered closing the table, and ending the body of the page? The server run Linux and python version is v2.7 and the browser is Chrome v27 The source appears empty. Frankly i dont see anythign wrong with my code: path = "/data/files/" for filename in os.walk(path): print '''
    ''' % (filename, filename) sys.exit(0) From nikos.gr33k at gmail.com Tue Mar 5 04:48:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 01:48:47 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: ?? ?????, 5 ??????? 2013 11:45:09 ?.?. UTC+2, ? ??????? Dave Angel ??????: > It would be useful to actually specifying the context of this fragment > > of code. Presumably it's running on a web server somewhere, and you're > > expecting the filenames to somehow show up on a browser. Which OS and > > which version of Python for that server, and what brand and version of > > browser? > > > > Have you considered closing the table, and ending the body of the page? The server run Linux and python version is v2.7 and the browser is Chrome v27 The source appears empty. Frankly i dont see anythign wrong with my code: path = "/data/files/" for filename in os.walk(path): print '''
    ''' % (filename, filename) sys.exit(0) From davea at davea.name Tue Mar 5 05:05:00 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 05:05:00 -0500 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: <5135C34C.8060304@davea.name> On 03/05/2013 04:48 AM, ????? ???33? wrote: > ?? ?????, 5 ??????? 2013 11:45:09 ?.?. UTC+2, ? ??????? Dave Angel ??????: > >> It would be useful to actually specifying the context of this fragment >> >> of code. Presumably it's running on a web server somewhere, and you're >> >> expecting the filenames to somehow show up on a browser. Which OS and >> >> which version of Python for that server, and what brand and version of >> >> browser? >> >> >> >> Have you considered closing the table, and ending the body of the page? > > The server run Linux and python version is v2.7 and the browser is Chrome v27 > > The source appears empty. In that case, there's something wrong far outside of this code fragment. A web page (html) has lots of required elements which were presumably in other parts of the script that are not shown here. > > Frankly i dont see anythign wrong with my code: > > path = "/data/files/" > > for filename in os.walk(path): > print ''' >
    >
    > > ''' % (filename, filename) > > sys.exit(0) > -- DaveA From davea at davea.name Tue Mar 5 04:51:41 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 04:51:41 -0500 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: <5135C02D.2070008@davea.name> On 03/05/2013 04:00 AM, ????? ???33? wrote: > > > for filename in os.walk(path): But os.walk() doesn't return a filename. It returns a tuple. Have you tested any of this code outside of a server? Also, you're using tabs here. They don't show up in most email programs, so you're better off replacing them with an appropriate number of spaces. After all, indentation matters. > print ''' >
    > print( "
    " ) % filename > > ''' > > sys.exit(0) > -- DaveA From nikos.gr33k at gmail.com Tue Mar 5 05:24:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 02:24:11 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: <91d6d661-1e6b-4365-8fa3-e46425705d78@googlegroups.com> ?? ?????, 5 ??????? 2013 11:51:41 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 03/05/2013 04:00 AM, ????? ???33? wrote: > > > > > > > > > > > for filename in os.walk(path): > > > > But os.walk() doesn't return a filename. It returns a tuple. Have you > > tested any of this code outside of a server? > > > > Also, you're using tabs here. They don't show up in most email > > programs, so you're better off replacing them with an appropriate number > > of spaces. After all, indentation matters. > > > > > > > print ''' > > >
    > > > print( "
    " ) % filename > > > > > > ''' > > > > > > sys.exit(0) > > > > > -- > > DaveA How is this lien supposed to be written do to iterate over a list of filenames? for filename in list( os.walk(path) ): i tried the above but still it doesn't work out. From lele at metapensiero.it Tue Mar 5 06:29:25 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 05 Mar 2013 12:29:25 +0100 Subject: Downloading a file form a displayed table References: <91d6d661-1e6b-4365-8fa3-e46425705d78@googlegroups.com> Message-ID: <87vc96kru2.fsf@nautilus.nautilus> ????? ???33? writes: > How is this lien supposed to be written do to iterate over a list of filenames? > > for filename in list( os.walk(path) ): > > i tried the above but still it doesn't work out. Please learn how Python itself can help you: $ python Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> help(os.walk) Help on function walk in module os: walk(top, topdown=True, onerror=None, followlinks=False) Directory tree generator. ... Example: import os from os.path import join, getsize for root, dirs, files in os.walk('python/Lib/email'): ... In general, the builtin help() function displays the documentation for either a single function or a whole module. 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 nikos.gr33k at gmail.com Tue Mar 5 05:24:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 02:24:11 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: <91d6d661-1e6b-4365-8fa3-e46425705d78@googlegroups.com> ?? ?????, 5 ??????? 2013 11:51:41 ?.?. UTC+2, ? ??????? Dave Angel ??????: > On 03/05/2013 04:00 AM, ????? ???33? wrote: > > > > > > > > > > > for filename in os.walk(path): > > > > But os.walk() doesn't return a filename. It returns a tuple. Have you > > tested any of this code outside of a server? > > > > Also, you're using tabs here. They don't show up in most email > > programs, so you're better off replacing them with an appropriate number > > of spaces. After all, indentation matters. > > > > > > > print ''' > > >
    > > > print( "
    " ) % filename > > > > > > ''' > > > > > > sys.exit(0) > > > > > -- > > DaveA How is this lien supposed to be written do to iterate over a list of filenames? for filename in list( os.walk(path) ): i tried the above but still it doesn't work out. From nikos.gr33k at gmail.com Tue Mar 5 08:01:19 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 05:01:19 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: Please help me correct thois code, iam tryign ti for hours and i cant seem to get it working....it irritates me.... path = "/home/nikos/public_html/data/files/" for filename in os.walk(path): try: #find the needed counter for the page URL cur.execute('''SELECT ID FROM files WHERE URL = %s''', (filename,) ) data = cur.fetchone() #URL is unique, so should only be one if not data: #first time for page; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (URL, lastvisit) VALUES (%s, %s)''', (filename, date) ) cID = cur.lastrowid #get the primary key value of the new record else: #found the page, save primary key and use it to issue hit UPDATE cID = data[0] cur.execute('''UPDATE files SET hits = hits + 1, lastvisit = %s WHERE ID = %s''', (date, cID) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) From joel.goldstick at gmail.com Tue Mar 5 08:38:28 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Mar 2013 08:38:28 -0500 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: On Tue, Mar 5, 2013 at 8:01 AM, ????? ???33? wrote: > Please help me correct thois code, iam tryign ti for hours and i cant seem > to get it working....it irritates me.... > There is no question here. No indication of what isn't working as you like. No traceback. > > path = "/home/nikos/public_html/data/files/" > for filename in os.walk(path): > try: > #find the needed counter for the page URL > cur.execute('''SELECT ID FROM files WHERE URL = %s''', > (filename,) ) > data = cur.fetchone() #URL is unique, so should > only be one > > if not data: > #first time for page; primary key is automatic, > hit is defaulted > cur.execute('''INSERT INTO files (URL, lastvisit) > VALUES (%s, %s)''', (filename, date) ) > cID = cur.lastrowid #get the primary key > value of the new record > else: > #found the page, save primary key and use it to > issue hit UPDATE > cID = data[0] > cur.execute('''UPDATE files SET hits = hits + 1, > lastvisit = %s WHERE ID = %s''', (date, cID) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vytasd2013 at gmail.com Tue Mar 5 08:38:49 2013 From: vytasd2013 at gmail.com (Vytas D.) Date: Tue, 5 Mar 2013 13:38:49 +0000 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: Hi, It is really complicated to reproduce the errors you get by running your code since it involves database queries. Though one thing that really needs your attention is how you handle the results from os.walk(path). Dave Angel told you already that: "But os.walk() doesn't return a filename. It returns a tuple.". To show where you are wrong I have create the directory structure: Folder "folder1" that has files "file4.txt" and "file3.txt" inside. In Python 2.6.5: >>> import os >>> for filename in os.walk('folder1'): ... print(filename) ... ('folder1', [], ['file4.txt', 'file3.txt']) >>> So your code is treating results from os.walk() incorrectly. You get tuple, so extract data you need from it first. In case you don't know how: Print files only (no directories. Adapt code to your needs): >>> for result in os.walk('folder1'): ... for filename in result[2]: ... print(filename) ... file4.txt file3.txt In http://docs.python.org/2/library/os.html you will find: os.walk(top, topdown=True, onerror=None, followlinks=False) Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames). ... Vytas On Tue, Mar 5, 2013 at 1:01 PM, ????? ???33? wrote: > Please help me correct thois code, iam tryign ti for hours and i cant seem > to get it working....it irritates me.... > > path = "/home/nikos/public_html/data/files/" > for filename in os.walk(path): > try: > #find the needed counter for the page URL > cur.execute('''SELECT ID FROM files WHERE URL = %s''', > (filename,) ) > data = cur.fetchone() #URL is unique, so should > only be one > > if not data: > #first time for page; primary key is automatic, > hit is defaulted > cur.execute('''INSERT INTO files (URL, lastvisit) > VALUES (%s, %s)''', (filename, date) ) > cID = cur.lastrowid #get the primary key > value of the new record > else: > #found the page, save primary key and use it to > issue hit UPDATE > cID = data[0] > cur.execute('''UPDATE files SET hits = hits + 1, > lastvisit = %s WHERE ID = %s''', (date, cID) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Tue Mar 5 09:37:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 06:37:45 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: ?? ?????, 5 ??????? 2013 3:38:49 ?.?. UTC+2, ? ??????? Vytas D. ??????: > Hi, > > It is really complicated to reproduce the errors you get by running your code since it involves database queries. > > Though one thing that really needs your attention is how you handle the results from os.walk(path). > > > Dave Angel told you already that: "But os.walk() doesn't return a filename. It returns a tuple.". > > > > To show where you are wrong I have create the directory structure: > > Folder "folder1" that has files "file4.txt" and "file3.txt" inside. > > > > > In Python 2.6.5: > >>> import os > >>> for filename in os.walk('folder1'): > ...? print(filename) > ... > ('folder1', [], ['file4.txt', 'file3.txt']) > > >>> > > > So your code is treating results from os.walk() incorrectly. You get tuple, so extract data you need from it first. In case you don't know how: > > > Print files only (no directories. Adapt code to your needs): > > >>> for result in os.walk('folder1'): > ...??? for filename in result[2]: > ...????? print(filename) > ... > file4.txt > file3.txt > > > > In http://docs.python.org/2/library/os.html you will find: > > os.walk(top, topdown=True, onerror=None, followlinks=False) > Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames). > > ... > > > > Vytas > > > > > On Tue, Mar 5, 2013 at 1:01 PM, ????? ???33? wrote: > > Please help me correct thois code, iam tryign ti for hours and i cant seem to get it working....it irritates me.... > > > > > path = "/home/nikos/public_html/data/files/" > > for filename in os.walk(path): > > ? ? ? ? try: > > ? ? ? ? ? ? ? ? #find the needed counter for the page URL > > ? ? ? ? ? ? ? ? cur.execute('''SELECT ID FROM files WHERE URL = %s''', (filename,) ) > > ? ? ? ? ? ? ? ? data = cur.fetchone() ? ? ? ?#URL is unique, so should only be one > > > > ? ? ? ? ? ? ? ? if not data: > > ? ? ? ? ? ? ? ? ? ? ? ? #first time for page; primary key is automatic, hit is defaulted > > ? ? ? ? ? ? ? ? ? ? ? ? cur.execute('''INSERT INTO files (URL, lastvisit) VALUES (%s, %s)''', (filename, date) ) > > ? ? ? ? ? ? ? ? ? ? ? ? cID = cur.lastrowid ? ? ? ?#get the primary key value of the new record > > ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? #found the page, save primary key and use it to issue hit UPDATE > > ? ? ? ? ? ? ? ? ? ? ? ? cID = data[0] > > ? ? ? ? ? ? ? ? ? ? ? ? cur.execute('''UPDATE files SET hits = hits + 1, lastvisit = %s WHERE ID = %s''', (date, cID) > > ? ? ? ? except MySQLdb.Error, e: > > ? ? ? ? ? ? ? ? print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > -- > > http://mail.python.org/mailman/listinfo/python-list Yes indeed! the problem was at the way os.walk resulted the data. one would think that os.walk would return the actual filenames ina tuple but it also returned coupel things more before the file themselevrs. thank you a lot for poitning this out to me. From nikos.gr33k at gmail.com Tue Mar 5 09:37:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 06:37:45 -0800 (PST) Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: ?? ?????, 5 ??????? 2013 3:38:49 ?.?. UTC+2, ? ??????? Vytas D. ??????: > Hi, > > It is really complicated to reproduce the errors you get by running your code since it involves database queries. > > Though one thing that really needs your attention is how you handle the results from os.walk(path). > > > Dave Angel told you already that: "But os.walk() doesn't return a filename. It returns a tuple.". > > > > To show where you are wrong I have create the directory structure: > > Folder "folder1" that has files "file4.txt" and "file3.txt" inside. > > > > > In Python 2.6.5: > >>> import os > >>> for filename in os.walk('folder1'): > ...? print(filename) > ... > ('folder1', [], ['file4.txt', 'file3.txt']) > > >>> > > > So your code is treating results from os.walk() incorrectly. You get tuple, so extract data you need from it first. In case you don't know how: > > > Print files only (no directories. Adapt code to your needs): > > >>> for result in os.walk('folder1'): > ...??? for filename in result[2]: > ...????? print(filename) > ... > file4.txt > file3.txt > > > > In http://docs.python.org/2/library/os.html you will find: > > os.walk(top, topdown=True, onerror=None, followlinks=False) > Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames). > > ... > > > > Vytas > > > > > On Tue, Mar 5, 2013 at 1:01 PM, ????? ???33? wrote: > > Please help me correct thois code, iam tryign ti for hours and i cant seem to get it working....it irritates me.... > > > > > path = "/home/nikos/public_html/data/files/" > > for filename in os.walk(path): > > ? ? ? ? try: > > ? ? ? ? ? ? ? ? #find the needed counter for the page URL > > ? ? ? ? ? ? ? ? cur.execute('''SELECT ID FROM files WHERE URL = %s''', (filename,) ) > > ? ? ? ? ? ? ? ? data = cur.fetchone() ? ? ? ?#URL is unique, so should only be one > > > > ? ? ? ? ? ? ? ? if not data: > > ? ? ? ? ? ? ? ? ? ? ? ? #first time for page; primary key is automatic, hit is defaulted > > ? ? ? ? ? ? ? ? ? ? ? ? cur.execute('''INSERT INTO files (URL, lastvisit) VALUES (%s, %s)''', (filename, date) ) > > ? ? ? ? ? ? ? ? ? ? ? ? cID = cur.lastrowid ? ? ? ?#get the primary key value of the new record > > ? ? ? ? ? ? ? ? else: > > ? ? ? ? ? ? ? ? ? ? ? ? #found the page, save primary key and use it to issue hit UPDATE > > ? ? ? ? ? ? ? ? ? ? ? ? cID = data[0] > > ? ? ? ? ? ? ? ? ? ? ? ? cur.execute('''UPDATE files SET hits = hits + 1, lastvisit = %s WHERE ID = %s''', (date, cID) > > ? ? ? ? except MySQLdb.Error, e: > > ? ? ? ? ? ? ? ? print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > -- > > http://mail.python.org/mailman/listinfo/python-list Yes indeed! the problem was at the way os.walk resulted the data. one would think that os.walk would return the actual filenames ina tuple but it also returned coupel things more before the file themselevrs. thank you a lot for poitning this out to me. From breamoreboy at yahoo.co.uk Tue Mar 5 09:04:00 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 05 Mar 2013 14:04:00 +0000 Subject: Downloading a file form a displayed table In-Reply-To: References: Message-ID: On 05/03/2013 09:00, ????? ???33? wrote: > # ================================================================================================================= > # display download button for each file and downlaod it on click > # ================================================================================================================= > if form.getvalue('show') == 'files': > > print ( "

    " ) > print ( "
    " ) > > path = "/data/files/" > > for filename in os.walk(path): > print ''' > > print( "" ) % filename > > ''' > > sys.exit(0) > > ======================== > > I use the above code to tidplay a filenames table so the user cna download a displayed button style lookign file but its not printing anything for me just an emptry table > > '/data/files' has 5 files in it but its not showing any. > I dont see what iam doign wrong > You're doing at least two things wrong. 1) Not reading documentation 2) Not trying the interactive prompt. 3) Not using the print statement/function. 4) Not taking any notice of what people tell you. 5) Not showing what you expect to happen and what actually happens. 6) You're not doing six wrong. -- Cheers. Mark Lawrence From chris at simplistix.co.uk Tue Mar 5 04:48:20 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 05 Mar 2013 09:48:20 +0000 Subject: testfixtures 3.0.0 Released! Message-ID: <5135BF64.3040902@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 3.0.0. The big change for this release is that testfixtures now supports Python 2.6, 2.7, 3.2 and 3.3! As a result, some changes have been made to TempDirectory to support encoding and decoding. There's also a nice little addition of an optional prefix to the message generated when comparisons fail: >>> from testfixtures import compare >>> compare(1, 2, prefix='wrong number of orders') Traceback (most recent call last): ... AssertionError: wrong number of orders: 1 != 2 The means that you still get the rich comparison feedback offered by compare, but can also add more information to make any failure more easily understandable without having to dig into the source. Other than that, there have been a couple of minor bug fixes. If you haven't bumped into it already, testfixtures is a collection of helpers for writing succinct unit tests including help for: - Comparing objects and sequences Better feedback when the results aren't as you expected along with support for comparison of objects that don't normally support comparison. - Mocking out objects and methods Easy to use ways of stubbing out objects, classes or individual methods for both doc tests and unit tests. Special helpers are provided for testing with dates and times. - Testing logging Helpers for capturing logging output in both doc tests and unit tests. - Testing stream output Helpers for capturing stream output, such as that from print statements, and making assertion about it. - Testing with files and directories Support for creating and checking files and directories in sandboxes for both doc tests and unit tests. - Testing exceptions Easy to use ways of checking that a certain exception is raised, even down the to the parameters the exception is raised with. 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 esj at harvee.org Tue Mar 5 09:20:37 2013 From: esj at harvee.org (Eric Johansson) Date: Tue, 05 Mar 2013 09:20:37 -0500 Subject: simple GUI environment Message-ID: <5135FF35.9010905@harvee.org> I need a simple GUI toolkits like easygui pythoncard. The main reason I discount both of those is that they are effectively dead as I can see. Last updates in the 2010/2011 range. Has there been some toolkit to replace them? And no, the existing wxpython/gtk/qt/... toolkits really aren't acceptable. I need to get something done in 12 hours and I don't have time to climb the learning curve. The application I'm building is a tool which gathers and saves configuration data for a specific Windows application. It needs to run in a Windows batch file for multisystem deployment and also as a GUI when the user is mucking about. It also needs to run as a portable app because I can't install this on every machine. many corporate IT types don't take kindly to utilities leaving little footprints all over the place. The CLI version works. Simple UI, does what I need for part of the job. Now I need to add a relatively simple GUI. The user interface will consist of a series of tabs across the top, one for each subsystem and the main panel beneath that will contain the UI for the tab related task. I could fake the tabs by using a horizontal list of radio buttons which have the same semantics as tabs but a very different look. I could do this relatively easily with twitter bootstrap but I don't have a standalone browser that I can embed in Python so I could build HTML for user interface. suggestions? I appreciate whatever help you can give. From kw at codebykevin.com Tue Mar 5 09:55:40 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 05 Mar 2013 09:55:40 -0500 Subject: simple GUI environment In-Reply-To: References: Message-ID: On 3/5/13 9:20 AM, Eric Johansson wrote: > The main reason I discount both of those is that they are effectively > dead as I can see. Last updates in the 2010/2011 range. Why not give EasyGUI a try? The site is still active, and two years isn't without an update doesn't mean a project is dead, especially if it's a simple and mature project that doesn't need a lot of maintenance. If your needs are basic, then I'd say EasyGUI would be a good fit. By contrast, a library undergoing heavy development with a constantly-shifting API can cause tons of headaches. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From mail at timgolden.me.uk Tue Mar 5 10:06:10 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 05 Mar 2013 15:06:10 +0000 Subject: simple GUI environment In-Reply-To: References: Message-ID: <513609E2.30403@timgolden.me.uk> On 05/03/2013 14:55, Kevin Walzer wrote: > On 3/5/13 9:20 AM, Eric Johansson wrote: >> The main reason I discount both of those is that they are effectively >> dead as I can see. Last updates in the 2010/2011 range. > > Why not give EasyGUI a try? or PyGUI: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ TJG From esj at harvee.org Tue Mar 5 12:45:04 2013 From: esj at harvee.org (Eric Johansson) Date: Tue, 05 Mar 2013 12:45:04 -0500 Subject: simple GUI environment In-Reply-To: <513609E2.30403@timgolden.me.uk> References: <513609E2.30403@timgolden.me.uk> Message-ID: <51362F20.3080205@harvee.org> On 3/5/2013 10:06 AM, Tim Golden wrote: > On 05/03/2013 14:55, Kevin Walzer wrote: >> On 3/5/13 9:20 AM, Eric Johansson wrote: >>> The main reason I discount both of those is that they are effectively >>> dead as I can see. Last updates in the 2010/2011 range. >> Why not give EasyGUI a try? > or PyGUI: > > http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ > you guys are great. I'm going to try pygui first and easygui second. My reason for this is that pygui looks like it will let me bundle using py2exe without trying hard.the only thing that would make it better is if either of these kits used standard Rich text edit controls under Windows so I can speech enable these applications. Thanks a bunch. All the advice was really useful and appreciated. From greg.ewing at canterbury.ac.nz Tue Mar 5 18:18:18 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Mar 2013 12:18:18 +1300 Subject: simple GUI environment In-Reply-To: References: <513609E2.30403@timgolden.me.uk> Message-ID: Eric Johansson wrote: > the only thing that would make it better is > if either of these kits used standard Rich text edit controls under > Windows so I can speech enable these applications. PyGUI's TextEditor is based on the rich edit control in Windows. It doesn't currently expose all of its capabilities, but if speech is all you want, it might be sufficient. -- Greg From esj at harvee.org Tue Mar 5 20:35:43 2013 From: esj at harvee.org (Eric Johansson) Date: Tue, 05 Mar 2013 20:35:43 -0500 Subject: simple GUI environment In-Reply-To: References: <513609E2.30403@timgolden.me.uk> Message-ID: <51369D6F.7070309@harvee.org> On 3/5/2013 6:18 PM, Gregory Ewing wrote: > Eric Johansson wrote: >> the only thing that would make it better is if either of these kits >> used standard Rich text edit controls under Windows so I can speech >> enable these applications. > > PyGUI's TextEditor is based on the rich edit control in > Windows. It doesn't currently expose all of its capabilities, > but if speech is all you want, it might be sufficient. Do you know which one? http://www.section508.va.gov/docs/Dragon_Naturally_Speaking_Apps.pdf (copied from the PDF, apologies for the crappy formatting) Use supported window classes for edit controls. Dragon 10 supports the following control classes. (Borland controls, TE Edit, and TX Text are supported only in Professional, Medical, Legal, and SDK editions of Dragon.) Vendor Control Class Microsoft Edit, Rich Edit, Rich Edit20A, RichEdit20W, Rich Edit50W, Inktextbox, Inkedit, RichTextBox .NET controls Borland TMemo, TEdit, TRichEdit Sub Systems TE Edit versions 10, 11, 12, 13, 14, 15 (not TE Edit .NET) Text Control TX Text versions 10, 11, 12, 13, 14 and TX Text .NET From greg.ewing at canterbury.ac.nz Wed Mar 6 00:08:35 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Mar 2013 18:08:35 +1300 Subject: simple GUI environment In-Reply-To: References: <513609E2.30403@timgolden.me.uk> Message-ID: Eric Johansson wrote: > On 3/5/2013 6:18 PM, Gregory Ewing wrote: >> >> PyGUI's TextEditor is based on the rich edit control in >> Windows. It doesn't currently expose all of its capabilities, >> but if speech is all you want, it might be sufficient. > > Do you know which one? > > Vendor Control Class > Microsoft Edit, Rich Edit, Rich Edit20A, RichEdit20W, Rich Edit50W, > Inktextbox, Inkedit, RichTextBox .NET controls > Borland TMemo, TEdit, TRichEdit > Sub Systems TE Edit versions 10, 11, 12, 13, 14, 15 (not TE Edit .NET) > Text Control TX Text versions 10, 11, 12, 13, 14 and TX Text .NET Whichever one MFC's RichEditView uses. I can't tell you any more than that, sorry. -- Greg From vlastimil.brom at gmail.com Tue Mar 5 10:45:28 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 5 Mar 2013 16:45:28 +0100 Subject: simple GUI environment In-Reply-To: <5135FF35.9010905@harvee.org> References: <5135FF35.9010905@harvee.org> Message-ID: 2013/3/5 Eric Johansson : > I need a simple GUI toolkits like easygui pythoncard. The main reason I > discount both of those is that they are effectively dead as I can see. Last > updates in the 2010/2011 range. Has there been some toolkit to replace them? > And no, the existing wxpython/gtk/qt/... toolkits really aren't acceptable. > I need to get something done in 12 hours and I don't have time to climb the > learning curve. ... > > The CLI version works. Simple UI, does what I need for part of the job. Now > I need to add a relatively simple GUI. The user interface will consist of a > series of tabs across the top, one for each subsystem and the main panel > beneath that will contain the UI for the tab related task. I could fake the > tabs by using a horizontal list of radio buttons which have the same > semantics as tabs but a very different look. > ... > > suggestions? > > I appreciate whatever help you can give. > -- > http://mail.python.org/mailman/listinfo/python-list Hi, I usually use wxpython for my GUI-needs, but given the considerations you mention, I'd check, whether the builtin tkinter and ttk might be appropriate for this task. I would somehow expect the least portability problems with this gui toolkit. There is a Notebook widget in ttk: http://docs.python.org/3.3/library/tkinter.ttk.html#tkinter.ttk.Notebook or http://docs.python.org/2/library/ttk.html#ttk.Notebook for python 2.7 tkinter/ttk can be quite capable and (with some care) nice-looking too; see, e.g.: http://code.google.com/p/python-ttk/wiki/Screenshots hth, vbr From anadionisio257 at gmail.com Tue Mar 5 10:32:11 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 5 Mar 2013 07:32:11 -0800 (PST) Subject: Recursive function Message-ID: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Hello! I have to make a script that calculates temperature, but one of the parameters is the temperature in the iteration before, for example: temp = (temp_-1)+1 it = 0 temp = 3 it = 1 temp = 3+1 it = 2 temp = 4+1 How can I do this in a simple way? Thanks a lot! From davea at davea.name Tue Mar 5 11:02:03 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 11:02:03 -0500 Subject: Recursive function In-Reply-To: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> References: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Message-ID: <513616FB.20507@davea.name> On 03/05/2013 10:32 AM, Ana Dion?sio wrote: > Hello! > > I have to make a script that calculates temperature, but one of the > parameters is the temperature in the iteration before, for example: > temp = (temp_-1)+1 > > it = 0 > temp = 3 > > it = 1 > temp = 3+1 > > it = 2 > temp = 4+1 > > How can I do this in a simple way? > > Thanks a lot! > Recursion only works when you have a termination condition. Otherwise, it just loops endlessly (or more specifically until the stack runs out of room). Still, you don't have a problem that even implies recursion, just iteration. For your simple case, there's a simple formula: def find_temp(it): return it+3 Methinks you have simplified the problem too far to make any sense. import itertools temp = 3 for it in itertools.count(): temp += 1 print it, temp Warning: that loop will never terminate. Is this what you were looking for? It uses recursion, and I used <=0 for the termination condition. def find_temp2(it): if it <=0: return 3 return find_temp(it-1) -- DaveA From vlastimil.brom at gmail.com Tue Mar 5 11:06:08 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 5 Mar 2013 17:06:08 +0100 Subject: Recursive function In-Reply-To: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> References: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Message-ID: 2013/3/5 Ana Dion?sio : > Hello! > > I have to make a script that calculates temperature, but one of the > parameters is the temperature in the iteration before, for example: > temp = (temp_-1)+1 > > it = 0 > temp = 3 > > it = 1 > temp = 3+1 > > it = 2 > temp = 4+1 > > How can I do this in a simple way? > > Thanks a lot! > -- > http://mail.python.org/mailman/listinfo/python-list Hi, it is not quite clear from the examples, what should be achieved (I guess, the actual computation is probably mor complex). I'd probably approach an iterative computation iteratively, rather than recursively; e.g. simply: def compute_iteratively(starting_value, number_of_iterations): tmp = starting_value for i in range(number_of_iterations): tmp = tmp + 1 return tmp print(compute_iteratively(starting_value=7, number_of_iterations=3)) hth, vbr From anadionisio257 at gmail.com Tue Mar 5 11:15:06 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 5 Mar 2013 08:15:06 -0800 (PST) Subject: Recursive function In-Reply-To: References: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Message-ID: <9b974e02-e055-4a52-9d79-336f3a85bb72@googlegroups.com> Yes, I simplified it a lot. I need to run it 24 times. What I don't really understand is how to put the final temperature (result) in it = 0 in temp_-1 in it =1 From anadionisio257 at gmail.com Tue Mar 5 11:15:06 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 5 Mar 2013 08:15:06 -0800 (PST) Subject: Recursive function In-Reply-To: References: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Message-ID: <9b974e02-e055-4a52-9d79-336f3a85bb72@googlegroups.com> Yes, I simplified it a lot. I need to run it 24 times. What I don't really understand is how to put the final temperature (result) in it = 0 in temp_-1 in it =1 From neilc at norwich.edu Tue Mar 5 14:05:22 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 5 Mar 2013 19:05:22 GMT Subject: Recursive function References: <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> Message-ID: On 2013-03-05, Ana Dion?sio wrote: > Yes, I simplified it a lot. > > I need to run it 24 times. What I don't really understand is > how to put the final temperature (result) in it = 0 in temp_-1 > in it =1 One way to compose a function that recurses by calling itself is to first write the simplest version of the function you can think of, the version that solves the most trivial form for the problem. For example, lets say I want to write a recursive function to reverse a string (you would never do this except as an exercise), I'd first write a version that can successfully reverse an empty string. def reverse0(s): if len(s) == 0: return s The next most complex problem is a string with one character. I'll write that next. They key is to write it in terms of the function I already wrote, reverse0. def reverse1(s): if len(s) == 1: return s + reverse0('') At this point it becomes clear that reverse0 is not needed. I'll just use a new version of reverse1 instead: def reverse1(s): if len(s) <= 1: return s The next vesion will be able to handle two characters. I'll write it to use my previously composed reverse1 function. def reverse2(s): if len(s) == 2: return s[-1] + reverse1(s[:-1]) And so on: def reverse3(s): if len(s) == 3: return s[-1] + reverse2(s[:-1]) def reverse4(s): if len(s) == 4: return s[-1] + reverse3(s[:-1]) By this time a pattern has emerged; every version of reverse after reverse1 is exactly the same. I can now write my recursive reverse function. def reverse_any(s): if len(s) <= 1: return s else: return s[-1] + reverse_any(s[:-1]) Try this exercise with your conversion problem and see if you can make progress. -- Neil Cerutti From Mamma_Wesolowski at hotmail.com Tue Mar 5 10:46:40 2013 From: Mamma_Wesolowski at hotmail.com (Mamma Wesolowski) Date: Tue, 05 Mar 2013 15:46:40 GMT Subject: Psychopath Jack Wesolowski takes another spam dump on the UseNet (was: Gary Sokolich - 3463) References: Message-ID: Psychopath Jack Wesolowski trolling and spamming the UseNet as Gary Sokolisch wrote in news:tv04oi1c11wu.1gv33jqjim98d$.dlg at 40tude.net: > 3463 > > W Gary Sokolich > 801 Kings Road > Newport Beach, CA 92663-5715 > (949) 650-5379 > Local PD > 949-644-3681 > > Residence: > 1029 S Point View St > Los Angeles CA 90035 > (310) 650-5379 > > and > 5309 Victoria Ave., Los Angeles, CA, 90043 > > > > > http://web.archive.org/web/20080821231423/http://www.tbpe.state.tx.us/d > a/da022808.htm > > TEXAS BOARD OF PROFESSIONAL ENGINEERS > February 28, 2008 Board Meeting Disciplinary Actions > > W. Gary Sokolich , Newport Beach, California ?V File B-29812 - It was > alleged that. Sokolich unlawfully offered or attempted to practice > engineering in Texas (...) Sokolich chose to end the proceedings by > signing a Consent Order that was accepted by the Board to cease and > desist from representing himself as an ??Engineer?? in Texas, from any > and all representations that he can offer or perform engineering > services and from the actual practice of engineering in Texas (...) > Sokolich was also assessed a $1,360.00 administrative penalty. > > _______________ > > http://articles.latimes.com/1988-04-14/local/me-1922_1_ucla-researcher > > A former UCLA employee has agreed to provide copies of his research to > the school to settle a lawsuit the university filed against him in > 1985, lawyers in the case said. > > (...) > > The University of California Board of Regents filed a $620,000 lawsuit > against Sokolich, accusing him of taking research on the hearing > capabilities of animals in June, 1982. Sokolich was dismissed by UCLA > (...). > > (...) > That's my boy Jack Wesolowski, a 68-year old, mentally-ill , retired SSD worker, foul-mouthed bigot, racist, liar, spammer and troll who has been spamming the UseNet as Gary Sokolisch since January of 2011. A recent ode to psychopath Jack Wesolowski, from rec.sport.boxing http://groups.google.com/group/rec.sport.boxing/msg/336baad3954b6f51?... http://tinyurl.com/7ldhq3b "Way Back Jack, his mother licks my crack, Then she sucks my dick until it's yellah. An' his mother-fuckin' fathah doesn't so much as bother To use some spittle when he's bung-holin' little Boys, before they're rollin' in the shower, their 'nads all a' swollen, While our perverted faggot Jack laps up all their bloody turds. He's a real low-life fellah, whose perversion escapes mere words And one from alt.native, May 4, 2002. http://groups.google.com/group/alt.native/msg/0f12476019613f13?dmode=... http://tinyurl.com/6ugweze Brother Jack is a racist bigot His mouth is a toxic old spigot He spews out his hate He never can wait To find some more dolts who will dig it! We know a white jerk named Jack Who really wants to be black He calls himself "brother" Wears clothes from his mother(*) The truth is he's just a hack We see his rantings as racist bile His words typically ugly and vile The master of hate Thank God he won't mate Let us leave him alone for awhile (*) Jack Wesolowski, circa 2000 http://tinyurl.com/3dtnmpz Meet Psychopath Jack Wesolowski, the crass, foul-mouthed, bigot, racist, liar, spammer and troll. Jack Wesolowski the spammer http://tinyurl.com/3o7su5k Jack Wesolowski the troll. http://tinyurl.com/6ynlegl http://tinyurl.com/5vljxag http://tinyurl.com/3nukkeo Jack Wesolowsk the liar. http://tinyurl.com/6hr3lmq http://tinyurl.com/44x4ceg Jack Wesolowski the bigot. http://tinyurl.com/3n5z48d http://tinyurl.com/3h2sc48 Jack Wesolowski the racist. http://tinyurl.com/3m3vhjb http://tinyurl.com/3qoolnh http://tinyurl.com/3j8gnfm http://tinyurl.com/3c97kg7 Jack Wesolowski, aka Bob Cain (resurrected) joe momma farting boar diane roselles dr jackal Repeal Obama Mothzer Roselles Xavier Amber Travsky Vladimir Tschenko Badenovsky Off the moonbat A liberal's worst nightmare Swatting Moonbatz Ruth Chilton That Sleazy Cunt Piglosi Obama Nation is Abomination ObamaNation=Abomination Let it Rock Nobama Repeal Obama Mother Roselles Swatting Moonbatz Amber Travsky Gary Sokolisch Weary Bruiser 1 reti... at home.net Vladimir Badenovsky Mike Gibson's Ghost Gary Sokolosch Gary Sakolich THE REAL GARY GARY IN ANIMAL RESEARCH GARY THE "ENGINEER" Calhoun Bobby Fuller Calhoon Jack (windswept at home.) JackW (windswept at home) Windswept at home. (jack) BroJack Bro Jack brojac... at my-deja.com waybackjack way back jack jackweso JackWesolowski jackw... at email.msn.com (brojac... at my-deja.com) Jack Wesolowski (wesolow... at freewwweb.com) BroJ... at windswept.net (BroJack) Windswept at Home (Jack W) jackw... at email.msn.com (brojac... at my-deja.com) Jack from waaaayyyyyBack John F Wesolowski 3045 Old Washington Rd Westminster, MD 21157 (410) 876-6914 http://tinyurl.com/6cv8t2e From olsr.kamal at gmail.com Tue Mar 5 12:07:30 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Tue, 5 Mar 2013 09:07:30 -0800 (PST) Subject: =?ISO-8859-1?Q?comment_r=E9cup=E9rer_les_valeurs_de_canvas_dans_pytho?= =?ISO-8859-1?Q?n?= Message-ID: <9a11a6d3-7633-4fa3-9a2d-7cd4a87d289f@googlegroups.com> comment r?cup?rer la couleur d'un canvas ou id d'un canvas? From jeanmichel at sequans.com Mon Mar 11 06:54:00 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 11 Mar 2013 11:54:00 +0100 (CET) Subject: =?utf-8?Q?Re:_comment_r=C3=A9cup=C3=A9rer_les_v?= =?utf-8?Q?aleurs_de_canvas_dans_python?= In-Reply-To: <9a11a6d3-7633-4fa3-9a2d-7cd4a87d289f@googlegroups.com> Message-ID: <162974015.3311436.1362999240916.JavaMail.root@sequans.com> ----- Original Message ----- > comment r?cup?rer la couleur d'un canvas ou id d'un canvas? > -- > http://mail.python.org/mailman/listinfo/python-list Hello, I'll take my chance : http://effbot.org/tkinterbook/canvas.htm JM PS : write in english, or frenglish like I do, something that has a chance of being understood here. -- 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 nikos.gr33k at gmail.com Tue Mar 5 12:11:07 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 09:11:07 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: Any ideas on hopw to embed some html data at the end of each python script? From breamoreboy at yahoo.co.uk Tue Mar 5 12:19:53 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 05 Mar 2013 17:19:53 +0000 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: On 05/03/2013 17:11, ????? ???33? wrote: > Any ideas on hopw to embed some html data at the end of each python script? > Write some code. -- Cheers. Mark Lawrence From joel.goldstick at gmail.com Tue Mar 5 12:25:54 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Mar 2013 12:25:54 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: On Tue, Mar 5, 2013 at 12:19 PM, Mark Lawrence wrote: > On 05/03/2013 17:11, ????? ???33? wrote: > >> Any ideas on hopw to embed some html data at the end of each python >> script? >> > http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm > >> > Write some code. > > -- > Cheers. > > Mark Lawrence > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Tue Mar 5 12:39:19 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 09:39:19 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: But i did, I just tried this: # open html template if htmlpage.endswith('.html'): f = open( "/home/nikos/public_html/" + htmlpage ) htmldata = f.read() counter = '''
    ''' % data[0] else: f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) htmldata = f.read() counter = ''' print '''
    ??????? ?????????? %d
    ''' ''' % data[0] template = htmldata + counter print ( template ) ============= But still doens't embed correctly the additional html data at the end of the .py files..... Do you have an idea? From joel.goldstick at gmail.com Tue Mar 5 12:45:25 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Mar 2013 12:45:25 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: On Tue, Mar 5, 2013 at 12:39 PM, ????? ???33? wrote: > But i did, I just tried this: > > # open html template > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > > htmldata = f.read() > counter = '''
    >
    ??????? ?????????? %d
    cellpadding=2 bgcolor=black> > > > ''' % data[0] > else: > f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) > > htmldata = f.read() > counter = ''' > print '''
    >
    color=lime>??????? ?????????? %d
    cellpadding=2 bgcolor=black> > > > ''' > remove the extra triple quote. But seriously, in 2013 you are writing html like the above? That is some awful stuff > ''' % data[0] > > template = htmldata + counter > print ( template ) > ============= > > But still doens't embed correctly the additional html data at the end of > the .py files..... > > Do you have an idea? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Tue Mar 5 12:49:28 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 09:49:28 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> What extra triple quote? There are 2 sets of triple quotes the counter's and the print's !! in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no? From nikos.gr33k at gmail.com Tue Mar 5 12:49:28 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 09:49:28 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> What extra triple quote? There are 2 sets of triple quotes the counter's and the print's !! in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no? From davea at davea.name Tue Mar 5 13:18:16 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 13:18:16 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> Message-ID: <513636E8.1050907@davea.name> On 03/05/2013 12:49 PM, ????? ???33? wrote: > What extra triple quote? > There are 2 sets of triple quotes the counter's and the print's !! There are 3 pairs of triple-quotes. But one pair is nested inside the other, so the interpreter will not handle it the way you apparently want. If you have to use quotes inside quotes, you must either use a different kind, or escape them. Perhaps you wanted something like: counter = """ print '''
    etc....
    color=lime>??????? ?????????? %d font ... ''' """ % data[0] But this fragment is unreadable to me, so the syntax error is probably the least of your worries. > > in case htmlpage variable is a .py file i must append a print '''html''' in order for .py code to absorve that code properly no? > No clue what that sentence fragment means. 'absorve' isn't an English word, and neither 'absorb' nor 'observe' make any sense. Perhaps if you posted a complete program, and identified it by name, and specified the complete environment it runs in, and used English to describe what should be appended to what, we'd be able to help. As it is, you've got mixed clues from which that it's both Python 2 and 3, running Linux or equivalent, and probably runs on a server. Using symbol names that make sense would also help. 'htmlpage' is apparently a str representing a filename on disk. 'counter' is not an integer, but a long string of html. 'data' is apparently a tuple or list, and the zeroth element is an int. ?? -- -- DaveA From nikos.gr33k at gmail.com Tue Mar 5 13:53:25 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 10:53:25 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> Message-ID: Let's focus on just the following snipper please: f = open( some_python_file ) htmldata = f.read() counter = ''' print( "
    " ) ''' % data[0] #render template template = htmldata + counter print ( template ) ============================= What this snippet tries to accomplish is append the following string ========================================= counter = '''
    ??????? ?????????? %d
    ''' % data[0 ========================================= at the end of the the python script file that it currently opened. I'am using the print statemnt inside the triple quoted string so to append that html data by inserting a print statemnt but although i have changes the type of quoting it still fails. If i try to append that html data to an .html file they are inserted beautifully but inside a .py file they dont. I just need to append that string after the end of a .py file. that's all i want to do. From joel.goldstick at gmail.com Tue Mar 5 14:33:59 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Mar 2013 14:33:59 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> Message-ID: On Tue, Mar 5, 2013 at 1:53 PM, ????? ???33? wrote: > Let's focus on just the following snipper please: > > f = open( some_python_file ) > > htmldata = f.read() > counter = ''' print( " >
    > >
    ??????? ?????????? %d
    bgcolor=black> > > > " ) > ''' % data[0] > > #render template > template = htmldata + counter > print ( template ) > ============================= > > What this snippet tries to accomplish is append the following string > > ========================================= > counter = '''
    > >
    ??????? > ?????????? %d
    bgcolor=black> > > > ''' % data[0 > ========================================= > > at the end of the the python script file that it currently opened. > I'am using the print statemnt inside the triple quoted string so to append > that html data by inserting a print statemnt but although i have changes > the type of quoting it still fails. > > If i try to append that html data to an .html file they are inserted > beautifully but inside a .py file they dont. > > I just need to append that string after the end of a .py file. that's all > i want to do. > -- > http://mail.python.org/mailman/listinfo/python-list > print displays to the console. To write to a file open file in 'append' mode and write: with open("test.py", "a") as myfile: myfile.write("appended text") -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Tue Mar 5 13:53:25 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 10:53:25 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> Message-ID: Let's focus on just the following snipper please: f = open( some_python_file ) htmldata = f.read() counter = ''' print( "
    ??????? > ?????????? %d
    " ) ''' % data[0] #render template template = htmldata + counter print ( template ) ============================= What this snippet tries to accomplish is append the following string ========================================= counter = '''
    ??????? ?????????? %d
    ''' % data[0 ========================================= at the end of the the python script file that it currently opened. I'am using the print statemnt inside the triple quoted string so to append that html data by inserting a print statemnt but although i have changes the type of quoting it still fails. If i try to append that html data to an .html file they are inserted beautifully but inside a .py file they dont. I just need to append that string after the end of a .py file. that's all i want to do. From davea at davea.name Tue Mar 5 14:48:45 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 14:48:45 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <14d3a13e-9d95-49b5-9d58-205021b79630@googlegroups.com> Message-ID: <51364C1D.9030708@davea.name> On 03/05/2013 01:53 PM, ????? ???33? wrote: > Let's focus on just the following snipper please: Once again, I repeat. Make a fragment that contains enough information to actually run. Explain in what environment it's running, and what you hoped would happen. For example, why on earth would you assume that printing to the console below would write to a file instead? Is some part of this running as a cgi inside a web server? What is your environment? > > f = open( some_python_file ) > > htmldata = f.read() > counter = ''' print( " Syntax error here. Since the inner string is more than one line, you will need to use """. See my example last message. This only matters if you succeed in writing this to a python file. >
    >
    ??????? ?????????? %d
    > > > " ) > ''' % data[0] > > #render template > template = htmldata + counter > print ( template ) Why should print write to some python file you have open?? Besides you have the file open for readonly access. So you might use: f.close() f = open( some_python_file, "w" ) f.write(template) f.close() > ============================= > > What this snippet tries to accomplish is append the following string > > ========================================= > counter = '''
    >
    ??????? ?????????? %d
    > > > ''' % data[0 > ========================================= > > at the end of the the python script file that it currently opened. But that's not at all what's inside the counter variable. > I'am using the print statemnt inside the triple quoted string so to append that html data by inserting a print statemnt but although i have changes the type of quoting it still fails. Don't ever say "it fails". If you can't be bothered to explain in what way it fails, forget it. Perhaps you're trying to say it prints a string to the console instead of writing a different string to the /fullpath/to/some_python_file.py Or perhaps you're saying it crashed the Windows machine, and killed power for miles around. Or perhaps you're saying it got an exception but we won't bother telling you which. > > If i try to append that html data to an .html file they are inserted beautifully Untrue, unless your environment is specified, it certainly did not. perhaps you were running the program with output redirected to a file, in which case it lost the earlier version. Or perhaps you were running it on a web server, and you *think* some file changed because some obscure thing happened on your browser. What's your environment? > but inside a .py file they dont. > > I just need to append that string after the end of a .py file. that's all i want to do. > Easy to do in emacs. -- DaveA From breamoreboy at yahoo.co.uk Tue Mar 5 12:53:10 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 05 Mar 2013 17:53:10 +0000 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: On 05/03/2013 17:39, ????? ???33? wrote: > But i did, I just tried this: > > # open html template > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > > htmldata = f.read() > counter = '''
    >
    ??????? ?????????? %d
    > > > ''' % data[0] > else: > f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) > > htmldata = f.read() > counter = ''' > print '''
    >
    ??????? ?????????? %d
    > > > ''' > ''' % data[0] > > template = htmldata + counter > print ( template ) > ============= > > But still doens't embed correctly the additional html data at the end of the .py files..... > > Do you have an idea? > You're doing something wrong. -- Cheers. Mark Lawrence From r.koebler at yahoo.de Wed Mar 6 04:00:14 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Wed, 6 Mar 2013 10:00:14 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: <20130306090013.GA11805@localhost> Hi, On Tue, Mar 05, 2013 at 09:39:19AM -0800, ????? ???33? wrote: > But i did, I just tried this: > > # open html template > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > > htmldata = f.read() > counter = '''
    >
    ??????? ?????????? %d
    > > > ''' % data[0] > else: > f = open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) > > htmldata = f.read() > counter = ''' > print '''
    >
    ??????? ?????????? %d
    > > > ''' > ''' % data[0] > > template = htmldata + counter > print ( template ) > ============= > > But still doens't embed correctly the additional html data at the end of the .py files..... > > Do you have an idea? as someone said: You're doing it the wrong way. I would recommend to use a template-engine; then you can put the complete html-design (and some design-control-structures) into the template (and *not* into the cgi) and fill data into the template with a python-script. Roland From nikos.gr33k at gmail.com Tue Mar 5 15:04:59 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 12:04:59 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> #open html template if htmlpage.endswith('.html'): f = open( "/home/nikos/public_html/" + htmlpage ) htmldata = f.read() counter = '''
    ??????? ?????????? %d
    ''' % data[0] #render template template = htmldata + counter print ( template ) ============================================ Yes the aboev code does work if we talk about appending html data to an already html file! But if the file is some_python.py file then i cannot just append the data. Actually by appending i dont want to actually insert the data to the end of the .py file, thus altering it but instead run the .py file and print the counter html data afterwards! From d at davea.name Tue Mar 5 16:02:18 2013 From: d at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 16:02:18 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> Message-ID: <51365D5A.4030802@davea.name> On 03/05/2013 03:04 PM, ????? ???33? wrote: > #open html template > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > > htmldata = f.read() > counter = '''
    >
    ??????? ?????????? %d
    > > > ''' % data[0] > > #render template > template = htmldata + counter > print ( template ) > ============================================ > Yes the aboev code does work if we talk about appending html data to an already html file! > > But if the file is some_python.py file then i cannot just append the data. > Actually by appending i dont want to actually insert the data to the end of the .py file, thus altering it but instead run the .py file and print the counter html data afterwards! > In other words, you're just trying to waste our time. Thanks for telling us. -- DaveA From gmx at ross.cx Tue Mar 5 16:29:41 2013 From: gmx at ross.cx (Michael Ross) Date: Tue, 05 Mar 2013 22:29:41 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> Message-ID: On Tue, 05 Mar 2013 21:04:59 +0100, ????? ???33? wrote: > #open html template > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > > htmldata = f.read() > counter = '''
    src="/data/images/mail.png"> >
    ??????? ?????????? %d
    > > > ''' % data[0] > > #render template > template = htmldata + counter > print ( template ) > ============================================ > Yes the aboev code does work if we talk about appending html data to an > already html file! > > But if the file is some_python.py file then i cannot just append the > data. > Actually by appending i dont want to actually insert the data to the end > of the .py file, thus altering it but instead run the .py file and print > the counter html data afterwards! subprocess.checkoutput() ? if htmlpage.endswith('.py'): htmldata=subprocess.check_output(...) counter=... template=htmldata+counter http://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.check_output From nikos.gr33k at gmail.com Tue Mar 5 17:49:49 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 14:49:49 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> Message-ID: <9096f7d9-288a-4394-8599-d7b87f8e7e01@googlegroups.com> ?? ?????, 5 ??????? 2013 11:02:18 ?.?. UTC+2, ? ??????? Dave Angel ??????: > In other words, you're just trying to waste our time. Thanks for > > telling us. Honestly, its not in my intentions to waste your time. I appreciate all the great help you have provided me in all of my questions, i really do. I'am sorry if i sometimes cannot express myself correctly in english, hence i cannot descrive exactly what i want to accomplish. I'am sorry about that but english its not my native language. From nikos.gr33k at gmail.com Tue Mar 5 17:49:49 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 14:49:49 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <9af13b75-a7b0-45c9-a801-797989583cd5@googlegroups.com> Message-ID: <9096f7d9-288a-4394-8599-d7b87f8e7e01@googlegroups.com> ?? ?????, 5 ??????? 2013 11:02:18 ?.?. UTC+2, ? ??????? Dave Angel ??????: > In other words, you're just trying to waste our time. Thanks for > > telling us. Honestly, its not in my intentions to waste your time. I appreciate all the great help you have provided me in all of my questions, i really do. I'am sorry if i sometimes cannot express myself correctly in english, hence i cannot descrive exactly what i want to accomplish. I'am sorry about that but english its not my native language. From nikos.gr33k at gmail.com Tue Mar 5 17:47:18 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 14:47:18 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> Message-ID: <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> Thank you very much! This is what i was looking for and here is my code after receiving your help. So, with the command you provided to me i can actually run the .py script ans save its output and then append from there!! Great! Here is my code now! ==================================== if htmlpage.endswith('.html'): f = open( "/home/nikos/public_html/" + htmlpage ) htmldata = f.read() elif htmlpage.endswith('.py'): htmldata = subprocess.check_output( open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) ) counter = '''
    ??????? ?????????? > %d
    ''' % data[0] template = htmldata + counter print ( template ) ======================================= But i'am getting this error: : 'module' object has no attribute 'check_output' Why does it say it has no attribute? From gmx at ross.cx Tue Mar 5 18:19:03 2013 From: gmx at ross.cx (Michael Ross) Date: Wed, 06 Mar 2013 00:19:03 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> Message-ID: On Tue, 05 Mar 2013 23:47:18 +0100, ????? ???33? wrote: > Thank you very much! This is what i was looking for and here is my code > after receiving your help. > So, with the command you provided to me i can actually run the .py > script ans save its output and then append from there!! Great! > > Here is my code now! > ==================================== > if htmlpage.endswith('.html'): > f = open( "/home/nikos/public_html/" + htmlpage ) > htmldata = f.read() > elif htmlpage.endswith('.py'): > htmldata = subprocess.check_output( open( > "/home/nikos/public_html/cgi-bin/" + htmlpage ) ) > > > counter = '''
    src="/data/images/mail.png"> >
    ??????? ?????????? %d
    > > > ''' % data[0] > > > template = htmldata + counter > print ( template ) > ======================================= > > But i'am getting this error: > : 'module' object has no attribute > 'check_output' > > Why does it say it has no attribute? Python version < 2.7 ? And it's more along the lines of subprocess.check_output( '/home/nikos/.../' + htmlpage ) without "open". Or even subprocess.check_output( [ '/your/python/interpreter', '/home/nikos/...' ] ) From nikos.gr33k at gmail.com Tue Mar 5 18:39:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 15:39:31 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> Message-ID: <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + htmlpage ) htmldata = subprocess.check_output( ['/usr/bin/python', '/home/nikos/public_html/cgi-bin/' + htmlpage] ) Both of the above statemnts fail i'am afraid with the same error message. From nikos.gr33k at gmail.com Tue Mar 5 18:39:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 15:39:31 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> Message-ID: <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + htmlpage ) htmldata = subprocess.check_output( ['/usr/bin/python', '/home/nikos/public_html/cgi-bin/' + htmlpage] ) Both of the above statemnts fail i'am afraid with the same error message. From gmx at ross.cx Tue Mar 5 19:06:33 2013 From: gmx at ross.cx (Michael Ross) Date: Wed, 06 Mar 2013 01:06:33 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: On Wed, 06 Mar 2013 00:39:31 +0100, ????? ???33? wrote: > htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + > htmlpage ) > > htmldata = subprocess.check_output( ['/usr/bin/python', > '/home/nikos/public_html/cgi-bin/' + htmlpage] ) > > Both of the above statemnts fail i'am afraid with the same error message. check_output is available as of Python 2.7 I guess you are still on version 2.6 ? From nikos.gr33k at gmail.com Wed Mar 6 01:12:01 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 22:12:01 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: <895c48df-e965-40c3-a69c-cfb2f5fc7a3e@googlegroups.com> ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Wed, 06 Mar 2013 00:39:31 +0100, ????? ???33? > > wrote: > > > > > htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + > > > htmlpage ) > > > > > > htmldata = subprocess.check_output( ['/usr/bin/python', > > > '/home/nikos/public_html/cgi-bin/' + htmlpage] ) > > > > > > Both of the above statemnts fail i'am afraid with the same error message. > check_output is available as of Python 2.7 > I guess you are still on version 2.6 ? Actually i'am runnign myu cgi script on my hostgator remote web hosting. How dod i check the version of python the server uses? From nikos.gr33k at gmail.com Wed Mar 6 01:12:01 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 22:12:01 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: <895c48df-e965-40c3-a69c-cfb2f5fc7a3e@googlegroups.com> ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Wed, 06 Mar 2013 00:39:31 +0100, ????? ???33? > > wrote: > > > > > htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + > > > htmlpage ) > > > > > > htmldata = subprocess.check_output( ['/usr/bin/python', > > > '/home/nikos/public_html/cgi-bin/' + htmlpage] ) > > > > > > Both of the above statemnts fail i'am afraid with the same error message. > check_output is available as of Python 2.7 > I guess you are still on version 2.6 ? Actually i'am runnign myu cgi script on my hostgator remote web hosting. How dod i check the version of python the server uses? From nikos.gr33k at gmail.com Wed Mar 6 02:48:18 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 23:48:18 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > check_output is available as of Python 2.7 > > > > I guess you are still on version 2.6 ? Indeed! i just checked it's Python 2.6.6: /usr/bin/python and i have asked the linxu admins @ hostgator.com to update python. I trust when they update to v2.7 the script will automatically work! From nikos.gr33k at gmail.com Wed Mar 6 02:48:18 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 23:48:18 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > check_output is available as of Python 2.7 > > > > I guess you are still on version 2.6 ? Indeed! i just checked it's Python 2.6.6: /usr/bin/python and i have asked the linxu admins @ hostgator.com to update python. I trust when they update to v2.7 the script will automatically work! From nikos.gr33k at gmail.com Wed Mar 6 18:18:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 15:18:44 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > check_output is available as of Python 2.7 > I guess you are still on version 2.6 ? I can access each of these from my jailed shell user account without issue, and especially i try /usr/bin/python3 nikos at superhost.gr [~]# /usr/bin/python -V Python 2.6.6 nikos at superhost.gr [~]# /opt/python3/bin/python3 -V Python 3.2.3 nikos at superhost.gr [~]# /usr/bin/python3 -V Python 3.2.3 Problem is that when i change my shebang constructor to #!/sur/bin/python3 my '/cgi-bin/metrites.py' python cgi scripts produces an internal server error while with #!/sur/bin/python the script works. Any ideas as to why? I can post ocde if you want to. From nikos.gr33k at gmail.com Wed Mar 6 18:18:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 15:18:44 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> Message-ID: <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross ??????: > check_output is available as of Python 2.7 > I guess you are still on version 2.6 ? I can access each of these from my jailed shell user account without issue, and especially i try /usr/bin/python3 nikos at superhost.gr [~]# /usr/bin/python -V Python 2.6.6 nikos at superhost.gr [~]# /opt/python3/bin/python3 -V Python 3.2.3 nikos at superhost.gr [~]# /usr/bin/python3 -V Python 3.2.3 Problem is that when i change my shebang constructor to #!/sur/bin/python3 my '/cgi-bin/metrites.py' python cgi scripts produces an internal server error while with #!/sur/bin/python the script works. Any ideas as to why? I can post ocde if you want to. From gmx at ross.cx Wed Mar 6 19:25:09 2013 From: gmx at ross.cx (Michael Ross) Date: Thu, 07 Mar 2013 01:25:09 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> Message-ID: On Thu, 07 Mar 2013 00:18:44 +0100, ????? ???33? wrote: > ?? ???????, 6 ??????? 2013 2:06:33 ?.?. UTC+2, ? ??????? Michael Ross > ??????: > >> check_output is available as of Python 2.7 >> I guess you are still on version 2.6 ? > > > I can access each of these from my jailed shell user account without > issue, and especially i try /usr/bin/python3 > > nikos at superhost.gr [~]# /usr/bin/python -V > Python 2.6.6 > > nikos at superhost.gr [~]# /opt/python3/bin/python3 -V > Python 3.2.3 > > nikos at superhost.gr [~]# /usr/bin/python3 -V > Python 3.2.3 > > > Problem is that when i change my shebang constructor to > #!/sur/bin/python3 my '/cgi-bin/metrites.py' python cgi scripts produces > an internal server error while with #!/sur/bin/python the script works. > > Any ideas as to why? I can post ocde if you want to. You need to post the Traceback. Either run /usr/bin/python3 /cgi-bin/metrites.py on the shell or better look in your webserver error log. Guess: In Python 3 "print" is a function. So print "something" will not work. You need to print("something") From nikos.gr33k at gmail.com Thu Mar 7 01:35:12 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 22:35:12 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> Message-ID: <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> ?? ??????, 7 ??????? 2013 2:25:09 ?.?. UTC+2, ? ??????? Michael Ross ??????: > Either run /usr/bin/python3 /cgi-bin/metrites.py on the shell > or better look in your webserver error log. > Guess: > In Python 3 "print" is a function. > So > print "something" > will not work. You need to > > print("something") Yes Michael i have already prinr with parenthesis except form the triple quoting: print '''

    LOG ???? ??? HTML ???????


    ??????? ?????????? %d >
    ''' have turned to: print('''

    LOG ???? ??? HTML ???????


    ?????? ??????????
    ''') but now iam receiving this error concering except: nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py File "metrites.py", line 88 except MySQLdb.Error, e: ^ SyntaxError: invalid syntax nikos at superhost.gr [~/www/cgi-bin]# which used to work ok in v2.6.6 can you help? From nikos.gr33k at gmail.com Thu Mar 7 01:35:12 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 22:35:12 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> Message-ID: <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> ?? ??????, 7 ??????? 2013 2:25:09 ?.?. UTC+2, ? ??????? Michael Ross ??????: > Either run /usr/bin/python3 /cgi-bin/metrites.py on the shell > or better look in your webserver error log. > Guess: > In Python 3 "print" is a function. > So > print "something" > will not work. You need to > > print("something") Yes Michael i have already prinr with parenthesis except form the triple quoting: print '''

    LOG ???? ??? HTML ???????


    ?????? ??????????
    ''' have turned to: print('''

    LOG ???? ??? HTML ???????


    ?????? ??????????
    ''') but now iam receiving this error concering except: nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py File "metrites.py", line 88 except MySQLdb.Error, e: ^ SyntaxError: invalid syntax nikos at superhost.gr [~/www/cgi-bin]# which used to work ok in v2.6.6 can you help? From r.koebler at yahoo.de Thu Mar 7 03:58:13 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 7 Mar 2013 09:58:13 +0100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> Message-ID: <20130307085813.GB11805@localhost> Hi, > but now iam receiving this error concering except: > > nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py > File "metrites.py", line 88 > except MySQLdb.Error, e: > ^ > SyntaxError: invalid syntax > nikos at superhost.gr [~/www/cgi-bin]# > > which used to work ok in v2.6.6 > > can you help? Python 3 introduced some Python 2-incompatible changes. So, please read: http://docs.python.org/release/3.0.1/whatsnew/3.0.html Roland From nikos.gr33k at gmail.com Thu Mar 7 04:05:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:05:45 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> Message-ID: <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> ?? ??????, 7 ??????? 2013 10:58:13 ?.?. UTC+2, ? ??????? Roland Koebler ??????: > Hi, > > > > > but now iam receiving this error concering except: > > > > > > nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py > > > File "metrites.py", line 88 > > > except MySQLdb.Error, e: > > > ^ > > > SyntaxError: invalid syntax > > > nikos at superhost.gr [~/www/cgi-bin]# > > > > > > which used to work ok in v2.6.6 > > > > > > can you help? > > Python 3 introduced some Python 2-incompatible changes. > > So, please read: http://docs.python.org/release/3.0.1/whatsnew/3.0.html > > > > Roland I did read about print but i'm interesetd to see and its not mentioned there how except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) is supposed to be written as in Python v3.x From nikos.gr33k at gmail.com Thu Mar 7 04:05:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:05:45 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> Message-ID: <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> ?? ??????, 7 ??????? 2013 10:58:13 ?.?. UTC+2, ? ??????? Roland Koebler ??????: > Hi, > > > > > but now iam receiving this error concering except: > > > > > > nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py > > > File "metrites.py", line 88 > > > except MySQLdb.Error, e: > > > ^ > > > SyntaxError: invalid syntax > > > nikos at superhost.gr [~/www/cgi-bin]# > > > > > > which used to work ok in v2.6.6 > > > > > > can you help? > > Python 3 introduced some Python 2-incompatible changes. > > So, please read: http://docs.python.org/release/3.0.1/whatsnew/3.0.html > > > > Roland I did read about print but i'm interesetd to see and its not mentioned there how except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) is supposed to be written as in Python v3.x From lele at metapensiero.it Thu Mar 7 04:22:09 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 07 Mar 2013 10:22:09 +0100 Subject: Inserting-embedding some html data at the end of a .py file References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> Message-ID: <87txona7jy.fsf@nautilus.nautilus> ????? ???33? writes: > I did read about print but i'm interesetd to see and its not mentioned there how > > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > is supposed to be written as in Python v3.x Read better: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax 4th (bullet) point. 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 nikos.gr33k at gmail.com Thu Mar 7 04:28:51 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:28:51 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> Message-ID: <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > I did read about print but i'm interesetd to see and its not mentioned there how > > > > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > > > is supposed to be written as in Python v3.x > > > > Read better: > > http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > 4th (bullet) point. > > > > 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. please give me the exact link to read, i cant seem to find it although you send 4th bullet i do not see it.... From nikos.gr33k at gmail.com Thu Mar 7 04:28:51 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:28:51 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> Message-ID: <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > I did read about print but i'm interesetd to see and its not mentioned there how > > > > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > > > is supposed to be written as in Python v3.x > > > > Read better: > > http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > 4th (bullet) point. > > > > 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. please give me the exact link to read, i cant seem to find it although you send 4th bullet i do not see it.... From lele at metapensiero.it Thu Mar 7 04:50:42 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 07 Mar 2013 10:50:42 +0100 Subject: Inserting-embedding some html data at the end of a .py file References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> Message-ID: <87ppzba68d.fsf@nautilus.nautilus> ????? ???33? writes: > ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: >> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax >> >> 4th (bullet) point. > > please give me the exact link to read, i cant seem to find it although > you send 4th bullet i do not see it.... Oh come on ?????, the above *is* the *exact* link to read, I even pointed at the right subparagraph: it contains both a link to the reference manual for the "except" keyword, and a link to the PEP that talks about the change. 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 rosuav at gmail.com Thu Mar 7 05:19:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 21:19:05 +1100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <87ppzba68d.fsf@nautilus.nautilus> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> <87ppzba68d.fsf@nautilus.nautilus> Message-ID: On Thu, Mar 7, 2013 at 8:50 PM, Lele Gaifax wrote: > ????? ???33? writes: > >> ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: >>> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax >>> >>> 4th (bullet) point. >> >> please give me the exact link to read, i cant seem to find it although >> you send 4th bullet i do not see it.... > > Oh come on ?????, the above *is* the *exact* link to read, I even > pointed at the right subparagraph: it contains both a link to the > reference manual for the "except" keyword, and a link to the PEP that > talks about the change. I think it's time to take him up on his offer to call him an idiot :) Nikos, try 'as'. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 05:34:18 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 02:34:18 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> <87ppzba68d.fsf@nautilus.nautilus> Message-ID: ?? ??????, 7 ??????? 2013 12:19:05 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 7, 2013 at 8:50 PM, Lele Gaifax wrote: > > > ????? ???33? writes: > > > > > >> ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > > >>> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > >>> > > >>> 4th (bullet) point. > > >> > > >> please give me the exact link to read, i cant seem to find it although > > >> you send 4th bullet i do not see it.... > > > > > > Oh come on ?????, the above *is* the *exact* link to read, I even > > > pointed at the right subparagraph: it contains both a link to the > > > reference manual for the "except" keyword, and a link to the PEP that > > > talks about the change. > > > > I think it's time to take him up on his offer to call him an idiot :) > > > > Nikos, try 'as'. > > > > ChrisA Thank you all the trick was to replace the comma with the 'as' script is almost ready for Python v3.2.3 now! ima just receivign this error: --> --> Traceback (most recent call last): File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute r = self._query(query) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query rowcount = self._do_query(q) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "metrites.py", line 212, in cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) ) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute self.errorhandler(self, exc, value) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass(errorvalue) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") Tou cna see it more clearly at my website http://superhost.gr From nikos.gr33k at gmail.com Thu Mar 7 05:34:18 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 02:34:18 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> <87ppzba68d.fsf@nautilus.nautilus> Message-ID: ?? ??????, 7 ??????? 2013 12:19:05 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 7, 2013 at 8:50 PM, Lele Gaifax wrote: > > > ????? ???33? writes: > > > > > >> ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > > >>> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > >>> > > >>> 4th (bullet) point. > > >> > > >> please give me the exact link to read, i cant seem to find it although > > >> you send 4th bullet i do not see it.... > > > > > > Oh come on ?????, the above *is* the *exact* link to read, I even > > > pointed at the right subparagraph: it contains both a link to the > > > reference manual for the "except" keyword, and a link to the PEP that > > > talks about the change. > > > > I think it's time to take him up on his offer to call him an idiot :) > > > > Nikos, try 'as'. > > > > ChrisA Thank you all the trick was to replace the comma with the 'as' script is almost ready for Python v3.2.3 now! ima just receivign this error: --> --> Traceback (most recent call last): File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute r = self._query(query) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query rowcount = self._do_query(q) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "metrites.py", line 212, in cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) ) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute self.errorhandler(self, exc, value) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass(errorvalue) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") Tou cna see it more clearly at my website http://superhost.gr From nikos.gr33k at gmail.com Thu Mar 7 06:51:51 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 03:51:51 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> <87ppzba68d.fsf@nautilus.nautilus> Message-ID: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] Why this line that worked in v2.6 give sme an error in v3.2.3 Traceback (most recent call last): File "files.py", line 14, in <module> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] File "/opt/python3/lib/python3.2/os.py", line 450, in __getitem__ value = self._data[self.encodekey(key)] KeyError: b'REMOTE_ADDR' --> From nikos.gr33k at gmail.com Thu Mar 7 06:51:51 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 03:51:51 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> <87ppzba68d.fsf@nautilus.nautilus> Message-ID: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] Why this line that worked in v2.6 give sme an error in v3.2.3 Traceback (most recent call last): File "files.py", line 14, in <module> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] File "/opt/python3/lib/python3.2/os.py", line 450, in __getitem__ value = self._data[self.encodekey(key)] KeyError: b'REMOTE_ADDR' --> From nikos.gr33k at gmail.com Thu Mar 7 04:55:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:55:57 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> Message-ID: <346f2960-9911-4634-861c-ac8ea01f98b6@googlegroups.com> ?? ??????, 7 ??????? 2013 11:50:42 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > > >> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > >> > > >> 4th (bullet) point. > > > > > > please give me the exact link to read, i cant seem to find it although > > > you send 4th bullet i do not see it.... > > > > Oh come on ?????, the above *is* the *exact* link to read, I even > > pointed at the right subparagraph: it contains both a link to the > > reference manual for the "except" keyword, and a link to the PEP that > > talks about the change. > > > > 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. call me an idiot but is till dont see it: i;am currently trying this: except MySQLdb.OperationalError, e: but give sme an internal server error too :( From nikos.gr33k at gmail.com Thu Mar 7 04:55:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:55:57 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <74843fc3-7ecd-473a-8271-c9f9d3085475@googlegroups.com> Message-ID: <346f2960-9911-4634-861c-ac8ea01f98b6@googlegroups.com> ?? ??????, 7 ??????? 2013 11:50:42 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > ?? ??????, 7 ??????? 2013 11:22:09 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > > >> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#changed-syntax > > >> > > >> 4th (bullet) point. > > > > > > please give me the exact link to read, i cant seem to find it although > > > you send 4th bullet i do not see it.... > > > > Oh come on ?????, the above *is* the *exact* link to read, I even > > pointed at the right subparagraph: it contains both a link to the > > reference manual for the "except" keyword, and a link to the PEP that > > talks about the change. > > > > 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. call me an idiot but is till dont see it: i;am currently trying this: except MySQLdb.OperationalError, e: but give sme an internal server error too :( From nikos.gr33k at gmail.com Thu Mar 7 05:09:59 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 02:09:59 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> Message-ID: <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> This fails also: except MySQLdb.ProgrammingError, e: How on earth the exception is suppsoed to be written!!!! From joel.goldstick at gmail.com Thu Mar 7 05:28:12 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Mar 2013 05:28:12 -0500 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 5:09 AM, ????? ???33? wrote: > This fails also: > > except MySQLdb.ProgrammingError, e: > > How on earth the exception is suppsoed to be written!!!! > Change from except *exc*, *var* to except *exc* as *var*. See *PEP 3110* . So change the comma to the word 'as' > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Thu Mar 7 05:09:59 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 02:09:59 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> Message-ID: <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> This fails also: except MySQLdb.ProgrammingError, e: How on earth the exception is suppsoed to be written!!!! From nikos.gr33k at gmail.com Thu Mar 7 07:06:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 04:06:54 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> Message-ID: An these kind of errors iam receiving to please: Original exception was: Traceback (most recent call last): File "pelatologio.py", line 230, in ''') % (clients, hits, money) UnicodeEncodeError: 'ascii' codec can't encode characters in position 102-108: ordinal not in range(128) in python v2.6.6 this code works and now i'am using: #!/usr/bin/python3 # -*- coding: utf-8 -*- From nikos.gr33k at gmail.com Thu Mar 7 07:06:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 04:06:54 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> Message-ID: An these kind of errors iam receiving to please: Original exception was: Traceback (most recent call last): File "pelatologio.py", line 230, in ''') % (clients, hits, money) UnicodeEncodeError: 'ascii' codec can't encode characters in position 102-108: ordinal not in range(128) in python v2.6.6 this code works and now i'am using: #!/usr/bin/python3 # -*- coding: utf-8 -*- From rosuav at gmail.com Thu Mar 7 07:17:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 23:17:36 +1100 Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> <78e92c1d-521b-440c-9517-84406cdc6d6a@googlegroups.com> <8dbd532b-2007-46e5-9e05-e3b2597d78d9@googlegroups.com> <69615062-409b-4315-bf5a-77e57ad549f2@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 11:06 PM, ????? ???33? wrote: > An these kind of errors iam receiving to please: Part of being a computer programmer is learning to solve problems. Dumping piles of problems onto a list like this isn't the best way to do this. Either pay someone to do the work (there are plenty of web sites that will help you find freelance programmers), or learn to do it yourself. Coming to a list like this should be done respectfully - knowing that you're asking people to devote dev hours for no return - and preferably in accordance with: http://www.catb.org/esr/faqs/smart-questions.html ChrisA From nikos.gr33k at gmail.com Thu Mar 7 01:42:05 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 22:42:05 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> Message-ID: <3b7b7279-f149-4474-9ae0-3c9a73600fe5@googlegroups.com> The whole try stement is as follows to have the compete idea: try: cur.execute( '''SELECT url, hits FROM counters ORDER BY hits DESC''' ) data = cur.fetchall() for row in data: (url, hits) = row print( "" ) % (url, url) print( "" ) % (hits) except MySQLdb.Error, e: print( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) From nikos.gr33k at gmail.com Thu Mar 7 01:42:05 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 22:42:05 -0800 (PST) Subject: Inserting-embedding some html data at the end of a .py file In-Reply-To: References: <7e0a8562-9a48-4f5a-804d-3751733288f0@googlegroups.com> <009ab803-6269-453b-bff1-0c58a6db358d@googlegroups.com> <0d58f312-9259-407d-b47b-80b88cf9a82c@googlegroups.com> <5bfc6644-388f-4469-a591-63fb8070faa2@googlegroups.com> Message-ID: <3b7b7279-f149-4474-9ae0-3c9a73600fe5@googlegroups.com> The whole try stement is as follows to have the compete idea: try: cur.execute( '''SELECT url, hits FROM counters ORDER BY hits DESC''' ) data = cur.fetchall() for row in data: (url, hits) = row print( "" ) % (url, url) print( "" ) % (hits) except MySQLdb.Error, e: print( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) From esj at harvee.org Tue Mar 5 12:56:19 2013 From: esj at harvee.org (Eric Johansson) Date: Tue, 05 Mar 2013 12:56:19 -0500 Subject: collaborative editing environments Message-ID: <513631C3.2000901@harvee.org> I finally have an intern helping me with my various accessibility projects. We need to do pair programming so he can write the code in my head that I can't express by broken hand or speech recognition (yet). The best technique with come up with so far is to use putty sessions with the same layout and use dtach into one emacs. Nonideal but it kind of sort of works after fashion. we are constrained that neither of us will poke holes in our firewalls to allow a peer-to-peer system to work so we will need a third system intermediary. What would be ideal is some sort of cloud-based collaborative editor/IDE with local storage capability. Revision control to be handled individually to a common repository outside of the IDE/editor. Super best would be an IDE with an API so I can drive the IDE from speech recognition but, I know I'm living in a fantasyland any time I look for accessibility. at the hands one of our projects being adding accessibility controls to an existing editor. Haven't decided which one yet but the leading contender is sublime. gobby it's kind of useful but again, it requires firewall holes or in intermediary that appears to have several shortcomings.also, according to folks I met on IRC, the developers disappeared from IRC about 18 months ago and there's been no development on the project since then. so, what have your experiences been with collaborative environments? From davea at davea.name Tue Mar 5 13:38:08 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 13:38:08 -0500 Subject: collaborative editing environments In-Reply-To: <513631C3.2000901@harvee.org> References: <513631C3.2000901@harvee.org> Message-ID: <51363B90.9000208@davea.name> On 03/05/2013 12:56 PM, Eric Johansson wrote: > I finally have an intern helping me with my various accessibility > projects. We need to do pair programming so he can write the code in my > head that I can't express by broken hand or speech recognition (yet). > > The best technique with come up with so far is to use putty sessions > with the same layout and use dtach into one emacs. Nonideal but it kind > of sort of works after fashion. we are constrained that neither of us > will poke holes in our firewalls to allow a peer-to-peer system to work > so we will need a third system intermediary. Call that intermediary the "host" machine. If host is running on a Linux box, you could run 'screen' or one of its variants (such as tmux). Screen lets you have multiple consoles run through one ssh session, and presents them on your remote as one console. Keystrokes let you switch which console you're connected to at the moment. And another user can be given permissions to see exactly the same screen session. So you can chat on one console, and emacs on another, all within the same screen. Naturally, you can run multiple screens, on independent ssh sessions, if that suits you better. No experience accessing it from Windows, but putty will probably do it. I've done remote collaboration this way, while using a satellite connection that's hopeless for gui environments. You might also want to check out synergy, which manages remote keyboard, mouse and clipboard for Linux. -- DaveA From esj at harvee.org Tue Mar 5 13:54:19 2013 From: esj at harvee.org (Eric Johansson) Date: Tue, 05 Mar 2013 13:54:19 -0500 Subject: collaborative editing environments In-Reply-To: <51363B90.9000208@davea.name> References: <513631C3.2000901@harvee.org> <51363B90.9000208@davea.name> Message-ID: <51363F5B.8040104@harvee.org> On 3/5/2013 1:38 PM, Dave Angel wrote: > On 03/05/2013 12:56 PM, Eric Johansson wrote: >> I finally have an intern helping me with my various accessibility >> projects. We need to do pair programming so he can write the code in my >> head that I can't express by broken hand or speech recognition (yet). >> >> The best technique with come up with so far is to use putty sessions >> with the same layout and use dtach into one emacs. > > > Nonideal but it kind >> of sort of works after fashion. we are constrained that neither of us >> will poke holes in our firewalls to allow a peer-to-peer system to work >> so we will need a third system intermediary. > > Call that intermediary the "host" machine. I prefer to think of it as a proxy or relay host. :-) In my perfect world, it would host no data, only relay traffic between a group of users. > > If host is running on a Linux box, you could run 'screen' or one of > its variants (such as tmux). Screen lets you have multiple consoles > run through one ssh session, and presents them on your remote as one > console. Keystrokes let you switch which console you're connected to > at the moment. And another user can be given permissions to see > exactly the same screen session. So you can chat on one console, and > emacs on another, all within the same screen. Naturally, you can run > multiple screens, on independent ssh sessions, if that suits you better. Been there, done that and I will tell you that if you are see using speech recognition, it's the fourth closest definition to hell I can possibly think of. in band keystrokes always get in the way because some application makes use of them. If they are sufficiently secure to not interfere, then they are bitch to remember. ideally, there would be an out of band API that I could drive from my speech recognition command extension environment and control the connection multiplexer. This is another reason for a local editor, it's easier to speech enable when the environment is nearby. I will thank you for this because you reminded me that team viewer didn't suck too bad and my intern could be the one with the live editor and I'm just watching and commenting over Skype > > No experience accessing it from Windows, but putty will probably do it. > it could. > I've done remote collaboration this way, while using a satellite > connection that's hopeless for gui environments. fortunately, I'm only going as far as Estonia which is reasonably well connected From faraz at squashclub.org Tue Mar 5 15:09:10 2013 From: faraz at squashclub.org (faraz at squashclub.org) Date: Tue, 5 Mar 2013 12:09:10 -0800 (PST) Subject: Controlling number of zeros of exponent in scientific notation Message-ID: Instead of: 1.8e-04 I need: 1.8e-004 So two zeros before the 4, instead of the default 1. From davea at davea.name Tue Mar 5 15:56:26 2013 From: davea at davea.name (Dave Angel) Date: Tue, 05 Mar 2013 15:56:26 -0500 Subject: Controlling number of zeros of exponent in scientific notation In-Reply-To: References: Message-ID: <51365BFA.4020102@davea.name> On 03/05/2013 03:09 PM, faraz at squashclub.org wrote: > Instead of: > > 1.8e-04 > > I need: > > 1.8e-004 > > So two zeros before the 4, instead of the default 1. > You could insert a zero two characters before the end, num = "1.8e-04" num = num[:-2] + "0" + num[-2:] But to get closer to your problem, could you give some background? What version of Python, what type is this "number" before you convert it to a string, how are you converting it? If the type supports variable precision, then what precision range are you interested in supporting? A sample program that produces the wrong output, but going through all the appropriate steps would be useful. Show what values you start with, how they get converted, and what you'd like to happen. What do you want to happen if the number is actually 1.8e-178 ? How about 1.8e-1488 ? -- DaveA From tjreedy at udel.edu Wed Mar 6 00:45:10 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 00:45:10 -0500 Subject: Controlling number of zeros of exponent in scientific notation In-Reply-To: References: Message-ID: On 3/5/2013 3:09 PM, faraz at squashclub.org wrote: > Instead of: > 1.8e-04 > I need: > 1.8e-004 > > So two zeros before the 4, instead of the default 1. The standard e and g float formats do not give you that kind of control over the exponent. You have to write code that forms the string you want. You can put that in a simple function or make a class with a __format__ method to tie into the new format() and str.format system. >>> class myfloat(float): def __format__(self, spec): return '3.14' >>> x = myfloat(1.4) >>> x 1.4 >>> format(x, '') '3.14' >>> '{}'.format(x) '3.14' You could write __format__ to use standard format specs and then adjust: def __format__(self, spec): s = float.__format__(self, spec) return s or generate the pieces of the string yourself, possibly using a custom spec, as opposed to the standard spec. Notice this example from the manual: ''' Using type-specific formatting: >>> import datetime >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58) >>> '{:%Y-%m-%d %H:%M:%S}'.format(d) '2010-07-04 12:15:58' ''' This works because datetime.datetime and a .__format__ that interprets a highly customized format spec. You could customize myfloat's spec to add a value for the exponent width. Your example above might be '8.1.3e' instead of the standard '7.1e' Standard, real: >>> format(1.8e-4, '7.1e') '1.8e-04' Custom, hypothetical: >>> format(myfloat(1.8e-4), '8.1.3e') '1.8e-004' Dave already suggested how you could write part of .__format__ to make the latter be real also. -- Terry Jan Reedy From roy at panix.com Wed Mar 6 09:03:43 2013 From: roy at panix.com (Roy Smith) Date: Wed, 06 Mar 2013 09:03:43 -0500 Subject: Controlling number of zeros of exponent in scientific notation References: Message-ID: In article , faraz at squashclub.org wrote: > Instead of: > > 1.8e-04 > > I need: > > 1.8e-004 > > So two zeros before the 4, instead of the default 1. Just out of curiosity, what's the use case here? From wxjmfauth at gmail.com Wed Mar 6 10:16:16 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 6 Mar 2013 07:16:16 -0800 (PST) Subject: Controlling number of zeros of exponent in scientific notation References: Message-ID: <4b8cc806-3065-404a-9f6f-dadafe895df9@i5g2000vbk.googlegroups.com> On 6 mar, 15:03, Roy Smith wrote: > In article , > > ?fa... at squashclub.org wrote: > > Instead of: > > > 1.8e-04 > > > I need: > > > 1.8e-004 > > > So two zeros before the 4, instead of the default 1. > > Just out of curiosity, what's the use case here? ------ >>> from vecmat6 import * >>> from svdecomp6 import * >>> from vmio6 import * >>> mm = NewMat(3, 2) >>> mm[0][0] = 1.0; mm[0][1] = 2.0e-178 >>> mm[1][0] = 3.0; mm[1][1] = 4.0e-1428 >>> mm[2][0] = 5.0; mm[2][1] = 6.0 >>> pr(mm, 'mm =') mm = ( 1.00000e+000 2.00000e-178 ) ( 3.00000e+000 0.00000e+000 ) ( 5.00000e+000 6.00000e+000 ) >>> aa, vv, bbt = SVDecompFull(mm) >>> pr(aa, 'aa =') aa = ( 3.04128e-001 -8.66366e-002 ) ( 9.12385e-001 -2.59910e-001 ) ( -2.73969e-001 -9.61739e-001 ) >>> pr(bbt, 'bbt =') bbt = ( 7.12974e-001 -7.01190e-001 ) ( -7.01190e-001 -7.12974e-001 ) >>> rr = MatMulMatMulMat(aa, vv, bbt) >>> pr(rr, 'rr =') rr = ( 1.00000e+000 -1.38778e-015 ) ( 3.00000e+000 -4.44089e-016 ) ( 5.00000e+000 6.00000e+000 ) >>> jmf From Russ.Paielli at gmail.com Wed Mar 6 14:11:44 2013 From: Russ.Paielli at gmail.com (Russ P.) Date: Wed, 6 Mar 2013 11:11:44 -0800 (PST) Subject: Controlling number of zeros of exponent in scientific notation In-Reply-To: References: Message-ID: <984652de-218f-4fc9-af4d-f939a7f8ad57@googlegroups.com> One possibility is to form the string as usual, split on the "e", format each part separately, then rejoin with an "e". On Tuesday, March 5, 2013 12:09:10 PM UTC-8, fa... at squashclub.org wrote: > Instead of: > > > > 1.8e-04 > > > > I need: > > > > 1.8e-004 > > > > So two zeros before the 4, instead of the default 1. From galois271 at gmail.com Tue Mar 5 15:09:38 2013 From: galois271 at gmail.com (Chuck) Date: Tue, 5 Mar 2013 12:09:38 -0800 (PST) Subject: Config & ConfigParser Message-ID: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> I'm curious about using configuration files. Can someone tell me how they are used? I'm writing a podcast catcher and would like to set up some default configurations, e.g. directory, etc Other than default directory, what are some of the things that are put in a configuration file? They don't seem to teach you this kind of stuff in school. :( Thanks! From python.list at tim.thechases.com Tue Mar 5 16:17:07 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 5 Mar 2013 15:17:07 -0600 Subject: Config & ConfigParser In-Reply-To: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> Message-ID: <20130305151707.1d72a68d@bigbox.christie.dr> On 2013-03-05 12:09, Chuck wrote: > I'm curious about using configuration files. Can someone tell me > how they are used? I'm writing a podcast catcher and would like > to set up some default configurations, e.g. directory, etc Other > than default directory, what are some of the things that are put in > a configuration file? Just looking at my hpodder config file, you can have all sorts of things in here. You might have a root folder, but then each feed could be configured to a particular sub-folder. You might have a cache location you download to, and only move them to the final destination after they've downloaded completely. You might have some check more frequently than others. You might have it execute an external utility (such as id3v2) to transform various ID3 information based on information in the feed. If you're downloading in multiple threads, you might have specify the number of threads it can use. If you are using "curl" under the covers, you might limit the transfer-rate so it doesn't suck up your bandwidth. If you display anything, you might allow for suppressing the display, formatting that display, or controlling whether it uses color. If you track download errors, you might specify how many failures constitute a "don't bother retrying this item" or how many days/hours you need to wait until you actually retry. You can even have it act as your data-store for holding the URLs to the RSS feeds, perhaps a readable name (to override what's in the feed), along with formatting. So a more complex .ini might look something like [general] root=/home/chuck/Music/Podcasts cache=/tmp/podchuck threads=4 rate=50k color=auto [feed "http://feeds.5by5.tv/webahead"] display-name=The Web Ahead" location=%(root)s/WebAhead/$FILENAME transform=id3v2 -a "WebAhead" -t "$EPTITLE" "$FILENAME" [feed "http://www.radiolab.org/feeds/podcast"] location=/path/to/someplace/else/$FILENAME transform=id3v2 -a "Radio Lab" -t "$EPTITLE" "$FILENAME" -tkc From galois271 at gmail.com Tue Mar 5 18:58:39 2013 From: galois271 at gmail.com (Chuck) Date: Tue, 5 Mar 2013 15:58:39 -0800 (PST) Subject: Config & ConfigParser In-Reply-To: References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> Message-ID: <8a24db13-b599-4a9f-a98f-5e0d256aeee5@googlegroups.com> Thanks Tim! So much stuff I haven't thought of before. Out of curiosity, what's the benefit of caching the download, instead of downloading to the final destination? So much stuff they never teach you school. So much theory & not enough practice. :( From python.list at tim.thechases.com Tue Mar 5 19:15:20 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 5 Mar 2013 18:15:20 -0600 Subject: Config & ConfigParser In-Reply-To: <8a24db13-b599-4a9f-a98f-5e0d256aeee5@googlegroups.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <8a24db13-b599-4a9f-a98f-5e0d256aeee5@googlegroups.com> Message-ID: <20130305181520.3f8cb10c@bigbox.christie.dr> On 2013-03-05 15:58, Chuck wrote: > Thanks Tim! So much stuff I haven't thought of before. Out of > curiosity, what's the benefit of caching the download, instead of > downloading to the final destination? If your connection gets interrupted, the server goes down, etc, you have a partial download. If you've put it directly in the download path, your other programs see this partial download. However if your program can resume the download where it left off, once it's completed successfully, it can atomically move the file to your download location. Thus your other programs only ever see all-or-nothing in the download directory. -tkc From steve+comp.lang.python at pearwood.info Tue Mar 5 23:04:29 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 04:04:29 GMT Subject: Config & ConfigParser References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <8a24db13-b599-4a9f-a98f-5e0d256aeee5@googlegroups.com> Message-ID: <5136c04c$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 05 Mar 2013 18:15:20 -0600, Tim Chase wrote: > On 2013-03-05 15:58, Chuck wrote: >> Thanks Tim! So much stuff I haven't thought of before. Out of >> curiosity, what's the benefit of caching the download, instead of >> downloading to the final destination? > > If your connection gets interrupted, the server goes down, etc, you have > a partial download. If you've put it directly in the download path, > your other programs see this partial download. However if your program > can resume the download where it left off, once it's completed > successfully, it can atomically move the file to your download location. > Thus your other programs only ever see all-or-nothing in the download > directory. That's not really a *cache* though. Personally, I find programs that do that sort of cleverness annoying rather than helpful. More often than not, they are buggy and fail to clean up after themselves if the download is interrupted, so the secret download directory ends up filled with junk: cat-video27~ cat-video27-1~ cat-video27-2~ cat-video27-3~ sort of thing. Another problem with this tactic is that it makes it unnecessarily difficult to watch progress of the download, except via the application's official user interface. (If it gives you any interface for watching download progress, which is may not.) You have to locate the secret download directory, work out what file name the app is using for the temporary file (many apps obfuscate the file name), then watch that file grow until it suddenly disappears, at which point you then have to change directories to see if it reappeared where you actually wanted it to be, or was just deleted by something else. A third problem: instead of having to worry about having enough disk space in one location, now you have to worry about having enough disk space in *two* locations. I've even see a program download a large file into the temp location, *unsuccessfully* try to copy it into the final location, then delete the temp version. Yet another problem: websites sometimes lie about the size of some files. So when you download them, the actual file ends (say) one byte short of what the webserver claims. There's nothing wrong with the file, it is actually complete, or at least recoverable (many formats, like JPEG, are remarkably resistant to damage), but your app will think it never completes and either never move it to the final destination, or worse, keep trying to download it over and over and over again. Finally, moving from the temp directory to the final location is not necessarily an atomic operation. If it crosses file system boundaries, it is a two-step process. I think that the KISS principle applies here. If the user tells your app to download in some location, your app should download in that location. -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 5 22:31:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 03:31:09 GMT Subject: Config & ConfigParser References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> Message-ID: <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 05 Mar 2013 12:09:38 -0800, Chuck wrote: > I'm curious about using configuration files. Can someone tell me how > they are used? I'm writing a podcast catcher and would like to set up > some default configurations, e.g. directory, etc Other than default > directory, what are some of the things that are put in a configuration > file? They don't seem to teach you this kind of stuff in school. :( I think that you are doing this backwards. You shouldn't start with a question: "I want a configuration file! What should I put in it?" and then try to invent a need for configuration settings to put in the file. You start with the need, and end with the conclusion: "I need these configuration settings. I'll put them in a config file." What configuration settings does your podcast catcher software need? What makes you think it needs any? Don't over-engineer your application from the start. Begin with the simplest thing that works, and go from there. -- Steven From rosuav at gmail.com Tue Mar 5 23:05:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Mar 2013 15:05:18 +1100 Subject: Config & ConfigParser In-Reply-To: <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 6, 2013 at 2:31 PM, Steven D'Aprano wrote: > What configuration settings does your podcast catcher software need? What > makes you think it needs any? Don't over-engineer your application from > the start. Begin with the simplest thing that works, and go from there. Agreed. The way I generally do these things is to simply gather the config entries into a block of literal assignments at the top of the program: host = "ftp" port = 21 proxy = "192.168.0.3:81" user = "transfers" password = "secret" >From there, it's easy to decide whether to make them into command-line parameters, a parseable config file, an importable Python script ("from config import *" is an easy and simple way to make that one), or whatever. ChrisA From galois271 at gmail.com Tue Mar 5 23:07:56 2013 From: galois271 at gmail.com (Chuck) Date: Tue, 5 Mar 2013 20:07:56 -0800 (PST) Subject: Config & ConfigParser In-Reply-To: <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <78a2e6bc-e37a-4016-9aba-73561f204986@googlegroups.com> I guess my question was more what is a config.file & why/how do I use one. Thanks From rosuav at gmail.com Tue Mar 5 23:19:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Mar 2013 15:19:53 +1100 Subject: Config & ConfigParser In-Reply-To: <78a2e6bc-e37a-4016-9aba-73561f204986@googlegroups.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> <78a2e6bc-e37a-4016-9aba-73561f204986@googlegroups.com> Message-ID: On Wed, Mar 6, 2013 at 3:07 PM, Chuck wrote: > I guess my question was more what is a config.file & why/how do I use one. > Thanks In its simplest form, a config file is one way to change a program's behaviour without editing the code. They're helpful when you want to be able to run the same program in different ways, or when you want to let someone else change what the program does without having to edit code (and without the changes getting overwritten by a program update). There are innumerable file formats that can be used. ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 5 23:54:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 04:54:58 GMT Subject: Config & ConfigParser References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> <78a2e6bc-e37a-4016-9aba-73561f204986@googlegroups.com> Message-ID: <5136cc21$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 15:19:53 +1100, Chris Angelico wrote: > On Wed, Mar 6, 2013 at 3:07 PM, Chuck wrote: >> I guess my question was more what is a config.file & why/how do I use >> one. Thanks > > In its simplest form, a config file is one way to change a program's > behaviour without editing the code. I don't think that's quite right, because your code has to be changed to read the data from the configuration file in the first place. It doesn't just happen by magic. Essentially, a configuration file is a file that holds configuration data. That data could be anything that makes sense for your program, but you still have to process the data in your program. -- Steven From rosuav at gmail.com Wed Mar 6 01:09:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Mar 2013 17:09:15 +1100 Subject: Config & ConfigParser In-Reply-To: <5136cc21$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> <78a2e6bc-e37a-4016-9aba-73561f204986@googlegroups.com> <5136cc21$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 6, 2013 at 3:54 PM, Steven D'Aprano wrote: > On Wed, 06 Mar 2013 15:19:53 +1100, Chris Angelico wrote: > >> On Wed, Mar 6, 2013 at 3:07 PM, Chuck wrote: >>> I guess my question was more what is a config.file & why/how do I use >>> one. Thanks >> >> In its simplest form, a config file is one way to change a program's >> behaviour without editing the code. > > I don't think that's quite right, because your code has to be changed to > read the data from the configuration file in the first place. It doesn't > just happen by magic. Sure, but once you've made your code read from the config file, you can then edit the file only and it changes the program's actions. Of course, that's an *incredibly* broad description; amongst its coverage are such diverse elements as Apache reading an HTML file to serve, CPython reading a .py file, and the ROM BIOS reading a boot sector and jumping to it... but based on the OP's question I couldn't really be any more specific. ChrisA From neilc at norwich.edu Thu Mar 7 11:18:23 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 7 Mar 2013 16:18:23 GMT Subject: Config & ConfigParser References: <61520ad1-9e3c-4eec-b1d9-8a9d8fc7bf0c@googlegroups.com> <5136b87c$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-03-06, Chris Angelico wrote: > On Wed, Mar 6, 2013 at 2:31 PM, Steven D'Aprano > wrote: >> What configuration settings does your podcast catcher software >> need? What makes you think it needs any? Don't over-engineer >> your application from the start. Begin with the simplest thing >> that works, and go from there. > > Agreed. The way I generally do these things is to simply gather the > config entries into a block of literal assignments at the top of the > program: > > host = "ftp" > port = 21 > proxy = "192.168.0.3:81" > user = "transfers" > password = "secret" I find it useful to stuff my config info in a class object; It is prettier than ALLCAPS, and also makes it simple to create and use new configurations without erasing or commenting out the old one. class Config: host = "ftp" port = 21 proxy = "192.168.0.3:81" user = "transfers" password = "secret" How much to engineer stuff is up to you. -- Neil Cerutti From olsr.kamal at gmail.com Tue Mar 5 18:07:39 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Tue, 5 Mar 2013 15:07:39 -0800 (PST) Subject: comment prendre la valeur de couleur de point dans canvas python tkinter Message-ID: <4503833d-6ac1-4736-a59f-870457d8f8c2@googlegroups.com> comment prendre la valeur de couleur de point dans canvas python tkinter comme : (x,y).cget('bg')!='white'??????? From techgeek201 at gmail.com Tue Mar 5 18:31:13 2013 From: techgeek201 at gmail.com (eli m) Date: Tue, 5 Mar 2013 15:31:13 -0800 (PST) Subject: Input wont work with if statement if it has a space Message-ID: Hi guys, i have a program like this: (A lot of code is not included) run = 0 while run == 0: raw_input("Type in a function:") if function == "Example": print ("Hello World!") else: print ("blah blah blah") The problem is that whenever i type in example with a space after it then it prints the else statement. My question is, how do i get it to except input with spaces? From techgeek201 at gmail.com Tue Mar 5 18:33:33 2013 From: techgeek201 at gmail.com (eli m) Date: Tue, 5 Mar 2013 15:33:33 -0800 (PST) Subject: Input wont work with if statement if it has a space In-Reply-To: References: Message-ID: On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote: > Hi guys, i have a program like this: (A lot of code is not included) > > run = 0 > > while run == 0: > > raw_input("Type in a function:") > > if function == "Example": > > print ("Hello World!") > > else: > > print ("blah blah blah") > > > > The problem is that whenever i type in example with a space after it then it prints the else statement. > > > > My question is, how do i get it to except input with spaces? oops i meant function = raw_input("Type in a function:") From emile at fenx.com Tue Mar 5 18:47:31 2013 From: emile at fenx.com (emile) Date: Tue, 05 Mar 2013 15:47:31 -0800 Subject: Input wont work with if statement if it has a space In-Reply-To: References: Message-ID: On 03/05/2013 03:33 PM, eli m wrote: > On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote: >> Hi guys, i have a program like this: (A lot of code is not included) >> >> run = 0 >> >> while run == 0: >> >> function = raw_input("Type in a function:") >> >> if function == "Example": whenever function isn't _exactly_ "Example" the else clause executes. If you want to catch forms of example you might try: if function.strip().upper() == "EXAMPLE": Emile >> >> print ("Hello World!") >> >> else: >> >> print ("blah blah blah") >> >> >> >> The problem is that whenever i type in example with a space after it then it prints the else statement. >> >> >> >> My question is, how do i get it to except input with spaces? > > oops i meant function = raw_input("Type in a function:") > From techgeek201 at gmail.com Tue Mar 5 20:50:32 2013 From: techgeek201 at gmail.com (eli m) Date: Tue, 5 Mar 2013 17:50:32 -0800 (PST) Subject: Input wont work with if statement if it has a space In-Reply-To: References: Message-ID: <71e39dc3-1b79-4331-9d4f-eb94c64068ce@googlegroups.com> On Tuesday, March 5, 2013 3:47:31 PM UTC-8, emile wrote: > On 03/05/2013 03:33 PM, eli m wrote: > > > On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote: > > >> Hi guys, i have a program like this: (A lot of code is not included) > > >> > > >> run = 0 > > >> > > >> while run == 0: > > >> > > >> function = raw_input("Type in a function:") > > >> > > >> if function == "Example": > > > > whenever function isn't _exactly_ "Example" the else clause executes. > > > > If you want to catch forms of example you might try: > > > > if function.strip().upper() == "EXAMPLE": > > > > Emile > > > > > > > > > > >> > > >> print ("Hello World!") > > >> > > >> else: > > >> > > >> print ("blah blah blah") > > >> > > >> > > >> > > >> The problem is that whenever i type in example with a space after it then it prints the else statement. > > >> > > >> > > >> > > >> My question is, how do i get it to except input with spaces? > > > > > > oops i meant function = raw_input("Type in a function:") > > > Thank you! From techgeek201 at gmail.com Tue Mar 5 20:50:32 2013 From: techgeek201 at gmail.com (eli m) Date: Tue, 5 Mar 2013 17:50:32 -0800 (PST) Subject: Input wont work with if statement if it has a space In-Reply-To: References: Message-ID: <71e39dc3-1b79-4331-9d4f-eb94c64068ce@googlegroups.com> On Tuesday, March 5, 2013 3:47:31 PM UTC-8, emile wrote: > On 03/05/2013 03:33 PM, eli m wrote: > > > On Tuesday, March 5, 2013 3:31:13 PM UTC-8, eli m wrote: > > >> Hi guys, i have a program like this: (A lot of code is not included) > > >> > > >> run = 0 > > >> > > >> while run == 0: > > >> > > >> function = raw_input("Type in a function:") > > >> > > >> if function == "Example": > > > > whenever function isn't _exactly_ "Example" the else clause executes. > > > > If you want to catch forms of example you might try: > > > > if function.strip().upper() == "EXAMPLE": > > > > Emile > > > > > > > > > > >> > > >> print ("Hello World!") > > >> > > >> else: > > >> > > >> print ("blah blah blah") > > >> > > >> > > >> > > >> The problem is that whenever i type in example with a space after it then it prints the else statement. > > >> > > >> > > >> > > >> My question is, how do i get it to except input with spaces? > > > > > > oops i meant function = raw_input("Type in a function:") > > > Thank you! From xer0925 at gmail.com Tue Mar 5 19:54:45 2013 From: xer0925 at gmail.com (Rex Macey) Date: Tue, 5 Mar 2013 16:54:45 -0800 (PST) Subject: listbox binding..what is the current selection? Message-ID: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> I have a listbox with two strings "Fixed" and "Random". It is bound by the following statement: lbLengthtype.bind('',set_lengthtype) Here's the beginning of the set_lengthtype code: def set_lengthtype(event=None): s=lbLengthtype.get(tk.ACTIVE) print(s) ..... The print(s) statement is for debugging. If 'Random' was selected and the user clicks 'Fixed', then Random will print. I would like to know what the user just selected, not what was selected before the user clicked. How can I determine the current selection? Thanks. From rantingrickjohnson at gmail.com Tue Mar 5 20:26:12 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 5 Mar 2013 17:26:12 -0800 (PST) Subject: listbox binding..what is the current selection? In-Reply-To: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> References: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> Message-ID: <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> On Tuesday, March 5, 2013 6:54:45 PM UTC-6, Rex Macey wrote: > I have a listbox with two strings "Fixed" and "Random". > [...] Here's the beginning of the set_lengthtype code: > > def set_lengthtype(event=None): > s=lbLengthtype.get(tk.ACTIVE) > print(s) > ..... > > The print(s) statement is for debugging. If 'Random' was > selected and the user clicks 'Fixed', then Random will > print. I would like to know what the user just selected, > not what was selected before the user clicked. How can I > determine the current selection? Thanks. Use "listbox.nearest(event.y)" instead of "get(ACTIVE"). And maybe you should spend some time reading the docs eh? http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html From xer0925 at gmail.com Wed Mar 6 23:38:22 2013 From: xer0925 at gmail.com (Rex Macey) Date: Wed, 6 Mar 2013 20:38:22 -0800 (PST) Subject: listbox binding..what is the current selection? In-Reply-To: <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> References: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> Message-ID: <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> Thanks. I have spent time with the docs, at least with the Python v3.3 and tkinter v8.5 (pdf). I wish they had more examples. My approach is to browse the docs, try a program, fail, read the docs, try again. When I can't figure it out, I post. I appreciate the help. On Tuesday, March 5, 2013 8:26:12 PM UTC-5, Rick Johnson wrote: > On Tuesday, March 5, 2013 6:54:45 PM UTC-6, Rex Macey wrote: > > > I have a listbox with two strings "Fixed" and "Random". > > > [...] Here's the beginning of the set_lengthtype code: > > > > > > def set_lengthtype(event=None): > > > s=lbLengthtype.get(tk.ACTIVE) > > > print(s) > > > ..... > > > > > > The print(s) statement is for debugging. If 'Random' was > > > selected and the user clicks 'Fixed', then Random will > > > print. I would like to know what the user just selected, > > > not what was selected before the user clicked. How can I > > > determine the current selection? Thanks. > > > > Use "listbox.nearest(event.y)" instead of "get(ACTIVE"). And maybe you should spend some time reading the docs eh? > > > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html From rantingrickjohnson at gmail.com Thu Mar 7 00:49:08 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 21:49:08 -0800 (PST) Subject: listbox binding..what is the current selection? In-Reply-To: <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> References: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> Message-ID: On Wednesday, March 6, 2013 10:38:22 PM UTC-6, Rex Macey wrote: > I have spent time with the docs, at least with the Python > v3.3 and tkinter v8.5 (pdf). Could you post links to the documents you are reading please? Actually when i said "read the docs" i did not mean the offical Python docs on Tkinter (because, IMHO, they are woefully inadequate). I actually meant "read some online tutorials". The link i gave you is really more of a reference than a tutorial. It's my go-to reference when i can't remember the behavior of "this" or "that" method, or the spelling of "this" or "that" event sequence. Here is another link that is much more of a tutorial. http://effbot.org/tkinterbook/tkinter-whats-tkinter.htm > I wish they had more examples. Yes me too! Examples speak much louder than mere words. Of course, ONLY if the examples are good examples. Maybe we could combine my ability to write good examples with your ability to judge the noob worthiness of such examples and contribute something positive to this community of ingrates. (please don't mis-interpret the theatrical verbiage, i am, in fact, quite serious) > My approach is to browse the docs, try a program, fail, > read the docs, try again. When I can't figure it out, I > post. That's a wise and considerate path. Considerate both for yourself and others. ============================================================ The path to enlightenment ============================================================ The temptation to run and ask somebody for an answer is *VERY*, well, tempting. The problem is, the more you ask and receive *easy* answers, the more you become dependent on your teacher and not yourself. Luckily for me (although i was unaware of the benefit at the time) i was oblivious to online help forms when i learned programming; forcing me to be self-reliant when learning. It was just me, some badly written docs, and a text editor. :-) After lots of trial and error and many a smashed keyboard, i emerged from under my rock with a deep knowledge that i don't believe i could have attained by having someone spoon feed me the answers. It seems that when you *DO* find yourself in a wet paper bag that you can't seem to mentally punch yourself out of, and you are forced to get outside input, the last thing you need is people "gift wrapping" answers for you. A wise teacher will give you a few clues and then aim you in the correct direction, leaving you to find the exact path to enlightenment. Learning "how to problem solve" is much more important skill than "learning how to solve a problem"; the old "teach a man to fish..." thing. ============================================================ Request for your personal experiences: ============================================================ Since you are new to Tkinter i wonder if you can give some insights into the specific troubles you are encountering. I have long since forgotten most of the troubles i experienced. This would be a good chance to document the issues with the documents. ============================================================ Learning GUI's cuts you twice! ============================================================ Learning GUI's for the first time is very difficult because before you can learn the API of the current GUI library, you must first learn what a "EditText" is, and what a "StaticText" is, and a "ProgressBar", and a "NoteBook", and abstract things like "InputEvents", and how to bind "inputEvents", and "GeometryManagment"; and blah, blah, blah. This first step is where most GUI tutorials fail. They try to present both the widgets AND the code to control them simultaneously. It's no wonder the student becomes bewildered! I believe the first step should involve NO code or even code examples. The first step should be mainly a visual experience combined with interactive delving into the intricacies of what "actions" each widget will expose; using only natural language and visuals to describe the actions. But even when GUI tuts follow this wise progression they fail to utilize the power of visualization, and instead focus on pages and pages of boring text. The second step is learning the actual methods of the widgets and how to link code to actions. ============================================================ Morals of My Experience: ============================================================ Looking back i believe the Tkinter learning path is flawed in to general ways. 1. The official docs are woefully inadequate. Which could be solved by writing better documentation, or simply, by linking to a few of the existing good outside documentation. The two links i posted offer the best of both worlds (reference and tutorial[1]) But then, there are all the issues of poor examples around the web. I found myself being thrown into fits of confusion by reading documentations or tutorials that seemed to conflict with one another. """Misleading documentation can be more devastating than missing documentation.""" 2. The Tkinter API is asinine, inconsistent, and full of multiplicities. I know that sounds unfair but it *IS* true. Yes, Tkinter is one of the simplest Python GUI's to learn, and it has the benefit of being in the Python stdlib, however, it has many issues[2] that should have been resolved long ago, and could be resolved today if i could convince the "keepers of the source" to engage in healthy discussion of these specifics. ============================================================ REFERENCES: ============================================================ [1] Although the tutorial site has a few confusing examples and fails to cover the new ttk widgets. [2] Plus, it is missing simple functionalities like "auto-scrollbars". (although this is a direct result of being a slave to the Tk:TCL folks. From wrw at mac.com Thu Mar 7 10:13:16 2013 From: wrw at mac.com (William Ray Wing) Date: Thu, 07 Mar 2013 10:13:16 -0500 Subject: listbox binding..what is the current selection? In-Reply-To: <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> References: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> Message-ID: <040756B3-9346-48AF-9F16-E24BB9D51515@mac.com> On Mar 6, 2013, at 11:38 PM, Rex Macey wrote: > Thanks. I have spent time with the docs, at least with the Python v3.3 and tkinter v8.5 (pdf). I wish they had more examples. My approach is to browse the docs, try a program, fail, read the docs, try again. When I can't figure it out, I post. I appreciate the help. > > With apologies for jumping into the middle of this discussion, but I've found the most helpful tkinter v8.5 docs to be the set at New Mexico tech: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html Seem quite complete and in particular, starting at section 28, they are quite detailed in their explanation of the ttk themed widgets. -Bill From rantingrickjohnson at gmail.com Thu Mar 7 12:03:23 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 7 Mar 2013 09:03:23 -0800 (PST) Subject: listbox binding..what is the current selection? In-Reply-To: References: <78aa4ba0-a722-494c-b14b-2aa012dc01ae@googlegroups.com> <695d20a9-26e2-4b46-8fb2-0152d435b68f@googlegroups.com> <8fd527bc-0f3f-4616-9512-3497c0858c2c@googlegroups.com> Message-ID: On Thursday, March 7, 2013 9:13:16 AM UTC-6, William Ray Wing wrote: > With apologies for jumping into the middle of this > discussion, but I've found the most helpful tkinter v8.5 > docs to be the set at New Mexico tech: Well these are free and open forums the last time i checked. Don't worry, nobody is going to get upset because you offered your opinions. I mean, the worst think that could happen is if someone offers up the exact same information that had already been offered early in the thread because they were too lazy to read the thread in full, and now they look like a complete boob ( a helpful boob, but a boob none-the-less). But that's just a "crazy" hypothetical situation. You would never do that. So no need to worry. From nikos.gr33k at gmail.com Wed Mar 6 02:45:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 5 Mar 2013 23:45:57 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values Message-ID: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> I'am using this snipper to read a current directory and insert all filenames into a databse and then display them. But what happens when files are get removed form the directory? The inserted records into databse remain. How can i update the databse to only contain the existing filenames without losing the previous stored data? Here is what i ahve so far: ================================== path = "/home/nikos/public_html/data/files/" #read the containing folder and insert new filenames for result in os.walk(path): for filename in result[2]: try: #find the needed counter for the page URL cur.execute('''SELECT URL FROM files WHERE URL = %s''', (filename,) ) data = cur.fetchone() #URL is unique, so should only be one if not data: #first time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (URL, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, date) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) ====================== Thank you. From lele at metapensiero.it Wed Mar 6 03:19:06 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 06 Mar 2013 09:19:06 +0100 Subject: sync databse table based on current directory data without losign previous values References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: <87zjyhhret.fsf@nautilus.nautilus> ????? ???33? writes: > How can i update the databse to only contain the existing filenames without losing the previous stored data? Basically you need to keep a list (or better, a set) containing all current filenames that you are going to insert, and finally do another "inverse" loop where you scan all the records and delete those that are not present anymore. Of course, this assume you have a "bidirectional" identity between the filenames you are loading and the records you are inserting, which is not the case in the code you show: > #read the containing folder and insert new filenames > for result in os.walk(path): > for filename in result[2]: Here "filename" is just that, not the full path: this could result in collisions, if your are actually loading a *tree* instead of a flat directory, that is multiple source files are squeezed into a single record in your database (imagine "/foo/index.html" and "/foo/subdir/index.html"). With that in mind, I would do something like the following: # Compute a set of current fullpaths current_fullpaths = set() for root, dirs, files in os.walk(path): for fullpath in files: current_fullpaths.add(os.path.join(root, file)) # Load'em for fullpath in current_fullpaths: try: #find the needed counter for the page URL cur.execute('''SELECT URL FROM files WHERE URL = %s''', (fullpath,) ) data = cur.fetchone() #URL is unique, so should only be one if not data: #first time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (URL, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, date) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) # Delete spurious cur.execute('''SELECT url FROM files''') for rec in cur: fullpath = rec[0] if fullpath not in current_fullpaths: other_cur.execute('''DELETE FROM files WHERE url = %s''', (fullpath,)) Of course here I am assuming a lot (a typical thing we do to answer your questions :-), in particular that the "url" field content matches the filesystem layout, which may not be the case. Adapt it to your usecase. hope this helps, 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 r32813 at freescale.com Wed Mar 6 05:11:12 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Wed, 6 Mar 2013 10:11:12 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <87zjyhhret.fsf@nautilus.nautilus> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B12EB11@039-SN2MPN1-012.039d.mgd.msft.net> Hello there, I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. Any idea why? >>> for i in range(100000L): ... str=str+"%s"%(i,) ... >>> i=None >>> str=None >>> del i >>> del str From tjreedy at udel.edu Wed Mar 6 05:59:57 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 05:59:57 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <78E1273CA6E76A43BB8830A194FF709B0B12EB11@039-SN2MPN1-012.039d.mgd.msft.net> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <78E1273CA6E76A43BB8830A194FF709B0B12EB11@039-SN2MPN1-012.039d.mgd.msft.net> Message-ID: On 3/6/2013 5:11 AM, Wong Wah Meng-R32813 wrote: > Hello there, > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > I discovered following behavior whereby the python process doesn't > seem to release memory utilized even after a variable is set to None, > and "deleted". I use glance tool to monitor the memory utilized by > this process. Obviously after the for loop is executed, the memory > used by this process has hiked to a few MB. However, after "del" is > executed to both I and str variables, the memory of that process > still stays at where it was. Whether memory freed by deleting an object is returned to and taken by the OS depends on the OS and other factors like like the size and layout of the freed memory, probably the history of memory use, and for CPython, the C compiler's malloc/free implementation. At various times, the Python memory handlers have been rewritten to encourage/facilitate memory return, but Python cannot control the process. > for i in range(100000L): > str=str+"%s"%(i,) > i=None; str=None # not necessary > del i; del str Reusing built-in names for unrelated purposes is generally a bad idea, although the final deletion does restore access to the builtin. -- Terry Jan Reedy From r32813 at freescale.com Wed Mar 6 07:36:04 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Wed, 6 Mar 2013 12:36:04 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <78E1273CA6E76A43BB8830A194FF709B0B12EB11@039-SN2MPN1-012.039d.mgd.msft.net> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B12EC27@039-SN2MPN1-012.039d.mgd.msft.net> Thanks for youre reply. I built python 2.7.1 binary myself on the HP box and I wasn't aware there is any configuration or setup that I need to modify in order to activate or engage the garbage collection (or even setting the memory size used). Probably you are right it leaves it to the OS itself (in this case HP-UX) to clean it up as after python removes the reference to the address of the variables the OS still thinks the python process should still owns it until the process exits. Regards, Wah Meng -----Original Message----- From: Python-list [mailto:python-list-bounces+wahmeng=freescale.com at python.org] On Behalf Of Terry Reedy Sent: Wednesday, March 06, 2013 7:00 PM To: python-list at python.org Subject: Re: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) On 3/6/2013 5:11 AM, Wong Wah Meng-R32813 wrote: > Hello there, > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > I discovered following behavior whereby the python process doesn't > seem to release memory utilized even after a variable is set to None, > and "deleted". I use glance tool to monitor the memory utilized by > this process. Obviously after the for loop is executed, the memory > used by this process has hiked to a few MB. However, after "del" is > executed to both I and str variables, the memory of that process still > stays at where it was. Whether memory freed by deleting an object is returned to and taken by the OS depends on the OS and other factors like like the size and layout of the freed memory, probably the history of memory use, and for CPython, the C compiler's malloc/free implementation. At various times, the Python memory handlers have been rewritten to encourage/facilitate memory return, but Python cannot control the process. > for i in range(100000L): > str=str+"%s"%(i,) > i=None; str=None # not necessary > del i; del str Reusing built-in names for unrelated purposes is generally a bad idea, although the final deletion does restore access to the builtin. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list From bryan.devaney at gmail.com Wed Mar 6 05:25:22 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Wed, 6 Mar 2013 02:25:22 -0800 (PST) Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> Message-ID: <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> On Wednesday, March 6, 2013 10:11:12 AM UTC, Wong Wah Meng-R32813 wrote: > Hello there, > > > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > > > I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. > > > > Any idea why? > > > > >>> for i in range(100000L): > > ... str=str+"%s"%(i,) > > ... > > >>> i=None > > >>> str=None > > >>> del i > > >>> del str Hi, I'm new here so I'm making mistakes too but I know they don't like it when you ask your question in someone else's question. that being said, to answer your question: Python uses a 'garbage collector'. When you delete something, all references are removed from the object in memory, the memory itself will not be freed until the next time the garbage collector runs. When that happens, all objects without references in memory are removed and the memory freed. If you wait a while you should see that memory free itself. From bryan.devaney at gmail.com Wed Mar 6 05:25:22 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Wed, 6 Mar 2013 02:25:22 -0800 (PST) Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> Message-ID: <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> On Wednesday, March 6, 2013 10:11:12 AM UTC, Wong Wah Meng-R32813 wrote: > Hello there, > > > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > > > I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. > > > > Any idea why? > > > > >>> for i in range(100000L): > > ... str=str+"%s"%(i,) > > ... > > >>> i=None > > >>> str=None > > >>> del i > > >>> del str Hi, I'm new here so I'm making mistakes too but I know they don't like it when you ask your question in someone else's question. that being said, to answer your question: Python uses a 'garbage collector'. When you delete something, all references are removed from the object in memory, the memory itself will not be freed until the next time the garbage collector runs. When that happens, all objects without references in memory are removed and the memory freed. If you wait a while you should see that memory free itself. From r32813 at freescale.com Wed Mar 6 07:31:47 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Wed, 6 Mar 2013 12:31:47 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B12EC1A@039-SN2MPN1-012.039d.mgd.msft.net> Apologies as after I have left the group for a while I have forgotten how not to post a question on top of another question. Very sorry and appreciate your replies. I tried explicitly calling gc.collect() and didn't manage to see the memory footprint reduced. I probably haven't left the process idle long enough to see the internal garbage collection takes place but I will leave it idle for more than 8 hours and check again. Thanks! -----Original Message----- From: Python-list [mailto:python-list-bounces+wahmeng=freescale.com at python.org] On Behalf Of Bryan Devaney Sent: Wednesday, March 06, 2013 6:25 PM To: python-list at python.org Cc: python-list at python.org Subject: Re: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) On Wednesday, March 6, 2013 10:11:12 AM UTC, Wong Wah Meng-R32813 wrote: > Hello there, > > > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > > > I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. > > > > Any idea why? > > > > >>> for i in range(100000L): > > ... str=str+"%s"%(i,) > > ... > > >>> i=None > > >>> str=None > > >>> del i > > >>> del str Hi, I'm new here so I'm making mistakes too but I know they don't like it when you ask your question in someone else's question. that being said, to answer your question: Python uses a 'garbage collector'. When you delete something, all references are removed from the object in memory, the memory itself will not be freed until the next time the garbage collector runs. When that happens, all objects without references in memory are removed and the memory freed. If you wait a while you should see that memory free itself. -- http://mail.python.org/mailman/listinfo/python-list From davea at davea.name Wed Mar 6 08:25:34 2013 From: davea at davea.name (Dave Angel) Date: Wed, 06 Mar 2013 08:25:34 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <78E1273CA6E76A43BB8830A194FF709B0B12EC1A@039-SN2MPN1-012.039d.mgd.msft.net> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> <78E1273CA6E76A43BB8830A194FF709B0B12EC1A@039-SN2MPN1-012.039d.mgd.msft.net> Message-ID: <513743CE.4@davea.name> On 03/06/2013 07:31 AM, Wong Wah Meng-R32813 wrote: > Apologies as after I have left the group for a while I have forgotten how not to post a question on top of another question. Very sorry and appreciate your replies. > > I tried explicitly calling gc.collect() and didn't manage to see the memory footprint reduced. I probably haven't left the process idle long enough to see the internal garbage collection takes place but I will leave it idle for more than 8 hours and check again. Thanks! > You're top-posting, which makes things very confusing, since your contribution to the message is out of accepted order. Put your remarks after the part you're commenting on, and delete anything following your message, as it clearly didn't need your comments. Once you've called gc.collect(), there's no point in waiting 8 hours for it to run again. It either triggered the C runtime's logic or it didn't, and running it again won't help unless in the meantime you rearranged the remaining allocated blocks. Accept the fact that not all freeing of memory blocks can possibly make it through to the OS. If they did, we'd have a minimum object size of at least 4k on the Pentium, and larger on some other processors. We'd also have performance that would crawl. So an external tool can only give you a very approximate size for what's going on in your own code. -- DaveA From davea at davea.name Wed Mar 6 08:18:00 2013 From: davea at davea.name (Dave Angel) Date: Wed, 06 Mar 2013 08:18:00 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> Message-ID: <51374208.6020006@davea.name> On 03/06/2013 05:25 AM, Bryan Devaney wrote: > On Wednesday, March 6, 2013 10:11:12 AM UTC, Wong Wah Meng-R32813 wrote: >> Hello there, >> >> >> >> I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. >> >> >> >> I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. >> >> >> > > Python uses a 'garbage collector'. When you delete something, all references are removed from the object in memory, the memory itself will not be freed until the next time the garbage collector runs. When that happens, all objects without references in memory are removed and the memory freed. If you wait a while you should see that memory free itself. > Actually, no. The problem with monitoring memory usage from outside the process is that memory "ownership" is hierarchical, and each hierarchy deals in bigger chunks. So when the CPython runtime calls free() on a particular piece of memory, the C runtime may or may not actually release the memory for use by other processes. Since the C runtime grabs big pieces from the OS, and parcels out little pieces to CPython, a particular big piece can only be freed if ALL the little pieces are free. And even then, it may or may not choose to do so. Completely separate from that are the two mechanisms that CPython uses to free its pieces. It does reference counting, and it does garbage collecting. In this case, only the reference counting is relevant, as when it's done there's no garbage left to collect. When an object is no longer referenced by anything, its count will be zero, and it will be freed by calling the C library function. GC is only interesting when there are cycles in the references, such as when a list contains as one of its elements a tuple, which in turn contains the original list. Sound silly? No, it's quite common once complex objects are created which reference each other. The counts don't go to zero, and the objects wait for garbage collection. OP: There's no need to set to None and also to del the name. Since there's only one None object, keeping another named reference to that object has very little cost. -- DaveA From steve+comp.lang.python at pearwood.info Wed Mar 6 18:34:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 23:34:42 GMT Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> Message-ID: <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 10:11:12 +0000, Wong Wah Meng-R32813 wrote: > Hello there, > > I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. > > I discovered following behavior whereby the python process doesn't seem > to release memory utilized even after a variable is set to None, and > "deleted". I use glance tool to monitor the memory utilized by this > process. Obviously after the for loop is executed, the memory used by > this process has hiked to a few MB. However, after "del" is executed to > both I and str variables, the memory of that process still stays at > where it was. > > Any idea why? Python does not guarantee to return memory to the operating system. Whether it does or not depends on the OS, but as a general rule, you should expect that it will not. >>>> for i in range(100000L): > ... str=str+"%s"%(i,) You should never build large strings in that way. It risks being horribly, horribly slow on some combinations of OS, Python implementation and version. Instead, you should do this: items = ["%s" % i for i in range(100000)] s = ''.join(items) -- Steven From r32813 at freescale.com Thu Mar 7 01:33:23 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Thu, 7 Mar 2013 06:33:23 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> Python does not guarantee to return memory to the operating system. Whether it does or not depends on the OS, but as a general rule, you should expect that it will not. >>>> for i in range(100000L): > ... str=str+"%s"%(i,) You should never build large strings in that way. It risks being horribly, horribly slow on some combinations of OS, Python implementation and version. Instead, you should do this: items = ["%s" % i for i in range(100000)] s = ''.join(items) [] The example is written for illustration purpose. Thanks for pointing out a better way of achieving the same result. Yes it seems so that the OS thinks the piece allocated to Python should not be taken back unless the process dies. :( From rosuav at gmail.com Thu Mar 7 02:19:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 18:19:38 +1100 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: On Thu, Mar 7, 2013 at 5:33 PM, Wong Wah Meng-R32813 wrote: > [] The example is written for illustration purpose. Thanks for pointing out a better way of achieving the same result. Yes it seems so that the OS thinks the piece allocated to Python should not be taken back unless the process dies. :( Don't be too bothered by that. That memory will be reused by Python for subsequent allocations. ChrisA From r32813 at freescale.com Fri Mar 8 04:08:15 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Fri, 8 Mar 2013 09:08:15 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> The problem is my server hits memory usage threshold, and starts giving me errors like Oracle unable to spawn off new session stating Out of Memory error and what not. I won't be bothered much if I have the luxury of available memory for other processes to use. If only if the UNIX understand my concerns and release the allocation when I issue gc.collect() or the gc.collect() takes place. :) On Thu, Mar 7, 2013 at 5:33 PM, Wong Wah Meng-R32813 wrote: > [] The example is written for illustration purpose. Thanks for > pointing out a better way of achieving the same result. Yes it seems > so that the OS thinks the piece allocated to Python should not be > taken back unless the process dies. :( Don't be too bothered by that. That memory will be reused by Python for subsequent allocations. From r32813 at freescale.com Sat Mar 9 03:07:52 2013 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Sat, 9 Mar 2013 08:07:52 +0000 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: <78E1273CA6E76A43BB8830A194FF709B0B157FC9@039-SN2MPN1-013.039d.mgd.msft.net> If the memory usage is continually growing, you have something else that is a problem -- something is holding onto objects. Even if Python is not returning memory to the OS, it should be reusing the memory it has if objects are being freed. -- [] Yes I have verified my python application is reusing the memory (just that it doesn't reduce once it has grown) and my python process doesn't have any issue to run even though it is seen taking up more than 2G in footprint. My problem is capacity planning on the server whereby since my python process doesn't release memory back to the OS, the OS wasn't able to allocate memory when a new process is spawn off. From davea at davea.name Sat Mar 9 06:02:37 2013 From: davea at davea.name (Dave Angel) Date: Sat, 09 Mar 2013 06:02:37 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <78E1273CA6E76A43BB8830A194FF709B0B157FC9@039-SN2MPN1-013.039d.mgd.msft.net> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B157FC9@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: <513B16CD.1030401@davea.name> On 03/09/2013 03:07 AM, Wong Wah Meng-R32813 wrote: > > > Yes I have verified my python application is reusing the memory (just that it doesn't reduce once it has grown) and my python process doesn't have any issue to run even though it is seen taking up more than 2G in footprint. My problem is capacity planning on the server whereby since my python process doesn't release memory back to the OS, the OS wasn't able to allocate memory when a new process is spawn off> So is the server running out of disk space? If not, why not increase the swapfile(s) size? That's what's being held onto, not RAM. If you are short on disk space, and therefore cannot afford to increase the swapfile size, then you may want to plan the Python program's execution around that constraint. Discounting the play-program that started this thread, is it possible that your actual app unnecessarily uses lots of space during one phase of execution, and therefore is saddled with that space at other times? For example, are you using a large list to hold a data file when an iterator would do just as well? If that phase of execution cannot be eliminated, but it's a fleeting time, perhaps that part of the execution can be launched from the main app as a separate process. When the process ends, the memory is freed. -- DaveA From isaac.to at gmail.com Sat Mar 9 10:02:17 2013 From: isaac.to at gmail.com (Isaac To) Date: Sat, 9 Mar 2013 23:02:17 +0800 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) In-Reply-To: <78E1273CA6E76A43BB8830A194FF709B0B157FC9@039-SN2MPN1-013.039d.mgd.msft.net> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B157FC9@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: In general, it is hard for any process to return the memory the OS allocate to it back to the OS, short of exiting the whole process. The only case that this works reliably is when the process allocates a chunk of memory by mmap (which is chosen by libc if it malloc or calloc a large chunk of memory), and that whole chunk is not needed any more. In that case the process can munmap it. Evidently you are not see that in your program. What you allocate might be too small (so libc choose to allocate it using another system call "sbrk"), or that the allocated memory also hold other objects not freed. If you want to reduce the footprint of a long running program that periodically allocates a large chunk of memory, the "easiest" solution is to fork a different process to achieve the computations that needs the memory. That way, you can exit the process after you complete the computation, and at that point all memory allocated to it is guaranteed to be freed to the OS. Modules like multiprocessing probably make the idea sufficiently easy to implement. On Sat, Mar 9, 2013 at 4:07 PM, Wong Wah Meng-R32813 wrote: > > > If the memory usage is continually growing, you have something > else that is a problem -- something is holding onto objects. Even if Python > is not returning memory to the OS, it should be reusing the memory it has > if objects are being freed. > -- > [] Yes I have verified my python application is reusing the memory (just > that it doesn't reduce once it has grown) and my python process doesn't > have any issue to run even though it is seen taking up more than 2G in > footprint. My problem is capacity planning on the server whereby since my > python process doesn't release memory back to the OS, the OS wasn't able to > allocate memory when a new process is spawn off. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Sat Mar 9 14:18:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 9 Mar 2013 19:18:59 +0000 (UTC) Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: On 2013-03-09, Wong Wah Meng-R32813 wrote: Your entire post is in your signature block. Don't do that. Many people have newsreaders or e-mail clinets configured to hide or ignore signature blocks. >Yes I have verified my python application is reusing the memory (just >that it doesn't reduce once it has grown) and my python process >doesn't have any issue to run even though it is seen taking up more >than 2G in footprint. Then there's nothing wrong with Python. >My problem is capacity planning on the server whereby since my python >process doesn't release memory back to the OS, In Unix there is no way to release heap memory (which is what you're talking about) back to the OS except for terminating the process. >the OS wasn't able to allocate memory when a new process is spawn off. You need to either get more memory, change your Python program to use less memory, or have your Python program terminate in order to return memory to the OS. Perhaps you can put the memory hungery portion of your processing into a subprocess that terminates when it's completed its work? -- Grant Edwards grant.b.edwards Yow! Don't hit me!! I'm in at the Twilight Zone!!! gmail.com From roy at panix.com Sat Mar 9 15:04:52 2013 From: roy at panix.com (Roy Smith) Date: Sat, 09 Mar 2013 15:04:52 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: In article , Grant Edwards wrote: > In Unix there is no way to release heap memory (which is what you're > talking about) back to the OS except for terminating the process. That's not quite true. The man page for BRK(2) (at least on the Linux box I happen to have handy) says: "brk() and sbrk() change the location of the program break, which defines the end of the process's data segment (i.e., the program break is the first location after the end of the uninitialized data segment). Increasing the program break has the effect of allocating memory to the process; decreasing the break deallocates memory." So, in theory, it's possible. I just ran this C program: #include #include int main(int argc, char** argv) { struct timespec t; t.tv_sec = 10; t.tv_nsec = 0; nanosleep(&t, NULL); sbrk(500 * 1024 * 1024); nanosleep(&t, NULL); sbrk(-500 * 1024 * 1024); nanosleep(&t, NULL); } while watching the process with ps. I could see the process appear and for the first 10 seconds it had a VSZ of 4156. Then, for the next 10 seconds, the VSZ was 516156, then it went back down to 4156. $ while sleep 1; do ps augx | grep a.out | grep -v grep; done roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 516156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out roy 6657 0.0 0.0 4156 356 pts/10 S+ 19:56 0:00 ./a.out In practice, unless you go to extraordinary lengths (i.e. avoid almost all of the standard C library), the break is going to be managed by malloc(), and malloc() provides no way to give memory back (insert handwave here about mmap, and another handwave about various versions of malloc). But, that's due to the way malloc() manages its arena, not anything fundamental about how Unix works. From invalid at invalid.invalid Sat Mar 9 15:35:47 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 9 Mar 2013 20:35:47 +0000 (UTC) Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: On 2013-03-09, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> In Unix there is no way to release heap memory (which is what you're >> talking about) back to the OS except for terminating the process. > > That's not quite true. The man page for BRK(2) (at least on the Linux > box I happen to have handy) says: > > "brk() and sbrk() change the location of the program break, which > defines the end of the process's data segment (i.e., the program > break is the first location after the end of the uninitialized data > segment). Increasing the program break has the effect of allocating > memory to the process; decreasing the break deallocates memory." > > So, in theory, it's possible. Well spotted. I would have bet money (OK, not a lot), that sbrk() only accepted positive increment values. I seem to have conflated what sbrk() will accept and the fact that the C library's malloc/free calls never call sbrk() with a nagative number. [... nicely done demonstraction of negative sbrk() parameter usage ...] > In practice, unless you go to extraordinary lengths (i.e. avoid > almost all of the standard C library), the break is going to be > managed by malloc(), and malloc() provides no way to give memory back > (insert handwave here about mmap, and another handwave about various > versions of malloc). But, that's due to the way malloc() manages its > arena, not anything fundamental about how Unix works. Indeed. What I should have said was that there's no way to return to the OS memory obtained via calls to malloc() et al, and those are the calls that "good" C programmers (like the maintainers of CPython) use. In theory, you could modify the C library so that calls to free() might return memory to the OS. Sometimes. If you're lucky. The problem is that if there's _one_byte_ of memory in use at the "end" of the heap region, it doesn't matter if there's an unused 16GB chunk in the middle -- it can't be returned to the OS. -- Grant Edwards grant.b.edwards Yow! Look DEEP into the at OPENINGS!! Do you see any gmail.com ELVES or EDSELS ... or a HIGHBALL?? ... From roy at panix.com Sat Mar 9 16:44:03 2013 From: roy at panix.com (Roy Smith) Date: Sat, 09 Mar 2013 16:44:03 -0500 Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: In article , Grant Edwards wrote: > What I should have said was that there's no way to return to the OS > memory obtained via calls to malloc() et al. That's true (for certain values of "et al"). > and those are the calls that "good" C programmers (like the > maintainers of CPython) use. Well, there is mmap, which is exposed via the Python mmap module. Python doesn't have anything like C++'s "placement new", so there's no way to use that memory to hold generic Python objects, but you can certainly use mmap to allocate a large chunk of memory, use it, and then give it back to the OS. For example: #!/usr/bin/env python import mmap import time time.sleep(5) f = open('my-500-mbyte-text-file') data = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ) count = 0 while 1: line = data.readline() if not line: break count += 1 print count time.sleep(5) data.close() time.sleep(5) When I run that and watch the process size (like I did with the previous example), you can see the process grow when mmap() is called, and shrink again when the segment is closed. I have to admit, in all the years I've been using Python, this is the first time I've ever used the mmap module. Even for long running processes, the automatic memory management that Python provides out of the box has always been good enough for me. But, it's nice to know mmap is there if I need to do something unusual. From invalid at invalid.invalid Mon Mar 11 10:27:31 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 11 Mar 2013 14:27:31 +0000 (UTC) Subject: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> Message-ID: On 2013-03-09, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> What I should have said was that there's no way to return to the OS >> memory obtained via calls to malloc() et al. > > That's true (for certain values of "et al"). > >> and those are the calls that "good" C programmers (like the >> maintainers of CPython) use. > > Well, there is mmap, which is exposed via the Python mmap module. > Python doesn't have anything like C++'s "placement new", so there's > no way to use that memory to hold generic Python objects, but you can > certainly use mmap to allocate a large chunk of memory, use it, and > then give it back to the OS. [example] I was surprised to find that the object returned by mmap.mmap() supported file semantics (seek, tell, read, etc.) in addition to byte buffer semantics. Usually, the reason one maps a file is that one doesn't want to use file semantics (which are already supported by the file object) but wants instead to use buffer semantics. Using memmap to obtain a "returnable" chunk of memory seems a bit obtuse, since it requires creating an underlying file of appropriate size that ends up being superfluous. -- Grant Edwards grant.b.edwards Yow! I wonder if I ought at to tell them about my gmail.com PREVIOUS LIFE as a COMPLETE STRANGER? From nikos.gr33k at gmail.com Wed Mar 6 03:57:26 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 00:57:26 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> ?? ???????, 6 ??????? 2013 10:19:06 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > How can i update the databse to only contain the existing filenames without losing the previous stored data? > > > > Basically you need to keep a list (or better, a set) containing all > > current filenames that you are going to insert, and finally do another > > "inverse" loop where you scan all the records and delete those that are > > not present anymore. > > > > Of course, this assume you have a "bidirectional" identity between the > > filenames you are loading and the records you are inserting, which is > > not the case in the code you show: > > > > > #read the containing folder and insert new filenames > > > for result in os.walk(path): > > > for filename in result[2]: > > > > Here "filename" is just that, not the full path: this could result in > > collisions, if your are actually loading a *tree* instead of a flat > > directory, that is multiple source files are squeezed into a single > > record in your database (imagine "/foo/index.html" and > > "/foo/subdir/index.html"). > > > > With that in mind, I would do something like the following: > > > > # Compute a set of current fullpaths > > current_fullpaths = set() > > for root, dirs, files in os.walk(path): > > for fullpath in files: > > current_fullpaths.add(os.path.join(root, file)) > > > > # Load'em > > for fullpath in current_fullpaths: > > > > try: > > #find the needed counter for the page URL > > cur.execute('''SELECT URL FROM files WHERE URL = %s''', (fullpath,) ) > > data = cur.fetchone() #URL is unique, so should only be one > > > > if not data: > > #first time for file; primary key is automatic, hit is defaulted > > cur.execute('''INSERT INTO files (URL, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, date) ) > > except MySQLdb.Error, e: > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > # Delete spurious > > cur.execute('''SELECT url FROM files''') > > for rec in cur: > > fullpath = rec[0] > > if fullpath not in current_fullpaths: > > other_cur.execute('''DELETE FROM files WHERE url = %s''', (fullpath,)) > > > > Of course here I am assuming a lot (a typical thing we do to answer your > > questions :-), in particular that the "url" field content matches the > > filesystem layout, which may not be the case. Adapt it to your usecase. > > > > hope this helps, > > 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. You are fantastic! Your straightforward logic amazes me! Thank you very much for making things clear to me!! But there is a slight problem when iam trying to run the code iam presenting this error ehre you can see its output here: http://superhost.gr/cgi-bin/files.py From nikos.gr33k at gmail.com Wed Mar 6 03:57:26 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 00:57:26 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> ?? ???????, 6 ??????? 2013 10:19:06 ?.?. UTC+2, ? ??????? Lele Gaifax ??????: > ????? ???33? writes: > > > > > How can i update the databse to only contain the existing filenames without losing the previous stored data? > > > > Basically you need to keep a list (or better, a set) containing all > > current filenames that you are going to insert, and finally do another > > "inverse" loop where you scan all the records and delete those that are > > not present anymore. > > > > Of course, this assume you have a "bidirectional" identity between the > > filenames you are loading and the records you are inserting, which is > > not the case in the code you show: > > > > > #read the containing folder and insert new filenames > > > for result in os.walk(path): > > > for filename in result[2]: > > > > Here "filename" is just that, not the full path: this could result in > > collisions, if your are actually loading a *tree* instead of a flat > > directory, that is multiple source files are squeezed into a single > > record in your database (imagine "/foo/index.html" and > > "/foo/subdir/index.html"). > > > > With that in mind, I would do something like the following: > > > > # Compute a set of current fullpaths > > current_fullpaths = set() > > for root, dirs, files in os.walk(path): > > for fullpath in files: > > current_fullpaths.add(os.path.join(root, file)) > > > > # Load'em > > for fullpath in current_fullpaths: > > > > try: > > #find the needed counter for the page URL > > cur.execute('''SELECT URL FROM files WHERE URL = %s''', (fullpath,) ) > > data = cur.fetchone() #URL is unique, so should only be one > > > > if not data: > > #first time for file; primary key is automatic, hit is defaulted > > cur.execute('''INSERT INTO files (URL, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, date) ) > > except MySQLdb.Error, e: > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > # Delete spurious > > cur.execute('''SELECT url FROM files''') > > for rec in cur: > > fullpath = rec[0] > > if fullpath not in current_fullpaths: > > other_cur.execute('''DELETE FROM files WHERE url = %s''', (fullpath,)) > > > > Of course here I am assuming a lot (a typical thing we do to answer your > > questions :-), in particular that the "url" field content matches the > > filesystem layout, which may not be the case. Adapt it to your usecase. > > > > hope this helps, > > 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. You are fantastic! Your straightforward logic amazes me! Thank you very much for making things clear to me!! But there is a slight problem when iam trying to run the code iam presenting this error ehre you can see its output here: http://superhost.gr/cgi-bin/files.py From lele at metapensiero.it Wed Mar 6 04:24:44 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 06 Mar 2013 10:24:44 +0100 Subject: sync databse table based on current directory data without losign previous values References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> Message-ID: <87vc94j2xv.fsf@nautilus.nautilus> ????? ???33? writes: > Thank you very much for making things clear to me!! You're welcome, even more if you spend 1 second to trim your answers removing unneeded citation :-) > > But there is a slight problem when iam trying to run the code iam presenting this error ehre you can see its output here: > > http://superhost.gr/cgi-bin/files.py Sorry, this seems completely unrelated, and from the little snippet that appear on that page I cannot understand what's going on there. 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 nikos.gr33k at gmail.com Wed Mar 6 04:41:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 01:41:31 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> Message-ID: <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Its about the following line of code: current_fullpaths.add( os.path.join(root, files) ) that presents the following error: : 'list' object has no attribute 'startswith' args = ("'list' object has no attribute 'startswith'",) message = "'list' object has no attribute 'startswith'" join calls some module that find difficulty when parsing its line: /usr/lib64/python2.6/posixpath.py in join(a='/home/nikos/public_html/data/files/', *p=(['\xce\x9a\xcf\x8d\xcf\x81\xce\xb9\xce\xb5 \xce\x99\xce\xb7\xcf\x83\xce\xbf\xcf\x8d \xce\xa7\xcf\x81\xce\xb9\xcf\x83\xcf\x84\xce\xad \xce\x95\xce\xbb\xce\xad\xce\xb7\xcf\x83\xce\xbf\xce\xbd \xce\x9c\xce\xb5.mp3', '\xce\xa0\xce\xb5\xcf\x81\xce\xaf \xcf\x84\xcf\x89\xce\xbd \xce\x9b\xce\xbf\xce\xb3\xce\xb9\xcf\x83\xce\xbc\xcf\x8e\xce\xbd.mp3'],)) 63 path = a 64 for b in p: 65 if b.startswith('/'): From nikos.gr33k at gmail.com Wed Mar 6 04:43:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 01:43:34 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Message-ID: Perhaps because my filenames is in greek letters that thsi error is presented but i'am not sure..... Maybe we can join root+files and store it to the set() someway differenyl.... From nikos.gr33k at gmail.com Wed Mar 6 04:43:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 01:43:34 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Message-ID: Perhaps because my filenames is in greek letters that thsi error is presented but i'am not sure..... Maybe we can join root+files and store it to the set() someway differenyl.... From bryan.devaney at gmail.com Wed Mar 6 05:15:36 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Wed, 6 Mar 2013 02:15:36 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Message-ID: On Wednesday, March 6, 2013 9:43:34 AM UTC, ????? ???33? wrote: > Perhaps because my filenames is in greek letters that thsi error is presented but i'am not sure..... > > > > Maybe we can join root+files and store it to the set() someway differenyl.... well, the error refers to the line "if b.startswith('/'): " and states "'list' object has no attribute 'startswith'" so b is assigned to a list type and list does not have a 'startswith' method or attribute. I Thought .startswith() was a string method but if it's your own method then I apologize (though if it is, I personally would have made a class that inherited from list rather than adding it to list itself) can you show where you are assigning b (or if its meant to be a list or string object) From bryan.devaney at gmail.com Wed Mar 6 05:15:36 2013 From: bryan.devaney at gmail.com (Bryan Devaney) Date: Wed, 6 Mar 2013 02:15:36 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Message-ID: On Wednesday, March 6, 2013 9:43:34 AM UTC, ????? ???33? wrote: > Perhaps because my filenames is in greek letters that thsi error is presented but i'am not sure..... > > > > Maybe we can join root+files and store it to the set() someway differenyl.... well, the error refers to the line "if b.startswith('/'): " and states "'list' object has no attribute 'startswith'" so b is assigned to a list type and list does not have a 'startswith' method or attribute. I Thought .startswith() was a string method but if it's your own method then I apologize (though if it is, I personally would have made a class that inherited from list rather than adding it to list itself) can you show where you are assigning b (or if its meant to be a list or string object) From nikos.gr33k at gmail.com Wed Mar 6 04:41:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 6 Mar 2013 01:41:31 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> Message-ID: <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Its about the following line of code: current_fullpaths.add( os.path.join(root, files) ) that presents the following error: : 'list' object has no attribute 'startswith' args = ("'list' object has no attribute 'startswith'",) message = "'list' object has no attribute 'startswith'" join calls some module that find difficulty when parsing its line: /usr/lib64/python2.6/posixpath.py in join(a='/home/nikos/public_html/data/files/', *p=(['\xce\x9a\xcf\x8d\xcf\x81\xce\xb9\xce\xb5 \xce\x99\xce\xb7\xcf\x83\xce\xbf\xcf\x8d \xce\xa7\xcf\x81\xce\xb9\xcf\x83\xcf\x84\xce\xad \xce\x95\xce\xbb\xce\xad\xce\xb7\xcf\x83\xce\xbf\xce\xbd \xce\x9c\xce\xb5.mp3', '\xce\xa0\xce\xb5\xcf\x81\xce\xaf \xcf\x84\xcf\x89\xce\xbd \xce\x9b\xce\xbf\xce\xb3\xce\xb9\xcf\x83\xce\xbc\xcf\x8e\xce\xbd.mp3'],)) 63 path = a 64 for b in p: 65 if b.startswith('/'): From lele at metapensiero.it Wed Mar 6 05:27:30 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 06 Mar 2013 11:27:30 +0100 Subject: sync databse table based on current directory data without losign previous values References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> Message-ID: <87r4jsj019.fsf@nautilus.nautilus> ????? ???33? writes: > Its about the following line of code: > > current_fullpaths.add( os.path.join(root, files) ) I'm sorry, typo on my part. That should have been "fullpath", not "file" (and neither "files" as you wrongly reported back!): # Compute a set of current fullpaths current_fullpaths = set() for root, dirs, files in os.walk(path): for fullpath in files: current_fullpaths.add(os.path.join(root, fullpath)) 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 davea at davea.name Wed Mar 6 08:31:40 2013 From: davea at davea.name (Dave Angel) Date: Wed, 06 Mar 2013 08:31:40 -0500 Subject: sync databse table based on current directory data without losign previous values In-Reply-To: <87r4jsj019.fsf@nautilus.nautilus> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> <87r4jsj019.fsf@nautilus.nautilus> Message-ID: <5137453C.8070405@davea.name> On 03/06/2013 05:27 AM, Lele Gaifax wrote: > ????? ???33? writes: > >> Its about the following line of code: >> >> current_fullpaths.add( os.path.join(root, files) ) > > I'm sorry, typo on my part. > > That should have been "fullpath", not "file" (and neither "files" as you > wrongly reported back!): > > # Compute a set of current fullpaths > current_fullpaths = set() > for root, dirs, files in os.walk(path): > for fullpath in files: 'fullpath' is a rather misleading name to use, since the 'files' list contains only the terminal node of the file name. It's only a full path after you do the following join. > current_fullpaths.add(os.path.join(root, fullpath)) > -- DaveA From lele at metapensiero.it Wed Mar 6 09:16:09 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 06 Mar 2013 15:16:09 +0100 Subject: sync databse table based on current directory data without losign previous values References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <3958fc2b-a2fe-4c85-a104-4c6f551cf787@googlegroups.com> <28828019-279a-4d8c-a7ea-ba677b4a8165@googlegroups.com> <87r4jsj019.fsf@nautilus.nautilus> <5137453C.8070405@davea.name> Message-ID: <87r4js397a.fsf@nautilus.nautilus> Dave Angel writes: >> # Compute a set of current fullpaths >> current_fullpaths = set() >> for root, dirs, files in os.walk(path): >> for fullpath in files: > > 'fullpath' is a rather misleading name to use, since the 'files' list > contains only the terminal node of the file name. It's only a full > path after you do the following join. Yes, you're right. Dunno what urged me to ``M-x replace-string file fullpath`` introducing both an error and a bad variable name, most probably the unconscious desire of not clobbering builtin names... :-) Thanks for pointing it out, 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 breamoreboy at yahoo.co.uk Wed Mar 6 06:52:00 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 06 Mar 2013 11:52:00 +0000 Subject: sync databse table based on current directory data without losign previous values In-Reply-To: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: On 06/03/2013 07:45, ????? ???33? wrote: > I'am using this snipper to read a current directory and insert all filenames into a databse and then display them. > > But what happens when files are get removed form the directory? > The inserted records into databse remain. > How can i update the databse to only contain the existing filenames without losing the previous stored data? > > Here is what i ahve so far: > > ================================== > path = "/home/nikos/public_html/data/files/" > > #read the containing folder and insert new filenames > for result in os.walk(path): You were told yesterday at least twice that os.walk returns a tuple but you still insist on refusing to take any notice of our replies when it suits you, preferring instead to waste everbody's time with these questions. Or are you trying to get into the Guinness Book of World Records for the laziest bastard on the planet? > for filename in result[2]: > try: > #find the needed counter for the page URL > cur.execute('''SELECT URL FROM files WHERE URL = %s''', (filename,) ) > data = cur.fetchone() #URL is unique, so should only be one > > if not data: > #first time for file; primary key is automatic, hit is defaulted > cur.execute('''INSERT INTO files (URL, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, date) ) > except MySQLdb.Error, e: > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > ====================== > > Thank you. > -- Cheers. Mark Lawrence From rosuav at gmail.com Wed Mar 6 08:40:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 00:40:42 +1100 Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: On Wed, Mar 6, 2013 at 10:52 PM, Mark Lawrence wrote: > On 06/03/2013 07:45, ????? ???33? wrote: >> blah blah blah >> blah blah blah >> blah blah blah > You were told yesterday at least twice that os.walk returns a tuple but you > still insist on refusing to take any notice of our replies when it suits > you, preferring instead to waste everbody's time with these questions. Or > are you trying to get into the Guinness Book of World Records for the > laziest bastard on the planet? This is the same person who posts under the name Ferrous Cranus. His threads are open-ended time sinks; he generally expects everyone else to do the work, while his contribution is to complain that the provided code doesn't fit some arbitrary set of restrictions that don't always even make sense. Guinness might be interested in him as "Most Successful Troll", though. He certainly absorbed a lot of my dev time before I gave up on him, and by the look of things, he's still getting other people to do his work for him. ChrisA From gmx at ross.cx Wed Mar 6 09:04:26 2013 From: gmx at ross.cx (Michael Ross) Date: Wed, 06 Mar 2013 15:04:26 +0100 Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: On Wed, 06 Mar 2013 12:52:00 +0100, Mark Lawrence wrote: > On 06/03/2013 07:45, ????? ???33? wrote: >> I'am using this snipper to read a current directory and insert all >> filenames into a databse and then display them. >> >> But what happens when files are get removed form the directory? >> The inserted records into databse remain. >> How can i update the databse to only contain the existing filenames >> without losing the previous stored data? >> >> Here is what i ahve so far: >> >> ================================== >> path = "/home/nikos/public_html/data/files/" >> >> #read the containing folder and insert new filenames >> for result in os.walk(path): > > You were told yesterday at least twice that os.walk returns a tuple but > you still insist on refusing to take any notice of our replies when it > suits you, preferring instead to waste everbody's time with these > questions. Or are you trying to get into the Guinness Book of World > Records for the laziest bastard on the planet? Hold on a sec ... He has for result in os.walk(path): for filename in result[2]: So he *did* take notice of that. Nikos: Expectation is to iterate through a tuple like this: for dirpath, dirnames, filenames in os.walk(path): ... From nagia.retsina at gmail.com Wed Mar 6 11:09:23 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 6 Mar 2013 08:09:23 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: <1a812041-c753-41f8-96d9-7030257543f3@googlegroups.com> ?? ???????, 6 ??????? 2013 4:04:26 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Wed, 06 Mar 2013 12:52:00 +0100, Mark Lawrence > > wrote: > > > > > On 06/03/2013 07:45, ????? ???33? wrote: > > >> I'am using this snipper to read a current directory and insert all > > >> filenames into a databse and then display them. > > >> > > >> But what happens when files are get removed form the directory? > > >> The inserted records into databse remain. > > >> How can i update the databse to only contain the existing filenames > > >> without losing the previous stored data? > > >> > > >> Here is what i ahve so far: > > >> > > >> ================================== > > >> path = "/home/nikos/public_html/data/files/" > > >> > > >> #read the containing folder and insert new filenames > > >> for result in os.walk(path): > > > > > > You were told yesterday at least twice that os.walk returns a tuple but > > > you still insist on refusing to take any notice of our replies when it > > > suits you, preferring instead to waste everbody's time with these > > > questions. Or are you trying to get into the Guinness Book of World > > > Records for the laziest bastard on the planet? > > > > Hold on a sec ... > > > > He has > > > > for result in os.walk(path): > > for filename in result[2]: > > > > So he *did* take notice of that. > > > > > > Nikos: > > Expectation is to iterate through a tuple like this: > > > > for dirpath, dirnames, filenames in os.walk(path): > > ... Thank you Michael, yes i ahve understood that myself yesterday after one of the guys here have shown the output of os.walk(path) in IDLE. So, yes in fact i was in need for the 3rd item in the tuple, so to get hold on to the files. Thank you for supporting me, some ppl here think i'am a troll and don't try thinks or ignore evrything but 'some_ppl's_opinion != True' I'am just sometimes persistant on having thing my way that why i was calling my self Ferrous cRanus, which i changes it since it was annoying.... From nagia.retsina at gmail.com Wed Mar 6 11:09:23 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 6 Mar 2013 08:09:23 -0800 (PST) Subject: sync databse table based on current directory data without losign previous values In-Reply-To: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> Message-ID: <1a812041-c753-41f8-96d9-7030257543f3@googlegroups.com> ?? ???????, 6 ??????? 2013 4:04:26 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Wed, 06 Mar 2013 12:52:00 +0100, Mark Lawrence > > wrote: > > > > > On 06/03/2013 07:45, ????? ???33? wrote: > > >> I'am using this snipper to read a current directory and insert all > > >> filenames into a databse and then display them. > > >> > > >> But what happens when files are get removed form the directory? > > >> The inserted records into databse remain. > > >> How can i update the databse to only contain the existing filenames > > >> without losing the previous stored data? > > >> > > >> Here is what i ahve so far: > > >> > > >> ================================== > > >> path = "/home/nikos/public_html/data/files/" > > >> > > >> #read the containing folder and insert new filenames > > >> for result in os.walk(path): > > > > > > You were told yesterday at least twice that os.walk returns a tuple but > > > you still insist on refusing to take any notice of our replies when it > > > suits you, preferring instead to waste everbody's time with these > > > questions. Or are you trying to get into the Guinness Book of World > > > Records for the laziest bastard on the planet? > > > > Hold on a sec ... > > > > He has > > > > for result in os.walk(path): > > for filename in result[2]: > > > > So he *did* take notice of that. > > > > > > Nikos: > > Expectation is to iterate through a tuple like this: > > > > for dirpath, dirnames, filenames in os.walk(path): > > ... Thank you Michael, yes i ahve understood that myself yesterday after one of the guys here have shown the output of os.walk(path) in IDLE. So, yes in fact i was in need for the 3rd item in the tuple, so to get hold on to the files. Thank you for supporting me, some ppl here think i'am a troll and don't try thinks or ignore evrything but 'some_ppl's_opinion != True' I'am just sometimes persistant on having thing my way that why i was calling my self Ferrous cRanus, which i changes it since it was annoying.... From kylotan at gmail.com Wed Mar 6 11:07:52 2013 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 6 Mar 2013 08:07:52 -0800 (PST) Subject: Creating an object that can track when its attributes are modified Message-ID: I am trying to make an object that can track when its attributes have been assigned new values, and which can rollback to previous values where necessary. I have the following code which I believe works, but would like to know if there are simpler ways to achieve this goal, or if there are any bugs I haven't seen yet. class ChangeTrackingObject(object): def __init__(self): self.clean() def clean(self): """Mark all attributes as unmodified.""" object.__setattr__(self, '_dirty_attributes', dict()) def dirty_vals(self): """Returns all dirty values.""" return dict( [ (k,v) for k,v in self.__dict__.iteritems() if k in self._dirty_attributes] ) def get_changes_and_clean(self): """Helper that collects all the changes and returns them, cleaning the dirty flags at the same time.""" changes = self.dirty_vals() self.clean() return changes def rollback(self): """Reset attributes to their previous values.""" for k,v in self._dirty_attributes.iteritems(): object.__setattr__(self, k, v) self.clean() def __setattr__(self, key, value): # If the first modification to this attribute, store the old value if key not in self._dirty_attributes: if key in self.__dict__: self._dirty_attributes[key] = object.__getattribute__(self, key) else: self._dirty_attributes[key] = None # Set the new value object.__setattr__(self, key, value) I am aware that adding a new attribute and then calling rollback() leaves the new attribute in place with a None value - maybe I can use a special DeleteMe marker object in the _dirty_attributes dict along with a loop that calls delattr on any attribute that has that value after a rollback. I also believe that this won't catch modification to existing attributes as opposed to assignments: eg. if one of the attributes is a list and I append to it, this system won't notice. Is that something I can rectify easily? Any other comments or suggestions? Thanks, -- Ben Sizer From rosuav at gmail.com Wed Mar 6 11:22:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 03:22:56 +1100 Subject: Creating an object that can track when its attributes are modified In-Reply-To: References: Message-ID: On Thu, Mar 7, 2013 at 3:07 AM, Ben Sizer wrote: > I also believe that this won't catch modification to existing attributes as opposed to assignments: eg. if one of the attributes is a list and I append to it, this system won't notice. Is that something I can rectify easily? The only way you could detect mutation of one of its attributes is with that object's assistance. Effectively, you would need to have a subclass of list/dict/tuple/whatever that can respond to the change. Alternatively, you could retain a deep copy and do a comparison at time of rollback; this, however, would have annoying consequences wrt performance and other references and such. What's the goal of this class? Can you achieve the same thing by using, perhaps, a before-and-after snapshot of a JSON-encoded form of the object? ChrisA From kylotan at gmail.com Wed Mar 6 11:56:09 2013 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 6 Mar 2013 08:56:09 -0800 (PST) Subject: Creating an object that can track when its attributes are modified In-Reply-To: References: Message-ID: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: > > Effectively, you would need to have a > subclass of list/dict/tuple/whatever that can respond to the change. This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types. > What's the goal of this class? Can you achieve the same thing by > using, perhaps, a before-and-after snapshot of a JSON-encoded form of > the object? > I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.) -- Ben Sizer From kylotan at gmail.com Wed Mar 6 11:56:09 2013 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 6 Mar 2013 08:56:09 -0800 (PST) Subject: Creating an object that can track when its attributes are modified In-Reply-To: References: Message-ID: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: > > Effectively, you would need to have a > subclass of list/dict/tuple/whatever that can respond to the change. This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types. > What's the goal of this class? Can you achieve the same thing by > using, perhaps, a before-and-after snapshot of a JSON-encoded form of > the object? > I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.) -- Ben Sizer From rosuav at gmail.com Wed Mar 6 12:03:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 04:03:59 +1100 Subject: Creating an object that can track when its attributes are modified In-Reply-To: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> References: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 3:56 AM, Ben Sizer wrote: > On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: >> >> Effectively, you would need to have a >> subclass of list/dict/tuple/whatever that can respond to the change. > > This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types. Since you're already overriding setattr, you could simply force all non-string sequences to your special subclass of list. That reduces that burden, though it'd break if there are any other references to the object. >> What's the goal of this class? Can you achieve the same thing by >> using, perhaps, a before-and-after snapshot of a JSON-encoded form of >> the object? >> > > I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.) Hmm. Interesting. The perfect solution probably is too messy, yeah. But if you have your subclassing done, you could possibly snapshot-on-write, which would allow the rollback. Not sure if it'd help though. ChrisA From dihedral88888 at googlemail.com Wed Mar 6 16:07:40 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 6 Mar 2013 13:07:40 -0800 (PST) Subject: Creating an object that can track when its attributes are modified In-Reply-To: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> References: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> Message-ID: Ben Sizer? 2013?3?7????UTC+8??12?56?09???? > On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: > > > > > > Effectively, you would need to have a > > > subclass of list/dict/tuple/whatever that can respond to the change. > > > > This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types. > > > > > What's the goal of this class? Can you achieve the same thing by > > > using, perhaps, a before-and-after snapshot of a JSON-encoded form of > > > the object? > > > > > > > I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.) > > > > -- > > Ben Sizer Please hook a stack implemented as a list in python to every property of the object that you want to track down. From dihedral88888 at googlemail.com Wed Mar 6 16:07:40 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 6 Mar 2013 13:07:40 -0800 (PST) Subject: Creating an object that can track when its attributes are modified In-Reply-To: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> References: <5c776c70-aa7d-4b2e-ad7b-54392793c607@googlegroups.com> Message-ID: Ben Sizer? 2013?3?7????UTC+8??12?56?09???? > On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico wrote: > > > > > > Effectively, you would need to have a > > > subclass of list/dict/tuple/whatever that can respond to the change. > > > > This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types. > > > > > What's the goal of this class? Can you achieve the same thing by > > > using, perhaps, a before-and-after snapshot of a JSON-encoded form of > > > the object? > > > > > > > I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.) > > > > -- > > Ben Sizer Please hook a stack implemented as a list in python to every property of the object that you want to track down. From steve+comp.lang.python at pearwood.info Wed Mar 6 19:07:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2013 00:07:02 GMT Subject: Creating an object that can track when its attributes are modified References: Message-ID: <5137da26$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 08:56:09 -0800, Ben Sizer wrote: > I need to be able to perform complex operations on the object that may > modify several properties, and then gather the properties at the end as > an efficient way to see what has changed and to store those changes. Any > comparison of before-and-after snapshots could work in theory, but in > practice it could be expensive to produce the snapshots on larger > objects and probably expensive to calculate the differences that way > too. Performance is important so I would probably just go for an > explicit function call to mark an attribute as having been modified > rather than trying to do a diff like that. (It wouldn't work for > rollbacks, but I can accept that.) Premature optimization. Unless you have been eating and breathing Python code for 15+ years, your intuition of what is expensive and what isn't will probably be *way* off. I've been using Python for ~15 years, and I wouldn't want to try to guess what the most efficient way to do this will be. Actually I lie. I would guess that the simple, most obvious way is faster: don't worry about storing what changed, just store *everything*. But I could be wrong. Fortunately, Python development is rapid enough that you can afford to develop this object the straightforward way, profile your application to see where the bottlenecks are, and if it turns out that the simple approach is too expensive, then try something more complicated. -- Steven From kylotan at gmail.com Wed Mar 6 19:26:57 2013 From: kylotan at gmail.com (Ben Sizer) Date: Wed, 6 Mar 2013 16:26:57 -0800 (PST) Subject: Creating an object that can track when its attributes are modified In-Reply-To: <5137da26$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <5137da26$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, 7 March 2013 00:07:02 UTC, Steven D'Aprano wrote: > On Wed, 06 Mar 2013 08:56:09 -0800, Ben Sizer wrote: > > > I need to be able to perform complex operations on the object that may > > modify several properties, and then gather the properties at the end as > > an efficient way to see what has changed and to store those changes. Any > > comparison of before-and-after snapshots could work in theory, but in > > practice it could be expensive to produce the snapshots on larger > > objects and probably expensive to calculate the differences that way > > too. Performance is important so I would probably just go for an > > explicit function call to mark an attribute as having been modified > > rather than trying to do a diff like that. (It wouldn't work for > > rollbacks, but I can accept that.) > > Premature optimization. > > Unless you have been eating and breathing Python code for 15+ years, your > intuition of what is expensive and what isn't will probably be *way* off. > I've been using Python for ~15 years, and I wouldn't want to try to guess > what the most efficient way to do this will be. I admit, I've only been using Python for 10 years, but I've learned a lot about optimisation and what needs optimising from my time as a game developer. This code needs to be fairly high-performing due to the role it plays in my server and the frequency with which the behaviour gets called. > Actually I lie. I would guess that the simple, most obvious way is > faster: don't worry about storing what changed, just store *everything*. > But I could be wrong. The use case I have is not one where that is suitable. It's not the snapshots that are important, but the changes between them. > Fortunately, Python development is rapid enough that you can afford to > develop this object the straightforward way, profile your application to > see where the bottlenecks are, and if it turns out that the simple > approach is too expensive, then try something more complicated. I don't see a more straightforward solution to the problem I have than the one I have posted. I said that a system that took snapshots of the whole object and attempted to diff them would probably perform worse, but it would probably be more complex too, given the traversal and copying requirements. -- Ben Sizer From steve+comp.lang.python at pearwood.info Fri Mar 8 13:50:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2013 18:50:58 GMT Subject: Creating an object that can track when its attributes are modified References: <5137da26$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513a3311$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 16:26:57 -0800, Ben Sizer wrote: > On Thursday, 7 March 2013 00:07:02 UTC, Steven D'Aprano wrote: [...] >> Actually I lie. I would guess that the simple, most obvious way is >> faster: don't worry about storing what changed, just store >> *everything*. But I could be wrong. > > The use case I have is not one where that is suitable. It's not the > snapshots that are important, but the changes between them. I'm afraid that doesn't make much sense to me. You're performing calculations, and stuffing them into instance attributes, but you don't care about the result of the calculations, only how they differ from the previous result? I obviously don't understand the underlying problem you're trying to solve. >> Fortunately, Python development is rapid enough that you can afford to >> develop this object the straightforward way, profile your application >> to see where the bottlenecks are, and if it turns out that the simple >> approach is too expensive, then try something more complicated. > > I don't see a more straightforward solution to the problem I have than > the one I have posted. I said that a system that took snapshots of the > whole object and attempted to diff them would probably perform worse, > but it would probably be more complex too, given the traversal and > copying requirements. Yes, and I said that your intuition of what will be fast and what will be slow is not necessarily trustworthy. Without testing, neither of us knows for sure. Given the code you showed in the original post, I don't see that traversal and copying requirements are terribly complicated. You don't do deep-copies of attributes, so a shallow copy of the instance __dict__ ought to be enough. Assuming you have a well-defined "start processing" moment, just grab a snapshot of the dict, which will be fast, then do your calculations, then call get_changes: def snapshot(self): self._snapshot = self.__dict__.copy() def get_changes(self): sentinel = object() return dict( [ (k,v) for k,v in self.__dict__.iteritems() if k == self._snapshot.get(k, sentinel) ] ) This doesn't support *deleting* attributes, but neither does your original version. Obviously I don't know for sure which strategy is fastest, but since your version already walks the entire __dict__, this shouldn't be much slower, and has a good chance of being faster. (Your version slows down *every* attribute assignment. My version does not.) By the way, your original version describes the get_changes_and_clean() method as cleaning the dirty *flags*. But the implementation doesn't store flags. Misleading documentation is worse than no documentation. But if you insist on the approach you've taken, you can simplify the __setattr__ method: def __setattr__(self, key, value): # If the first modification to this attribute, store the old value dirty = self._dirty_attributes if key not in dirty: dirty[key] = getattr(self, key, None) # Set the new value object.__setattr__(self, key, value) You might try this (slightly) obfuscated version, which *could* be faster still, although I doubt it. def __setattr__(self, key, value): # If the first modification to this attribute, store the old value self._dirty_attributes.setdefault(key, getattr(self, key, None)) # Set the new value object.__setattr__(self, key, value) but if you really need to get every bit of performance, it's worth trying them both and seeing which is faster. (P.S. I trust you know to use timeit for timing small code snippets, rather than rolling your own timing code?) -- Steven From lele at metapensiero.it Wed Mar 6 11:56:05 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 06 Mar 2013 17:56:05 +0100 Subject: Creating an object that can track when its attributes are modified References: Message-ID: <87mwug31sq.fsf@nautilus.nautilus> Ben Sizer writes: > I also believe that this won't catch modification to existing > attributes as opposed to assignments: eg. if one of the attributes is > a list and I append to it, this system won't notice. Is that something > I can rectify easily? It's really up to how far you wanna go: a similar use case is implemented by SQLAlchemy__, which "instrument" builtin collection classes to achieve the goal. But I'd not call that "easy" though :-) ciao, lele. __ http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/orm/collections.py -- 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 js at globe.de Thu Mar 7 07:21:00 2013 From: js at globe.de (Schneider) Date: Thu, 07 Mar 2013 13:21:00 +0100 Subject: Creating an object that can track when its attributes are modified In-Reply-To: References: Message-ID: <5138862C.9080708@globe.de> Hi, maybe you could do this by a decorator on the setattr method. It should look more or less like your implementation, but in my eyes it's a cleaner and can be reused. Further, I would use a stack for each attribute, so that you can restore all previous values. bg, Johannes On 03/06/2013 05:07 PM, Ben Sizer wrote: > I am trying to make an object that can track when its attributes have been assigned new values, and which can rollback to previous values where necessary. I have the following code which I believe works, but would like to know if there are simpler ways to achieve this goal, or if there are any bugs I haven't seen yet. > > > class ChangeTrackingObject(object): > def __init__(self): > self.clean() > > def clean(self): > """Mark all attributes as unmodified.""" > object.__setattr__(self, '_dirty_attributes', dict()) > > def dirty_vals(self): > """Returns all dirty values.""" > return dict( [ (k,v) for k,v in self.__dict__.iteritems() if k in self._dirty_attributes] ) > > def get_changes_and_clean(self): > """Helper that collects all the changes and returns them, cleaning the dirty flags at the same time.""" > changes = self.dirty_vals() > self.clean() > return changes > > def rollback(self): > """Reset attributes to their previous values.""" > for k,v in self._dirty_attributes.iteritems(): > object.__setattr__(self, k, v) > self.clean() > > def __setattr__(self, key, value): > # If the first modification to this attribute, store the old value > if key not in self._dirty_attributes: > if key in self.__dict__: > self._dirty_attributes[key] = object.__getattribute__(self, key) > else: > self._dirty_attributes[key] = None > # Set the new value > object.__setattr__(self, key, value) > > > I am aware that adding a new attribute and then calling rollback() leaves the new attribute in place with a None value - maybe I can use a special DeleteMe marker object in the _dirty_attributes dict along with a loop that calls delattr on any attribute that has that value after a rollback. > > I also believe that this won't catch modification to existing attributes as opposed to assignments: eg. if one of the attributes is a list and I append to it, this system won't notice. Is that something I can rectify easily? > > Any other comments or suggestions? > > Thanks, From priyanka.khamankar at gmail.com Wed Mar 6 11:28:12 2013 From: priyanka.khamankar at gmail.com (priyanka.khamankar at gmail.com) Date: Wed, 6 Mar 2013 08:28:12 -0800 (PST) Subject: Unable to connect to internet URL behind firewall Message-ID: <17e5f19c-57d1-461b-bf1c-59a525922511@googlegroups.com> Hi, I am using below two approaches to connect to read the content of internet url. These two approaches work for me when the internet explorer session is open. When the internet explorer window is closed, below code gives me 407 error. I have also set the HTTP_PROXY environment variables as http://proxy-example.com:3128 Is there any way that the Python does not use Internet explorer proxy settings? I want my python script to work even when the IE window is closed.Please help. I am using Python version 2.6. Python code I am using is provide below. Approach 1: import urlib2 # == HTTP == # # HTTP with auth info in ProxyHandler is working # proxy_handler = urllib2.ProxyHandler({'http': 'http://user:pass at proxy-example.com:3128/'}) opener = urllib2.build_opener(proxy_handler) response = opener.open('http://example.com/testpage.htm') print response.read() Approach 2: # HTTP with AuthHandler is working # proxy_handler = urllib2.ProxyHandler({'http': 'http://proxy-example.com:3128/'}) proxy_auth_handler = urllib2.ProxyBasicAuthHandler() proxy_auth_handler.add_password('realm', 'proxy-example.com:3128', 'user', 'pass') opener = urllib2.build_opener(proxy_handler, proxy_auth_handler) response = opener.open('http://example.com/testpage.htm') print response.read() From vytasd2013 at gmail.com Thu Mar 7 04:10:00 2013 From: vytasd2013 at gmail.com (Vytas D.) Date: Thu, 7 Mar 2013 09:10:00 +0000 Subject: Unable to connect to internet URL behind firewall In-Reply-To: <17e5f19c-57d1-461b-bf1c-59a525922511@googlegroups.com> References: <17e5f19c-57d1-461b-bf1c-59a525922511@googlegroups.com> Message-ID: Hi, My guess is that your firewall is blocking the connections. To check this, disable your firewall and run your python program. If it runs, you have to configure your firewall to allow your program to connect to the internet. Vytas On Wed, Mar 6, 2013 at 4:28 PM, wrote: > Hi, > > I am using below two approaches to connect to read the content of internet > url. > These two approaches work for me when the internet explorer session is > open. > > When the internet explorer window is closed, below code gives me 407 error. > I have also set the HTTP_PROXY environment variables as > http://proxy-example.com:3128 > > Is there any way that the Python does not use Internet explorer proxy > settings? > I want my python script to work even when the IE window is closed.Please > help. > > I am using Python version 2.6. Python code I am using is provide below. > > Approach 1: > import urlib2 > > # == HTTP == > # > # HTTP with auth info in ProxyHandler is working > # > proxy_handler = urllib2.ProxyHandler({'http': ' > http://user:pass at proxy-example.com:3128/'}) > opener = urllib2.build_opener(proxy_handler) > response = opener.open('http://example.com/testpage.htm') > print response.read() > > Approach 2: > # HTTP with AuthHandler is working > # > proxy_handler = urllib2.ProxyHandler({'http': ' > http://proxy-example.com:3128/'}) > proxy_auth_handler = urllib2.ProxyBasicAuthHandler() > proxy_auth_handler.add_password('realm', 'proxy-example.com:3128', > 'user', 'pass') > > opener = urllib2.build_opener(proxy_handler, proxy_auth_handler) > response = opener.open('http://example.com/testpage.htm') > print response.read() > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Thu Mar 7 04:31:30 2013 From: svenito at gmail.com (Sven) Date: Thu, 7 Mar 2013 09:31:30 +0000 Subject: Unable to connect to internet URL behind firewall In-Reply-To: <17e5f19c-57d1-461b-bf1c-59a525922511@googlegroups.com> References: <17e5f19c-57d1-461b-bf1c-59a525922511@googlegroups.com> Message-ID: On 6 March 2013 16:28, wrote: > Hi, > > I am using below two approaches to connect to read the content of internet > url. > These two approaches work for me when the internet explorer session is > open. > > When the internet explorer window is closed, below code gives me 407 error. > I have also set the HTTP_PROXY environment variables as > http://proxy-example.com:3128 > >From experience the environment variable name is in lowercase. Try http_proxy instead. Don't ask me why this environment variable is lowercase when most others aren't. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexandre.zani at gmail.com Wed Mar 6 11:59:19 2013 From: alexandre.zani at gmail.com (Alexandre Zani) Date: Wed, 6 Mar 2013 08:59:19 -0800 Subject: Detecting the end of the program using bdb Message-ID: Hello all, I am attempting to write a remote debugger using bdb. One problem I am running into is that if I call self.set_next when on the last line of my program, I see this line printed: Exception AttributeError: "'NoneType' object has no attribute 'path'" in ignored But I don't see any way of detecting that the program I am debugging has now completed. More generally, I am not sure how to use bdb (or some alternative way) to detect that the program has finished executing. Any help would be appreciated. Alexandre Zani -------------- next part -------------- An HTML attachment was scrubbed... URL: From warem2888 at gmail.com Wed Mar 6 12:00:15 2013 From: warem2888 at gmail.com (Constantine) Date: Wed, 6 Mar 2013 09:00:15 -0800 (PST) Subject: Riley Mason Sucking Message-ID: <2eeada70-f300-4e67-9ace-f85f99391024@googlegroups.com> Riley Mason Sucking http://t.co/84rpqh7W From manishreddytirumala at gmail.com Wed Mar 6 12:00:31 2013 From: manishreddytirumala at gmail.com (Manish) Date: Wed, 6 Mar 2013 09:00:31 -0800 (PST) Subject: Getting started with Python: The ultimate guide with Tips, Tools and Resources Message-ID: Getting started with Python: Tips, Tools and Resources http://lurnq.com/lesson/getting-started-with-python-tips-tools-and-resources/ This is a lesson I published on LurnQ which acts like a beginners guide. I have included various Books, MOOCs, Video Tutorials, Interactive tutorials, exercises which can get you started with Python. I have included my review along with some resources, which I have used while teaching Python myself. Any form of feedback is most welcome. Also, if I missed out on any good learning resource, do leave it as a comment. I will update the list. Thanks From olsr.kamal at gmail.com Wed Mar 6 12:46:27 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Wed, 6 Mar 2013 09:46:27 -0800 (PST) Subject: =?ISO-8859-1?Q?draw_a_line_if_the_color_of_points_of_beginning_and_?= =?ISO-8859-1?Q?end_are_diff=E9rent_from_white?= Message-ID: <181dcc9d-eedf-429e-9307-a49303e9f7c9@googlegroups.com> how can i draw a line if the point of the begining and the end if those points are diff?rent from the white in other exepretion how can i get the color of two points of the begining and the end????? please help me!!!! From breamoreboy at yahoo.co.uk Wed Mar 6 14:32:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 06 Mar 2013 19:32:33 +0000 Subject: =?ISO-8859-1?Q?Re=3A_draw_a_line_if_the_color_of_?= =?ISO-8859-1?Q?points_of_beginning_and_end_are_diff=E9rent_?= =?ISO-8859-1?Q?from_white?= In-Reply-To: <181dcc9d-eedf-429e-9307-a49303e9f7c9@googlegroups.com> References: <181dcc9d-eedf-429e-9307-a49303e9f7c9@googlegroups.com> Message-ID: On 06/03/2013 17:46, olsr.kamal at gmail.com wrote: > how can i draw a line if the point of the begining and the end if those points are diff?rent from the white > in other exepretion how can i get the color of two points of the begining and the end????? > please help me!!!! > Please tell us what package, Python version and OS, plus give us a code sample, what you expect to see and what actually happens. -- Cheers. Mark Lawrence From anthra.norell at bluewin.ch Wed Mar 6 15:57:24 2013 From: anthra.norell at bluewin.ch (F.R.) Date: Wed, 06 Mar 2013 21:57:24 +0100 Subject: =?ISO-8859-1?Q?Re=3A_draw_a_line_if_the_color_of_?= =?ISO-8859-1?Q?points_of_beginning_and_end_are_diff=E9rent_?= =?ISO-8859-1?Q?from_white?= In-Reply-To: <181dcc9d-eedf-429e-9307-a49303e9f7c9@googlegroups.com> References: <181dcc9d-eedf-429e-9307-a49303e9f7c9@googlegroups.com> Message-ID: <5137ADB4.4030409@bluewin.ch> On 03/06/2013 06:46 PM, olsr.kamal at gmail.com wrote: > how can i draw a line if the point of the begining and the end if those points are diff?rent from the white > in other exepretion how can i get the color of two points of the begining and the end????? > please help me!!!! This should get you going. If it doesn't work it will still direct you to the relevant chapters in the tutorial. Frederic def draw_line (image): # image is a PIL Image ( ) # Define your colors WHITE = ~0 # Probably white for all modes. LINE_COLOR = 0 # define # Find end points points = [] pixels = image.load () # Fast pixel access for y in range (image.size [1]): for x in range (image.size [0]): if pixels [x, y] != WHITE points.append ((x, y)) # Join end points draw = ImageDraw.Draw (image) draw.line (points, fill = LINE_COLOR) From matt at tplus1.com Wed Mar 6 12:53:38 2013 From: matt at tplus1.com (W. Matthew Wilson) Date: Wed, 6 Mar 2013 12:53:38 -0500 Subject: Any logger created before calling logging.config.dictCOnfig is not configured Message-ID: It seems like that any logger I create BEFORE calling logging.config.dictConfig does not get configured. Meanwhile, if I configure the logger like I always have, by just setting handlers on root, everything works fine, including the loggers that were created BEFORE I configure logging. I make a lot of module-level log instances. I wrote a simple script to show my problem. Run it like: $ python scratch.py code and then $ python scratch.py dict and see how the logging output is different. ### SCRIPT START """ import argparse import logging import logging.config log1 = logging.getLogger('scratch') def configure_logging_with_dictConfig(): d = { 'formatters': { 'consolefmt': { 'format': '%(asctime)s %(levelname)-10s %(process)-6d %(name)-24s %(lineno)-4d %(message)s'}}, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'consolefmt', 'level': 'DEBUG'}}, 'root': { 'handlers': ['console'], 'level': 'DEBUG'}, 'version': 1} logging.config.dictConfig(d) def configure_logging_with_code(): # Set the logger to DEBUG. logging.root.setLevel(logging.DEBUG) # Now write a custom formatter, so that we get all those different # things. f = logging.Formatter( '%(asctime)s ' '%(levelname)-10s ' '%(process)-6d ' '%(filename)-24s ' '%(lineno)-4d ' '%(message)s ' ) # Set up a stream handler for DEBUG stuff (and greater). sh = logging.StreamHandler() sh.setLevel(logging.DEBUG) sh.setFormatter(f) logging.root.addHandler(sh) def set_up_arguments(): ap = argparse.ArgumentParser() ap.add_argument('how_to_configure', choices=['code', 'dict']) return ap.parse_args() if __name__ == '__main__': args = set_up_arguments() if args.how_to_configure == 'code': configure_logging_with_code() elif args.how_to_configure == 'dict': configure_logging_with_dictConfig() log1.debug('debug from log1') # log2 is created AFTER I configure logging. log2 = logging.getLogger('log2') log2.debug('debug from log2') # Try to figure out what is the difference! Nothing jumps out at me. print "log.root.level: {0}".format(log1.root.level) print "log.root.handlers: {0}".format(log1.root.handlers) print "log1.parent.level: {0}".format(log1.parent.level) print "log1.parent.handlers: {0}".format(log1.parent.handlers) print "log1.level: {0}".format(log1.level) print "log1.handlers: {0}".format(log1.handlers) print "log1.propagate: {0}".format(log1.propagate) print "log1.getEffectiveLevel(): {0}".format(log1.getEffectiveLevel()) ### SCRIPT END -- W. Matthew Wilson matt at tplus1.com http://tplus1.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jhsu802701 at gmail.com Wed Mar 6 13:03:14 2013 From: jhsu802701 at gmail.com (Jason Hsu) Date: Wed, 6 Mar 2013 10:03:14 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? Message-ID: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> I'm currently in the process of learning Ruby on Rails. I'm going through the Rails for Zombies tutorial, and I'm seeing the power of Rails. I still need to get a Ruby on Rails site up and running for the world to see. (My first serious RoR site will profile mutual funds from a value investor's point of view.) I have an existing web site and project called Doppler Value Investing (dopplervalueinvesting.com) that uses Drupal to display the web pages and Python web-scraping scripts to create *.csv and *.html files showing information on individual stocks. My site has a tacked-on feel to it, and I definitely want to change the setup. At a future time, I will rebuild my Doppler Value Investing web site in either Ruby on Rails or Django. The Ruby on Rails route will require rewriting my Python script in Ruby. The Django route will require learning Django. (I'm not sure which one will be easier.) My questions: 1. Why is Ruby on Rails much more popular than Django? 2. Why is there a much stronger demand for Ruby on Rails developers than Django/Python developers? 3. If Doppler Value Investing were your project instead of mine, would you recommend the Ruby on Rails route or the Django route? From marduk at python.net Wed Mar 6 13:24:19 2013 From: marduk at python.net (marduk at python.net) Date: Wed, 06 Mar 2013 13:24:19 -0500 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> Message-ID: <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> > My questions: > 1. Why is Ruby on Rails much more popular than Django? AFAIK Rails got a slightly longer head start than Django. And it has been said that RoR's first killer app was a screencast. A little marketing can go a long way. Since then Django has caught up a bit with RoR in terms of maturity and adoption (I think this is in part because of RoR's adoption slowing due to it not being the NKOTB anymore (not to mention a few security embarrassments)) . > 2. Why is there a much stronger demand for Ruby on Rails developers than > Django/Python developers? I'm not sure how big the difference is, but it's probably related to its early(er) adoption. Same reason that there is a stronger demand for PHP coders. PHP hit it big first, so there is a lot more PHP code to maintain. > 3. If Doppler Value Investing were your project instead of mine, would > you recommend the Ruby on Rails route or the Django route? If you already know/work with Python than I would go the Django route. RoR and Django are not that much different nowadays as far as methodologies. The main differences I think between RoR and Django are that one is Ruby-based and one is Python-based. Other than that, if you can get used to one you can get used to the other. From tim at akwebsoft.com Wed Mar 6 14:16:35 2013 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 6 Mar 2013 10:16:35 -0900 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> Message-ID: <20130306191635.GO17836@mail.akwebsoft.com> * marduk at python.net [130306 09:31]: > > > > > My questions: > > 1. Why is Ruby on Rails much more popular than Django? > If you already know/work with Python than I would go the Django route. > RoR and Django are not that much different nowadays as far as > methodologies. The main differences I think between RoR and Django are > that one is Ruby-based and one is Python-based. Other than that, if you > can get used to one you can get used to the other. I had problems getting django to work on my hostmonster account which is shared hosting and supports fast_cgi but not wsgi. I put that effort on hold for now, as it was just R&D for me, but I would welcome you to take a look at this link where I opened a ticket. https://code.djangoproject.com/ticket/19970 From what I inferred there and from the django ML, the django "community" is indifferent to fastcgi and the shared hosting environment. As someone is new to shared hosting environments (I would mostly on dedicated servers) I get the impression that django is cutting itself out of some (if not a lot) of the market. I don't know about RoR tho.... -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From marduk at letterboxes.org Wed Mar 6 21:13:00 2013 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 06 Mar 2013 21:13:00 -0500 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <20130306191635.GO17836@mail.akwebsoft.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> <20130306191635.GO17836@mail.akwebsoft.com> Message-ID: <1362622380.6289.140661201030025.4479DE68@webmail.messagingengine.com> On Wed, Mar 6, 2013, at 02:16 PM, Tim Johnson wrote: > I had problems getting django to work on my hostmonster account > which is shared hosting and supports fast_cgi but not wsgi. I put > that effort on hold for now, as it was just R&D for me, but > I would welcome you to take a look at this link where I opened a > ticket. > https://code.djangoproject.com/ticket/19970 > From what I inferred there and from the django ML, the django > "community" is indifferent to fastcgi and the shared hosting > environment. As someone is new to shared hosting environments (I > would mostly on dedicated servers) I get the impression that > django is cutting itself out of some (if not a lot) of the market. > I don't know about RoR tho.... I haven't any experience with shared hosting, so can't help you there. I did do some work with lighttpd and fast_cgi and the Django docs worked fine for that. But you're right. wsgi is pretty much the standard for web services in Python, like DB API is to relational database access. Ruby has Rack. Python has WSGI. From tim at akwebsoft.com Wed Mar 6 21:55:12 2013 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 6 Mar 2013 17:55:12 -0900 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <1362622380.6289.140661201030025.4479DE68@webmail.messagingengine.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> <20130306191635.GO17836@mail.akwebsoft.com> <1362622380.6289.140661201030025.4479DE68@webmail.messagingengine.com> Message-ID: <20130307025512.GV17836@mail.akwebsoft.com> * Albert Hopkins [130306 17:14]: > > > On Wed, Mar 6, 2013, at 02:16 PM, Tim Johnson wrote: > > > I had problems getting django to work on my hostmonster account > > which is shared hosting and supports fast_cgi but not wsgi. I put > > that effort on hold for now, as it was just R&D for me, but > > I would welcome you to take a look at this link where I opened a > > ticket. > > https://code.djangoproject.com/ticket/19970 > > From what I inferred there and from the django ML, the django > > "community" is indifferent to fastcgi and the shared hosting > > environment. As someone is new to shared hosting environments (I > > would mostly on dedicated servers) I get the impression that > > django is cutting itself out of some (if not a lot) of the market. > > I don't know about RoR tho.... > > I haven't any experience with shared hosting, so can't help you there. > I did do some work with lighttpd and fast_cgi and the Django docs worked > fine for that. But you're right. wsgi is pretty much the standard for > web services in Python, like DB API is to relational database access. > Ruby has Rack. Python has WSGI. I believe that indifference on the part of Python to fastcgi is a self-inflicted wound. I don't believe that there is any good excuse for such indifference, except for a sort of bureaucratic inertia. It's sad, when you consider how well python is designed and how crappily PHP is designed and how easy it is to set up and deploy drupal in the same environment. I speak from my own experience. respectfully : -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From tim at akwebsoft.com Fri Mar 8 11:35:24 2013 From: tim at akwebsoft.com (Tim Johnson) Date: Fri, 8 Mar 2013 07:35:24 -0900 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <20130307204332.bfbc573759b13b5f9e63612c@lavabit.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <1362594259.18860.140661200857865.2591DE46@webmail.messagingengine.com> <20130306191635.GO17836@mail.akwebsoft.com> <1362622380.6289.140661201030025.4479DE68@webmail.messagingengine.com> <20130307025512.GV17836@mail.akwebsoft.com> <20130307204332.bfbc573759b13b5f9e63612c@lavabit.com> Message-ID: <20130308163524.GA382@mail.akwebsoft.com> * rh [130307 20:21]: > On Wed, 6 Mar 2013 17:55:12 -0900 > Tim Johnson wrote: > > > > > I believe that indifference on the part of Python to fastcgi is a > > self-inflicted wound. I don't believe that there is any good > > excuse for such indifference, except for a sort of bureaucratic > > inertia. It's sad, when you consider how well python is designed > > Python is not indifferent to fastcgi, django is indifferent to fastcgi. > > > and how crappily PHP is designed and how easy it is to set up and > > deploy drupal in the same environment. I speak from my own > > experience. > > -- > http://mail.python.org/mailman/listinfo/python-list I stand corrected, that was a typo. thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From steve+comp.lang.python at pearwood.info Wed Mar 6 18:58:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2013 23:58:07 GMT Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> Message-ID: <5137d80e$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 10:03:14 -0800, Jason Hsu wrote: > My questions: > 1. Why is Ruby on Rails much more popular than Django? 2. Why is there > a much stronger demand for Ruby on Rails developers than Django/Python > developers? Fashion. Demand for technology is usually driven more by copying what everyone else does than by merit. Consider: Fred is a busy manager who has to start a new website and is dissatisfied with the technology he's previously been using. Does he have time to learn Ruby on Rails, Django, CherryPy, Drupal, and thirty other web technologies, to systematically and objectively decide on the best language for the website? Of course not. Even evaluating *two* technologies is probably beyond his time or budget constraints. So he does a search on the Internet, or reads trade magazines, or asks his peers, to find out what everyone else is doing, then copies them. "Oh, they're using Ruby on Rails, it must be good." So now he decides to use Ruby on Rails, advertises for RoR developers, and the cycle continues. But is RoR actually better for his specific situation? Doubtful. Presumably RoR is better for *some* specific jobs. At some point, early in RoR's history, it must have been a *good* solution. But unlikely to be the *best* solution, just better than whatever people were using before. And so RoR will be the easy choice, not the best choice, until such time as RoR is no longer satisfying developers. And then there will be a sudden, and random, phase-change to some other tool, which will become the next easy choice. > 3. If Doppler Value Investing were your project instead of > mine, would you recommend the Ruby on Rails route or the Django route? Neither. I'd be rather tempted to try doing it in CherryPy. But then, what do I know, I'm just as much a follow of fashion as the next guy. -- Steven From wuwei23 at gmail.com Wed Mar 6 20:08:53 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 6 Mar 2013 17:08:53 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <5137d80e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <65418349-6cf5-4faa-8353-29513bf047bd@w9g2000pbf.googlegroups.com> On Mar 7, 9:58?am, Steven D'Aprano wrote: > Neither. I'd be rather tempted to try doing it in CherryPy. But then, > what do I know, I'm just as much a follow of fashion as the next guy. All of the cool kids are using Pyramid these days. From rustompmody at gmail.com Wed Mar 6 21:58:12 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 6 Mar 2013 18:58:12 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> Message-ID: <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> On Mar 6, 11:03?pm, Jason Hsu wrote: > I'm currently in the process of learning Ruby on Rails. ?I'm going through the Rails for Zombies tutorial, and I'm seeing the power of Rails. > > I still need to get a Ruby on Rails site up and running for the world to see. ?(My first serious RoR site will profile mutual funds from a value investor's point of view.) > > I have an existing web site and project called Doppler Value Investing (dopplervalueinvesting.com) that uses Drupal to display the web pages and Python web-scraping scripts to create *.csv and *.html files showing information on individual stocks. ?My site has a tacked-on feel to it, and I definitely want to change the setup. > > At a future time, I will rebuild my Doppler Value Investing web site in either Ruby on Rails or Django. ?The Ruby on Rails route will require rewriting my Python script in Ruby. ?The Django route will require learning Django. ?(I'm not sure which one will be easier.) > > My questions: > 1. ?Why is Ruby on Rails much more popular than Django? "Where there is choice there is no freedom" http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamurti-8th-public-talk Python-for-web offered so much choice -- zope, django, turbogears, cherrypy, web.py etc etc -- that the newbie was completely drowned. With Ruby there is only one choice to make -- choose Ruby and rails follows. Anyone who's used emacs will know this as the bane of FLOSS software -- 100 ways of doing something and none perfect -- IOW too much spurious choice. GvR understood and rigorously implemented a dictum that Nicklaus Wirth formulated decades ago -- "The most important thing about language design is what to leave out." Therefore Python is a beautiful language. Unfortunately the same leadership did not carry over to web frameworks and so we have a mess. I guess the situation is being corrected with google putting its artillery behind django. From rantingrickjohnson at gmail.com Thu Mar 7 01:09:30 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 6 Mar 2013 22:09:30 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <3111fadd-1841-4b4a-9d3f-f96b702857e5@googlegroups.com> On Wednesday, March 6, 2013 8:58:12 PM UTC-6, rusi wrote: > "Where there is choice there is no freedom" > [snip link] > > Python-for-web offered so much choice -- zope, django, turbogears, > cherrypy, web.py etc etc -- that the newbie was completely drowned. > With Ruby there is only one choice to make -- choose Ruby and rails > follows. Indeed! "Costco", a wholesale grocery chain, realized the same issue of consumers being drowned by multiplicity, and have been very successful by intelligently narrowing those choices for it's customer base. From rui.maciel at gmail.com Thu Mar 7 04:28:41 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Thu, 07 Mar 2013 09:28:41 +0000 Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: rusi wrote: > Anyone who's used emacs will know this as the bane of FLOSS software > -- 100 ways of doing something and none perfect -- IOW too much > spurious choice. This is a fallacy. Just because someone claims that "there are 100 ways of doing something and none perfect", it doesn't mean that restricting choice leads to perfection. It doesn't. It only leads to getting stuck with a poor solution with no possibility of improving your life by switching to a better alternative. Worse, a complete lack of alternatives leads to a complete lack of competition, and therefore the absense of incentives to work on improvements. You know, progress. Choice is good. Don't pretend it isn't. It's one of the reasons we have stuff like Python or Ruby nowadays, for example. Rui Maciel From svenito at gmail.com Thu Mar 7 04:52:26 2013 From: svenito at gmail.com (Sven) Date: Thu, 7 Mar 2013 09:52:26 +0000 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: On 7 March 2013 09:28, Rui Maciel wrote: > rusi wrote: > > > Anyone who's used emacs will know this as the bane of FLOSS software > > -- 100 ways of doing something and none perfect -- IOW too much > > spurious choice. > > > This is a fallacy. Just because someone claims that "there are 100 ways of > doing something and none perfect", it doesn't mean that restricting choice > leads to perfection. It doesn't. It only leads to getting stuck with a > poor solution with no possibility of improving your life by switching to a > better alternative. > This thread reminds me of an article I read recently: http://rubiken.com/blog/2013/02/11/web-dev-a-crazy-world.html It's mostly a matter of having enough time to evaluate what's best for you. In the case of RoR vs Django, you will (assuming zero knowledge) need to learn a language, then a framework. That's quite a time consuming task. Personally I've opted for Django because I've used Python for years. I've written some Ruby in the past, but I not enough to make me choose RoR over Django to get stuff done. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrickjohnson at gmail.com Thu Mar 7 11:20:47 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 7 Mar 2013 08:20:47 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <8394cfb6-5a3c-4ca6-808c-de16447f1407@googlegroups.com> On Thursday, March 7, 2013 3:28:41 AM UTC-6, Rui Maciel wrote: > rusi wrote: > > > Anyone who's used emacs will know this as the bane of FLOSS software > > -- 100 ways of doing something and none perfect -- IOW too much > > spurious choice. > > This is a fallacy. Just because someone claims that "there are 100 ways of > doing something and none perfect", it doesn't mean that restricting choice > leads to perfection. It doesn't. It only leads to getting stuck with a > poor solution with no possibility of improving your life by switching to a > better alternative. Not true. The "one solution" is only poor when the dev team of that "one solution" become resistant to change. But i don't think anybody would agree that a *single* solution could exist for ALL problems (at least not in the early stages of defining a "problem domain'), although a *single* solution could exist for MOST problems. > Worse, a complete lack of alternatives leads to a complete lack of > competition, and therefore the absense of incentives to work on > improvements. You know, progress. Wrong again. You don't need 10 versions of the same software to maintain evolution. Your premise is that competition between multiple versions of, what is basically the same exact software with TINY difference, creates evolution; WRONG!; competition cannot exist without IDEAS, and it is the presence of conflicting IDEAS that create evolution in software development, NOT fragmentation. Fragmenting the pool of great software developers into "zeoltry sects" is slowing evolution. What you do need is a bare minimum of projects that are perpetually open to outside ideas and constant evolution. You goal should be to work towards a single monolithic solution. But you must also keep in mind that the single solution must continue to evolve. > Choice is good. Don't pretend it isn't. It's one of the reasons we have > stuff like Python or Ruby nowadays, for example. Python and Ruby should both be superseded by a language that takes the best from both languages. Python and Ruby are so much alike in so many ways it's really silly. I think the main split point at this time is the "PythonZen vs TIMTOWDI". Sure there are some glaring differences in Ruby vs Python methodology, but at the end of the day, An iterator is an iterator, a class is a class, a sequence is a sequence, a mapping is a mapping, a conditional is a conditional, a variable is a variable. Python has list comprehensions and Ruby has Array.[select|collect]. But let's investigate a much better example where multiplicity has fragmented a problem domain into OBLIVION, and that domain is Graphical User Interfaces! Python has tons of them available. How many different versions of a GUI window do we REALLY need. People, a StaticText is a StaticText, a Dialog is a Dialog, a ProgressBar is a ProgressBar, an EditText is an EditText, a Canvas is a Canvas, a NoteBook is a NoteBook, a ListControl is a ListControl; BLAH! If we are going to split into "sects", then we should at least abstract away the parts that we agree on, and then collectively EXTEND our selfish versions from that single abstraction. Do you people realize how far we could have evolved a single GUI library by now if we were not wasting our time re-inventing the same old widgets again and again just because we cannot agree on minutiae! You would rather fragment the community and slow evolution than to make compromises and produce something greater than the combination of ALL the multiple projects out there? Fragmentation is foolish. We need to focus or energies wisely and work towards a common goal. This is the path of intelligent evolution, not a billion years of naive "dice rolling". From rosuav at gmail.com Thu Mar 7 11:33:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 03:33:07 +1100 Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: <8394cfb6-5a3c-4ca6-808c-de16447f1407@googlegroups.com> References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> <8394cfb6-5a3c-4ca6-808c-de16447f1407@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 3:20 AM, Rick Johnson wrote: > If we are going to split into "sects", then we should at least abstract away the parts that we agree on, and then collectively EXTEND our selfish versions from that single abstraction. We've already done that. We've agreed that a program is stored in zero or more files. Everything after that is an extension from that basic abstraction. ChrisA From rustompmody at gmail.com Thu Mar 7 13:00:19 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 7 Mar 2013 10:00:19 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <5872a992-6a13-463e-a327-25243a890fa5@m3g2000pba.googlegroups.com> On Mar 7, 2:52?pm, Sven wrote: > This thread reminds me of an article I read recently: > > http://rubiken.com/blog/2013/02/11/web-dev-a-crazy-world.html Ha Ha! Thanks for that. Of course its exaggerated. But then hyperbole can tell a story that logic cannot. From rowen at uw.edu Thu Mar 7 16:08:21 2013 From: rowen at uw.edu (Russell E. Owen) Date: Thu, 07 Mar 2013 13:08:21 -0800 Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: In article <3d9fe0b2-7931-4ab6-8929-235460729c64 at q9g2000pbf.googlegroups.com>, rusi wrote: > On Mar 6, 11:03?pm, Jason Hsu wrote: > > I'm currently in the process of learning Ruby on Rails. ?I'm going through > > the Rails for Zombies tutorial, and I'm seeing the power of Rails. > > > > I still need to get a Ruby on Rails site up and running for the world to > > see. ?(My first serious RoR site will profile mutual funds from a value > > investor's point of view.) > > > > I have an existing web site and project called Doppler Value Investing > > (dopplervalueinvesting.com) that uses Drupal to display the web pages and > > Python web-scraping scripts to create *.csv and *.html files showing > > information on individual stocks. ?My site has a tacked-on feel to it, and > > I definitely want to change the setup. > > > > At a future time, I will rebuild my Doppler Value Investing web site in > > either Ruby on Rails or Django. ?The Ruby on Rails route will require > > rewriting my Python script in Ruby. ?The Django route will require learning > > Django. ?(I'm not sure which one will be easier.) > > > > My questions: > > 1. ?Why is Ruby on Rails much more popular than Django? > > "Where there is choice there is no freedom" > http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamurti-8th-pu > blic-talk > > Python-for-web offered so much choice -- zope, django, turbogears, > cherrypy, web.py etc etc -- that the newbie was completely drowned. > With Ruby there is only one choice to make -- choose Ruby and rails > follows. > > Anyone who's used emacs will know this as the bane of FLOSS software > -- 100 ways of doing something and none perfect -- IOW too much > spurious choice. > > GvR understood and rigorously implemented a dictum that Nicklaus Wirth > formulated decades ago -- "The most important thing about language > design is what to leave out." Therefore Python is a beautiful > language. Unfortunately the same leadership did not carry over to web > frameworks and so we have a mess. > > I guess the situation is being corrected with google putting its > artillery behind django. I strongly agree. The fact that there is no de-facto standard web system for Python is a major problem. Consider: - With too many choice one has no idea which projects will be maintained and which will be abandoned. - Expert knowledge among users is spread more thinly. - The effort of contributors is diluted. Years ago when I had some simple web programming to do I looked at the choices, gave up and used PHP (which I hated, but got the job done). If RoR had been available I would have been much happier using that. In my opinion the plethora of Python web frameworks is a serious detriment to trust and wider acceptance of Python for this use. If Django is becoming this standard, that is excellent news. Some choice is good, but in my opinion too much choice and lack of a de-facto standard are very detrimental. -- Russell From rustompmody at gmail.com Thu Mar 7 22:46:11 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 7 Mar 2013 19:46:11 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <10e6f5a2-0f1b-4a10-8670-b96286507347@l4g2000pbn.googlegroups.com> On Mar 8, 2:08?am, "Russell E. Owen" wrote: > In article > <3d9fe0b2-7931-4ab6-8929-235460729... at q9g2000pbf.googlegroups.com>, > > > > > > > > > > ?rusi wrote: > > On Mar 6, 11:03?pm, Jason Hsu wrote: > > > I'm currently in the process of learning Ruby on Rails. ?I'm going through > > > the Rails for Zombies tutorial, and I'm seeing the power of Rails. > > > > I still need to get a Ruby on Rails site up and running for the world to > > > see. ?(My first serious RoR site will profile mutual funds from a value > > > investor's point of view.) > > > > I have an existing web site and project called Doppler Value Investing > > > (dopplervalueinvesting.com) that uses Drupal to display the web pages and > > > Python web-scraping scripts to create *.csv and *.html files showing > > > information on individual stocks. ?My site has a tacked-on feel to it, and > > > I definitely want to change the setup. > > > > At a future time, I will rebuild my Doppler Value Investing web site in > > > either Ruby on Rails or Django. ?The Ruby on Rails route will require > > > rewriting my Python script in Ruby. ?The Django route will require learning > > > Django. ?(I'm not sure which one will be easier.) > > > > My questions: > > > 1. ?Why is Ruby on Rails much more popular than Django? > > > "Where there is choice there is no freedom" > >http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamur... > > blic-talk > > > Python-for-web offered so much choice -- zope, django, turbogears, > > cherrypy, web.py etc etc -- that the newbie was completely drowned. > > With Ruby there is only one choice to make -- choose Ruby and rails > > follows. > > > Anyone who's used emacs will know this as the bane of FLOSS software > > -- 100 ways of doing something and none perfect -- IOW too much > > spurious choice. > > > GvR understood and rigorously implemented a dictum that Nicklaus Wirth > > formulated decades ago -- "The most important thing about language > > design is what to leave out." Therefore Python is a beautiful > > language. ?Unfortunately the same leadership did not carry over to web > > frameworks and so we have a mess. > > > I guess the situation is being corrected with google putting its > > artillery behind django. > > I strongly agree. The fact that there is no de-facto standard web system > for Python is a major problem. Consider: > - With too many choice one has no idea which projects will be maintained > and which will be abandoned. > - Expert knowledge among users is spread more thinly. > - The effort of contributors is diluted. > > Years ago when I had some simple web programming to do I looked at the > choices, gave up and used PHP (which I hated, but got the job done). If > RoR had been available I would have been much happier using that. > > In my opinion the plethora of Python web frameworks is a serious > detriment to trust and wider acceptance of Python for this use. If > Django is becoming this standard, that is excellent news. > > Some choice is good, but in my opinion too much choice and lack of a > de-facto standard are very detrimental. > > -- Russell Hmm? I am not sure I agree with your agreement :-) Its not so much "some choice" vs "too much choice" as "real choice" vs "spurious choice". Python or C or Haskell is a real choice. Python or Ruby is a spurious choice. From rantingrickjohnson at gmail.com Fri Mar 8 11:19:02 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 8 Mar 2013 08:19:02 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? In-Reply-To: References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <9748aa63-9b06-4b75-8881-bda43f7c6d4e@googlegroups.com> On Thursday, March 7, 2013 10:50:52 PM UTC-6, rh wrote: > Choices are good. [...] Having one choice is a mess. And > look back at history and current events Sometimes "choices" are forced upon you without your consent or even without regard for the end users' well-being. In this case "choices" are no longer "choices", they become unnecessary dead weight on the backs of users, they become malevolent multiplicities. ============================================================ Take cell phones for example. ============================================================ Nobody would argue that having many different cell phones available in the marketplace, each with different capabilities, is a good thing; however, one of the downsides is that the manufactures refuse to comply with universal standards for things like "charger receptacles" and so you end up needing to buy a new charger for every new phone. I have a box in one of my closets with probably 20 of them, and they're all different! Some have the same receptacle, but different output. Many are even from the same damn manufacturers and not transferable between different models of the same manufacture!!! *Wise observer blubbered:* "Rick, what you describe is more a result of corporate greed than a good analogy for the ills of web programming, this is open source software, nobody is being paid. The developers are not intending to extort the lemmings under the guise of a self-induced hardware incompatibility ." Yes you are correct, the motivation to fragment is not due to greedy wishes to become rich, no, the motivation is one of these two: * Selfishness: (They want to create something is "new", but really just the same old $hit with a different name) * Static stubbornness of current module developers does not allow for change, so they are forced to start a new project. Either excuse causes damaging fragmentation of the community and the problem. It injects multiplicity and asininity. The so called "choices" (which are really the same thing with a a shiny new name tag) then become an obstacle for new users. The whole system slows to crawl, stagnates, and inevitably becomes extinct. This is the future of Python web programming (and the language itself) if we keep refusing to change from within. Fragmentation WILL destroy us. From rustompmody at gmail.com Fri Mar 8 12:30:20 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 8 Mar 2013 09:30:20 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <2eeb2376-980f-4204-8b5a-e0c2b7da39a3@kn5g2000pbb.googlegroups.com> On Mar 8, 9:50?am, rh wrote: > Choices are good. > Having one choice is a mess. And look back at history and current events > if you don't see that. See http://www.perl.com/pub/1999/03/pm.html for how a real post-modern hip language gives endless choice. Also called TIMTOWTDI. Or perl From steve+comp.lang.python at pearwood.info Fri Mar 8 12:47:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2013 17:47:36 GMT Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> Message-ID: <513a2437$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 18:58:12 -0800, rusi wrote: >> My questions: >> 1. ?Why is Ruby on Rails much more popular than Django? > > "Where there is choice there is no freedom" > http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu- krishnamurti-8th-public-talk Surely that should be, where there is NO choice there is no freedom. You must work down the mines every day until you die. Are you free? You must use Rails for your web app. Are you free? The "Paradox of Choice" is real, that is, *too* much choice can lead to paralysis. Freedom is not an unmitigated good. But there are ways to work around that, starting with the simple fact that products often are aimed at niche markets and so are not actually direct competitors. The hard part is deciding what niche you exist in, not what product you want. [...] > GvR understood and rigorously implemented a dictum that Nicklaus Wirth > formulated decades ago -- "The most important thing about language > design is what to leave out." Therefore Python is a beautiful language. > Unfortunately the same leadership did not carry over to web frameworks > and so we have a mess. The entire software ecosystem is not equivalent to designing a single language. Apart from the practical matter that it would require a totalitarian dictator to declare that there is One True web framework which everyone must use on pain of death, there is also the little matter that individual products can concentrate on different strengths. No one product can solve all problems -- you can't have a web framework which is simultaneously lightweight for those with small needs AND heavyweight for those with large needs. (Or at least, it is *incredibly difficult* to have a single product be all things to all people.) 'I'm sure we can pull together, sir.' Lord Vetinari raised his eyebrows. 'Oh, I do hope not, I really do hope not. Pulling together is the aim of despotism and tyranny. Free men pull in all kinds of directions.' He smiled. 'It's the only way to make progress.' - Terry Pratchett, "The Truth" -- Steven From rustompmody at gmail.com Fri Mar 8 23:40:37 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 8 Mar 2013 20:40:37 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> <3d9fe0b2-7931-4ab6-8929-235460729c64@q9g2000pbf.googlegroups.com> <513a2437$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <01322e07-cc18-4f02-9828-beb0cdc7064a@kt16g2000pbb.googlegroups.com> On Mar 8, 10:47?pm, Steven D'Aprano wrote: > On Wed, 06 Mar 2013 18:58:12 -0800, rusi wrote: > >> My questions: > >> 1. ?Why is Ruby on Rails much more popular than Django? > > > "Where there is choice there is no freedom" > >http://www.jiddu-krishnamurti.net/en/1954/1954-03-03-jiddu-krishnamurti-8th-public-talk > > Surely that should be, where there is NO choice there is no freedom. > > The "Paradox of Choice" is real, that is, *too* much choice can lead to > paralysis. Thanks for that 'google-tip'. I guess a secular outlook would have wider reach than a guru like Krishnamurti. In any case http://en.wikipedia.org/wiki/The_Paradox_of_Choice:_Why_More_Is_Less says more or less what Krishnamurti does (apart from the absolutes). From rustompmody at gmail.com Wed Mar 6 23:16:51 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 6 Mar 2013 20:16:51 -0800 (PST) Subject: Why is Ruby on Rails more popular than Django? References: <2fc87695-9d0b-45b3-ae96-98e0591b30a0@googlegroups.com> Message-ID: <322c7d37-5fb3-4f15-b88f-9c8a83b7757b@kw7g2000pbb.googlegroups.com> On Mar 6, 11:03?pm, Jason Hsu wrote: > I'm currently in the process of learning Ruby on Rails. ?I'm going through the Rails for Zombies tutorial, and I'm seeing the power of Rails. > > I still need to get a Ruby on Rails site up and running for the world to see. ?(My first serious RoR site will profile mutual funds from a value investor's point of view.) > > I have an existing web site and project called Doppler Value Investing (dopplervalueinvesting.com) that uses Drupal to display the web pages and Python web-scraping scripts to create *.csv and *.html files showing information on individual stocks. ?My site has a tacked-on feel to it, and I definitely want to change the setup. > > At a future time, I will rebuild my Doppler Value Investing web site in either Ruby on Rails or Django. ?The Ruby on Rails route will require rewriting my Python script in Ruby. ?The Django route will require learning Django. ?(I'm not sure which one will be easier.) It is a natural programmer instinct that a uni-language solution is felt cleaner than a multi-language one. This feeling is valid under the following assumptions: - You are starting from ground up - The investment in learning something new is not considered significant In your case, with a site already up (maybe with a tacked on feel) and learning django a significant effort compared to directly coding in RoR, you should look at polyglot solutions more carefully (eg not directly relevant ... something like http://www.igvita.com/2009/03/20/ruby-polyglot-talking-with-erlang/ ) IOW code your site in RoR and call out to your python scraper-scripts may be an option to consider. From bv8bv8bv8 at gmail.com Wed Mar 6 15:39:30 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Wed, 6 Mar 2013 12:39:30 -0800 (PST) Subject: Introducing Islam to Non--Muslims Message-ID: <834b200d-21c8-42ae-bcc5-34a42d62003b@g8g2000vbf.googlegroups.com> Introducing Islam to Non--Muslims Shaikh Yusuf Estes Explains the basics of Islam including the five pillars of Islam to Non-Muslims. http://www.youtube.com/v/gBlCnpUkobE?rel=0 thank you From dzabel at snafu.de Wed Mar 6 17:30:48 2013 From: dzabel at snafu.de (Dirk Zabel) Date: Wed, 06 Mar 2013 23:30:48 +0100 Subject: debugging with idle Message-ID: Hi, I am trying to debug a script using the idle debug control. I want to see the current source line which is executed, so I select the "Source" checkbox. If I step through the program, the editor window with the source is popping up, but the current source line is not marked. Only If I activate the source window by clicking on the window top, the marker appears. This I have to repeat for every step: click on "step" button, click on source window, click on "step" button, click on source window ... very boring. The problem occurs with python 3.3 on Windows XP SP3 as well as on Windows 7 X64, SP1. Running python 3.2 on Ubuntu 12.4 LTE the problem does not come up. Here the currently executed line stays marked regardless whether the source window is active or not. Any help is welcome. Regards Dirk From tjreedy at udel.edu Wed Mar 6 19:17:04 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 19:17:04 -0500 Subject: debugging with idle In-Reply-To: References: Message-ID: On 3/6/2013 5:30 PM, Dirk Zabel wrote: > Hi, > I am trying to debug a script using the idle debug control. I want to > see the current source line which is executed, so I select the "Source" > checkbox. If I step through the program, the editor window with the > source is popping up, but the current source line is not marked. Only If > I activate the source window by clicking on the window top, the marker > appears. This I have to repeat for every step: click on "step" button, > click on source window, click on "step" button, click on source window > ... very boring. > The problem occurs with python 3.3 on Windows XP SP3 as well as on > Windows 7 X64, SP1. I use IDLE and work on IDLE issues, but have never used the debug window before. It looks useful -- and its operation should be documented. I believe I duplicated your report with 3.3 on win 7. > Running python 3.2 on Ubuntu 12.4 LTE the problem does not come up. Here > the currently executed line stays marked regardless whether the source > window is active or not. You changed both python version and os. Which change made the difference? I believe I duplicated your problem also with 3.2 on win 7, so perhaps it is the OS. If you possibly can, load 3.3 on Ubuntu and see if you still get the correct behavior. Then open an issue on the tracker. bugs.python.org. -- Terry Jan Reedy From techgeek201 at gmail.com Wed Mar 6 18:39:42 2013 From: techgeek201 at gmail.com (eli m) Date: Wed, 6 Mar 2013 15:39:42 -0800 (PST) Subject: Insert comma in number? Message-ID: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number. For example: instead of 1000 it would say 1,000 From iandouglas736 at gmail.com Wed Mar 6 18:51:10 2013 From: iandouglas736 at gmail.com (ian douglas) Date: Wed, 06 Mar 2013 15:51:10 -0800 Subject: Insert comma in number? In-Reply-To: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: <5137D66E.2080800@gmail.com> On 03/06/2013 03:39 PM, eli m wrote: > I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number. > For example: instead of 1000 it would say 1,000 pip install humanize import humanize my_integer = 12345678 commafied_integer = humanize.intcomma(my_integer) print commafied_integer output: 12,345,678 From clp2 at rebertia.com Wed Mar 6 19:07:11 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 6 Mar 2013 16:07:11 -0800 Subject: Insert comma in number? In-Reply-To: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: On Wed, Mar 6, 2013 at 3:39 PM, eli m wrote: > I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number. > For example: instead of 1000 it would say 1,000 Use the "," (i.e. comma) format() specifier directive. See http://docs.python.org/2/library/string.html#format-specification-mini-language See also: http://www.python.org/dev/peps/pep-0378/ Cheers, Chris From tjreedy at udel.edu Wed Mar 6 20:28:56 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Mar 2013 20:28:56 -0500 Subject: Insert comma in number? In-Reply-To: References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: On 3/6/2013 7:07 PM, Chris Rebert wrote: > On Wed, Mar 6, 2013 at 3:39 PM, eli m wrote: >> I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number. >> For example: instead of 1000 it would say 1,000 > > Use the "," (i.e. comma) format() specifier directive. See > http://docs.python.org/2/library/string.html#format-specification-mini-language > See also: http://www.python.org/dev/peps/pep-0378/ >>> format(12345234434, ',d') '12,345,234,434' >>> '{:,d}'.format(333333333333) '333,333,333,333' -- Terry Jan Reedy From __peter__ at web.de Thu Mar 7 02:55:43 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Mar 2013 08:55:43 +0100 Subject: Insert comma in number? References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: eli m wrote: > I have a python program that accepts input and calculates the factorial of > that number, and i want to know if i can make it so commas get inserted in > the number. For example: instead of 1000 it would say 1,000 Last not least there's the option to employ locale-aware formatting: >>> import locale >>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8") 'en_US.UTF-8' >>> locale.format("%d", 12345, grouping=True) '12,345' In German usage of "." and "," is reversed, so: >>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8") 'de_DE.UTF-8' >>> locale.format("%d", 12345, grouping=True) '12.345' From capt-obvious at yandex.ru Thu Mar 7 03:30:35 2013 From: capt-obvious at yandex.ru (Paul Volkov) Date: Thu, 7 Mar 2013 12:30:35 +0400 Subject: Insert comma in number? In-Reply-To: References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: 2013/3/7 Peter Otten <__peter__ at web.de>: > Last not least there's the option to employ locale-aware formatting: > >>>> import locale >>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8") > 'en_US.UTF-8' >>>> locale.format("%d", 12345, grouping=True) > '12,345' > > In German usage of "." and "," is reversed, so: > >>>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8") > 'de_DE.UTF-8' >>>> locale.format("%d", 12345, grouping=True) > '12.345' Does this locale-aware example only work on UNIX? From __peter__ at web.de Thu Mar 7 03:58:24 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Mar 2013 09:58:24 +0100 Subject: Insert comma in number? References: <9c8df3b5-510a-4d00-a3ff-0c59799dcded@googlegroups.com> Message-ID: Paul Volkov wrote: > 2013/3/7 Peter Otten <__peter__ at web.de>: >> Last not least there's the option to employ locale-aware formatting: >> >>>>> import locale >>>>> locale.setlocale(locale.LC_ALL, "en_US.UTF-8") >> 'en_US.UTF-8' >>>>> locale.format("%d", 12345, grouping=True) >> '12,345' >> >> In German usage of "." and "," is reversed, so: >> >>>>> locale.setlocale(locale.LC_ALL, "de_DE.UTF-8") >> 'de_DE.UTF-8' >>>>> locale.format("%d", 12345, grouping=True) >> '12.345' > > Does this locale-aware example only work on UNIX? If you have Windows in mind: I don't know what it takes to get multiple locales on a Windows system, but for the default locale that you can specify with locale.setlocale(locale.LC_ALL, "") it should work. From jjposner at optimum.net Thu Mar 7 14:06:03 2013 From: jjposner at optimum.net (John Posner) Date: Thu, 07 Mar 2013 14:06:03 -0500 Subject: Insert comma in number? In-Reply-To: References: Message-ID: <5138E51B.3050803@optimum.net> Peter Otten wrote: > Last not least there's the option to employ locale-aware formatting: Not quite last ... there's the mind-bending regular expression route: import re re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "12345678") # 12,345,678 re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "-54321") # -54,321 -John From roy at panix.com Wed Mar 6 22:20:11 2013 From: roy at panix.com (Roy Smith) Date: Wed, 06 Mar 2013 22:20:11 -0500 Subject: Interesting list() un-optimization Message-ID: I stumbled upon an interesting bit of trivia concerning lists and list comprehensions today. We use mongoengine as a database model layer. A mongoengine query returns an iterable object called a QuerySet. The "obvious" way to create a list of the query results would be: my_objects = list(my_query_set) and, indeed, that works. But, then I found this code: my_objects = [obj for obj in my_query_set] which seemed a bit silly. I called over the guy who wrote it and asked him why he didn't just write it using list(). I was astounded when it turned out there's a good reason! Apparently, list() has an "optimization" where it calls len() on its argument to try and discover the number of items it's going to put into the list. Presumably, list() uses this information to pre-allocate the right amount of memory the first time, without any resizing. If len() fails, it falls back to just iterating and resizing as needed. Normally, this would be a win. The problem is, QuerySets have a __len__() method. Calling it is a lot faster than iterating over the whole query set and counting the items, but it does result in an additional database query, which is a lot slower than the list resizing! Writing the code as a list comprehension prevents list() from trying to optimize when it shouldn't! From davea at davea.name Wed Mar 6 22:38:58 2013 From: davea at davea.name (Dave Angel) Date: Wed, 06 Mar 2013 22:38:58 -0500 Subject: Interesting list() un-optimization In-Reply-To: References: Message-ID: <51380BD2.8050704@davea.name> On 03/06/2013 10:20 PM, Roy Smith wrote: > I stumbled upon an interesting bit of trivia concerning lists and list > comprehensions today. > > We use mongoengine as a database model layer. A mongoengine query > returns an iterable object called a QuerySet. The "obvious" way to > create a list of the query results would be: > > my_objects = list(my_query_set) > > and, indeed, that works. But, then I found this code: > > my_objects = [obj for obj in my_query_set] > > which seemed a bit silly. I called over the guy who wrote it and asked > him why he didn't just write it using list(). I was astounded when it > turned out there's a good reason! > > Apparently, list() has an "optimization" where it calls len() on its > argument to try and discover the number of items it's going to put into > the list. Presumably, list() uses this information to pre-allocate the > right amount of memory the first time, without any resizing. If len() > fails, it falls back to just iterating and resizing as needed. > Normally, this would be a win. > > The problem is, QuerySets have a __len__() method. Calling it is a lot > faster than iterating over the whole query set and counting the items, > but it does result in an additional database query, which is a lot > slower than the list resizing! Writing the code as a list comprehension > prevents list() from trying to optimize when it shouldn't! > That is very interesting. list() assumes the __len__() method would be very quick. Perhaps list() should take an optional second argument that specifies the initial length to allocate. That way code that either doesn't want __len__() to be used, or that already knows a reasonable number to use, can supply the value to preallocate. -- DaveA From python.list at tim.thechases.com Wed Mar 6 22:57:35 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 6 Mar 2013 21:57:35 -0600 Subject: Interesting list() un-optimization In-Reply-To: References: Message-ID: <20130306215735.649932ee@bigbox.christie.dr> On 2013-03-06 22:20, Roy Smith wrote: > I stumbled upon an interesting bit of trivia concerning lists and > list comprehensions today. I agree with Dave Angel that this is interesting. A little testing shows that this can be rewritten as my_objects = list(iter(my_query_set)) which seems to then skip the costly __len__ call. Performance geeks are welcome to time it against the list-comprehension version :-) -tkc class Foo(object): def __init__(self): self.items = range(10) def __iter__(self): return iter(self.items) def __len__(self): print "Calling costly __len__" return len(self.items) print "Ensuring we can iterate over it:" for x in Foo(): print x print "\nJust call list():" lst = list(Foo()) print lst print "\nCall list(iter())" lst = list(iter(Foo())) print lst From wolfgang.maier at biologie.uni-freiburg.de Thu Mar 7 06:22:56 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 7 Mar 2013 11:22:56 +0000 (UTC) Subject: Interesting list() un-optimization References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: Tim Chase tim.thechases.com> writes: > On 2013-03-06 22:20, Roy Smith wrote: > > I stumbled upon an interesting bit of trivia concerning lists and > > list comprehensions today. > > A little testing > shows that this can be rewritten as > > my_objects = list(iter(my_query_set)) > > which seems to then skip the costly __len__ call. Performance geeks > are welcome to time it against the list-comprehension version > > class Foo(object): > def __init__(self): > self.items = range(10) > def __iter__(self): > return iter(self.items) > def __len__(self): > print "Calling costly __len__" > return len(self.items) > Well, it skips the costly len() call because your iter(Foo()) returns iter(range()) under the hood and list() uses that object's __len__() method. In most cases, such a workaround will not be feasible. Why should iter(QuerySet()) have a faster __len__() method defined than QuerySet() itself. Most likely, iter(QuerySet()) just returns self anyway? Best, Wolfgang From ian.g.kelly at gmail.com Thu Mar 7 11:00:32 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Mar 2013 09:00:32 -0700 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier wrote: > Well, it skips the costly len() call because your iter(Foo()) returns > iter(range()) under the hood and list() uses that object's __len__() method. Iterators do not generally have __len__ methods. >>> len(iter(range(10))) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'range_iterator' has no len() > In > most cases, such a workaround will not be feasible. Why should iter(QuerySet()) > have a faster __len__() method defined than QuerySet() itself. iter(QuerySet()) should not have any __len__ method defined at all, which is why the optimization would be skipped. > Most likely, > iter(QuerySet()) just returns self anyway? But on this point, you are correct. The mongoengine QuerySet.__iter__ method is defined as: def __iter__(self): self.rewind() return self This is unfortunate design. Not only does it mean that the iterator's __len__ method cannot be trusted (what should the __len__ of a partially exhausted iterator return?), but it also means that requesting an iterator over the QuerySet will also silently invalidate any existing iterators. From christian at python.org Thu Mar 7 11:20:52 2013 From: christian at python.org (Christian Heimes) Date: Thu, 07 Mar 2013 17:20:52 +0100 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: Am 07.03.2013 17:00, schrieb Ian Kelly: > On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier > wrote: >> Well, it skips the costly len() call because your iter(Foo()) returns >> iter(range()) under the hood and list() uses that object's __len__() method. > > Iterators do not generally have __len__ methods. > >>>> len(iter(range(10))) > Traceback (most recent call last): > File "", line 1, in > TypeError: object of type 'range_iterator' has no len() But iterators have a length hint method that are used for some optimizations and preallocations, too. >>> i = iter(range(10)) >>> i.__length_hint__() 10 See http://www.python.org/dev/peps/pep-0424/ Christian From ian.g.kelly at gmail.com Thu Mar 7 12:31:44 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Mar 2013 10:31:44 -0700 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On Thu, Mar 7, 2013 at 9:20 AM, Christian Heimes wrote: > Am 07.03.2013 17:00, schrieb Ian Kelly: >> On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier >> wrote: >>> Well, it skips the costly len() call because your iter(Foo()) returns >>> iter(range()) under the hood and list() uses that object's __len__() method. >> >> Iterators do not generally have __len__ methods. >> >>>>> len(iter(range(10))) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: object of type 'range_iterator' has no len() > > But iterators have a length hint method that are used for some > optimizations and preallocations, too. > >>>> i = iter(range(10)) >>>> i.__length_hint__() > 10 > > See http://www.python.org/dev/peps/pep-0424/ Didn't know about that, thanks. Presumably a proper iter(QuerySet()) object could implement __length_hint__ in an efficient manner rather than by just calling the __len__ of the underlying QuerySet, From stefan_ml at behnel.de Thu Mar 7 14:19:07 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 07 Mar 2013 20:19:07 +0100 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: Ian Kelly, 07.03.2013 18:31: > On Thu, Mar 7, 2013 at 9:20 AM, Christian Heimes wrote: >> Am 07.03.2013 17:00, schrieb Ian Kelly: >>> On Thu, Mar 7, 2013 at 4:22 AM, Wolfgang Maier wrote: >>>> Well, it skips the costly len() call because your iter(Foo()) returns >>>> iter(range()) under the hood and list() uses that object's __len__() method. >>> >>> Iterators do not generally have __len__ methods. >>> >>> >>> len(iter(range(10))) >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: object of type 'range_iterator' has no len() >> >> But iterators have a length hint method that are used for some >> optimizations and preallocations, too. >> >> >>> i = iter(range(10)) >> >>> i.__length_hint__() >> 10 >> >> See http://www.python.org/dev/peps/pep-0424/ > > Didn't know about that, thanks. Presumably a proper iter(QuerySet()) > object could implement __length_hint__ in an efficient manner rather > than by just calling the __len__ of the underlying QuerySet, And how exactly would it do that, without either doing what __len__ does or reading the whole result set into memory? Stefan From ian.g.kelly at gmail.com Thu Mar 7 15:26:59 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Mar 2013 13:26:59 -0700 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On Thu, Mar 7, 2013 at 12:19 PM, Stefan Behnel wrote: >> Didn't know about that, thanks. Presumably a proper iter(QuerySet()) >> object could implement __length_hint__ in an efficient manner rather >> than by just calling the __len__ of the underlying QuerySet, > > And how exactly would it do that, without either doing what __len__ does or > reading the whole result set into memory? If the underlying cursor provides its own efficient length hint, it could return that. Or if the query is result-limited, use the limit as a length hint, provided it's not absurdly large. And if you really can't efficiently determine anything about the length of the result set at all, you can always fall back on returning NotImplemented. From wolfgang.maier at biologie.uni-freiburg.de Thu Mar 7 15:41:37 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 7 Mar 2013 20:41:37 +0000 (UTC) Subject: Interesting list() un-optimization References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: > >>> Iterators do not generally have __len__ methods. > >>> > >>> >>> len(iter(range(10))) > >>> Traceback (most recent call last): > >>> File "", line 1, in > >>> TypeError: object of type 'range_iterator' has no len() > >> > >> But iterators have a length hint method that are used for some > >> optimizations and preallocations, too. > >> > >> >>> i = iter(range(10)) > >> >>> i.__length_hint__() > >> 10 > >> > >> See http://www.python.org/dev/peps/pep-0424/ > > very interesting (hadn't heard of it)! Just checked the PEP, then tested list()'s behavior, and it is just as described: class stupid(list): def __len__(self): print ('len() called') return NotImplemented def __length_hint__(self): print ('hint requested') l=iter(self).__length_hint__() print (l) return l a=stupid((1,2,3)) len(d) ======> len() called Traceback (most recent call last): File "", line 1, in len(d) TypeError: an integer is required list(d) ======> len() called hint requested 3 [1, 2, 3] so list() first tries to call the iterable's __len__ method. If that raises a TypeError it falls back to __length_hint__ . What I still don't know is how the listiterator object's __length_hint__ works. Why, in this case, does it know that it has a length of 3 ? The PEP does not provide any hint how a reasonable hint could be calculated. > And how exactly would it do that, without either doing what __len__ does or > reading the whole result set into memory? > > Stefan > a very good question. Best, Wolfgang From tjreedy at udel.edu Thu Mar 7 17:53:27 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 07 Mar 2013 17:53:27 -0500 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On 3/7/2013 3:41 PM, Wolfgang Maier wrote: > >>>>> Iterators do not generally have __len__ methods. >>>>> >>>>>>>> len(iter(range(10))) >>>>> Traceback (most recent call last): >>>>> File "", line 1, in >>>>> TypeError: object of type 'range_iterator' has no len() >>>> >>>> But iterators have a length hint method that are used for some >>>> optimizations and preallocations, too. >>>> >>>>>>> i = iter(range(10)) >>>>>>> i.__length_hint__() >>>> 10 >>>> >>>> See http://www.python.org/dev/peps/pep-0424/ >>> > > very interesting (hadn't heard of it)! Just checked the PEP, > then tested list()'s behavior, and it is just as described: > > class stupid(list): > def __len__(self): > print ('len() called') > return NotImplemented > > def __length_hint__(self): > print ('hint requested') > l=iter(self).__length_hint__() > print (l) > return l > > a=stupid((1,2,3)) > len(d) > ======> > len() called > > Traceback (most recent call last): > File "", line 1, in > len(d) > TypeError: an integer is required > > list(d) > ======> > len() called > hint requested > 3 > [1, 2, 3] > > so list() first tries to call the iterable's __len__ method. If that raises a > TypeError it falls back to __length_hint__ . > What I still don't know is how the listiterator object's __length_hint__ works. > Why, in this case, does it know that it has a length of 3 ? The PEP does not > provide any hint how a reasonable hint could be calculated. 'How' depends on the iterator, but when it has an underlying concrete iterable of known length, it should be rather trivial as .__next__ will explicitly or implicitly use the count remaining in its operation. Part of the justification of adding __length_hint__ is that in many cases it is so easy. Iterators based on an iterator with a length_hint can just pass it along. The list iterator might work with a C pointer to the next item and a countdown count initialized to the list length. The __next__ method might be something like this mixed C and Python pseudocode: if (countdown--) return *(current--); else raise StopIteration (For non-C coders, postfix -- decrements value *after* retrieving it.) Then __length_hint__ would just return countdown. Tuples would work the same way. Sets and dicts would need current-- elaborated to skip over empty hash table slots. Range iterators would add the step to current, instead of 1. -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 7 15:34:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 07 Mar 2013 15:34:33 -0500 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On 3/7/2013 11:20 AM, Christian Heimes wrote: > But iterators have a length hint method that are used for some > optimizations and preallocations, too. This is easy when the base iterable has a length method, as do range objects. >>>> i = iter(range(10)) >>>> i.__length_hint__() > 10 And the length_hint can (should be) decremented with each next call. >>> next(i); next(i) 0 1 >>> i.__length_hint__() 8 -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 7 15:29:00 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 07 Mar 2013 15:29:00 -0500 Subject: Interesting list() un-optimization In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> Message-ID: On 3/7/2013 11:00 AM, Ian Kelly wrote: > But on this point, you are correct. The mongoengine QuerySet.__iter__ > method is defined as: > > def __iter__(self): > self.rewind() > return self > > This is unfortunate design. Not only does it mean that the iterator's > __len__ method cannot be trusted (what should the __len__ of a > partially exhausted iterator return?), but it also means that requesting > an iterator over the QuerySet will also silently invalidate any > existing iterators. I view that design as a violation of the iterator protocol and hence a program bug. __iter__ should either *just* return self (if the self is an iterator) or return a new object (if self is a non-iterator iterable). File objects are iterators and .__iter__ does not rewind. >>> f = open("f:/python/mypy/tem.py") >>> next(f) 'class myit(list):\n' >>> f2 = iter(f) >>> f2 is f True >>> next(f2) " def __bytes__(self): return b'hello'\n" -- Terry Jan Reedy From kevin.p.dwyer at gmail.com Thu Mar 7 02:31:26 2013 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Thu, 07 Mar 2013 07:31:26 +0000 Subject: Interesting list() un-optimization References: Message-ID: Roy Smith wrote: > I stumbled upon an interesting bit of trivia concerning lists and list > comprehensions today. > > We use mongoengine as a database model layer. A mongoengine query > returns an iterable object called a QuerySet. The "obvious" way to > create a list of the query results would be: > > my_objects = list(my_query_set) > > and, indeed, that works. But, then I found this code: > > my_objects = [obj for obj in my_query_set] > > which seemed a bit silly. I called over the guy who wrote it and asked > him why he didn't just write it using list(). I was astounded when it > turned out there's a good reason! > > Apparently, list() has an "optimization" where it calls len() on its > argument to try and discover the number of items it's going to put into > the list. Presumably, list() uses this information to pre-allocate the > right amount of memory the first time, without any resizing. If len() > fails, it falls back to just iterating and resizing as needed. > Normally, this would be a win. > > The problem is, QuerySets have a __len__() method. Calling it is a lot > faster than iterating over the whole query set and counting the items, > but it does result in an additional database query, which is a lot > slower than the list resizing! Writing the code as a list comprehension > prevents list() from trying to optimize when it shouldn't! Interesting discovery. Yet isn't this as much an issue with the mongoengine library as with list()? Queryset.count() can be called if the "length" of a resultset needs to be retrieved, so the __len__() methd seems redundant. And given that it's not unheard of to call list() on iterables, perhaps the library designers should either optimise the __len__() method, or document the performance implications of calling list on the queryset? Anyway, thanks for this thought-provoking post. Cheers, Kev From steve+comp.lang.python at pearwood.info Fri Mar 8 12:59:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2013 17:59:22 GMT Subject: Interesting list() un-optimization References: Message-ID: <513a26fa$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Mar 2013 22:20:11 -0500, Roy Smith wrote: > I stumbled upon an interesting bit of trivia concerning lists and list > comprehensions today. > > We use mongoengine as a database model layer. A mongoengine query > returns an iterable object called a QuerySet. The "obvious" way to > create a list of the query results would be: > > my_objects = list(my_query_set) > > and, indeed, that works. But, then I found this code: > > my_objects = [obj for obj in my_query_set] > > which seemed a bit silly. I called over the guy who wrote it and asked > him why he didn't just write it using list(). I was astounded when it > turned out there's a good reason! And why was that not documented in the code? I hope you took this fellow out and gave him a damned good thrashing! -- Steven From roy at panix.com Fri Mar 8 13:45:02 2013 From: roy at panix.com (Roy Smith) Date: Fri, 08 Mar 2013 13:45:02 -0500 Subject: Interesting list() un-optimization References: <513a26fa$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <513a26fa$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 06 Mar 2013 22:20:11 -0500, Roy Smith wrote: > > > I stumbled upon an interesting bit of trivia concerning lists and list > > comprehensions today. > > > > We use mongoengine as a database model layer. A mongoengine query > > returns an iterable object called a QuerySet. The "obvious" way to > > create a list of the query results would be: > > > > my_objects = list(my_query_set) > > > > and, indeed, that works. But, then I found this code: > > > > my_objects = [obj for obj in my_query_set] > > > > which seemed a bit silly. I called over the guy who wrote it and asked > > him why he didn't just write it using list(). I was astounded when it > > turned out there's a good reason! > > And why was that not documented in the code? > > I hope you took this fellow out and gave him a damned good thrashing! Nah. I'm a pacifist. Besides, he's my boss :-) From roy at panix.com Sun Mar 10 09:05:09 2013 From: roy at panix.com (Roy Smith) Date: Sun, 10 Mar 2013 09:05:09 -0400 Subject: Interesting list() un-optimization References: Message-ID: In article , Roy Smith wrote: > The problem is, QuerySets have a __len__() method. Calling it is a lot > faster than iterating over the whole query set and counting the items, > but it does result in an additional database query, which is a lot > slower than the list resizing! Writing the code as a list comprehension > prevents list() from trying to optimize when it shouldn't! Hmmm, I think I've found a good solution. It turns out, we don't actually use QuerySet in our models. We've defined our own QuerySet subclass which adds a few convenience methods. Adding def __len__(self): raise NotImplemented to our subclass should do the job. It looks like list() respects that, calls __iter__(), and does the right thing. I can't find any place where that behavior for list() is documented, but it's logical and experimentally, it seems to work. Can anybody see any downside to this? From tjreedy at udel.edu Sun Mar 10 17:39:14 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Mar 2013 17:39:14 -0400 Subject: Interesting list() un-optimization In-Reply-To: References: Message-ID: On 3/10/2013 9:05 AM, Roy Smith wrote: > In article , > Roy Smith wrote: > >> The problem is, QuerySets have a __len__() method. Calling it is a lot >> faster than iterating over the whole query set and counting the items, >> but it does result in an additional database query, which is a lot >> slower than the list resizing! Writing the code as a list comprehension >> prevents list() from trying to optimize when it shouldn't! > > Hmmm, I think I've found a good solution. > > It turns out, we don't actually use QuerySet in our models. We've > defined our own QuerySet subclass which adds a few convenience methods. > Adding > > def __len__(self): > raise NotImplemented > > to our subclass should do the job. It looks like list() respects that, > calls __iter__(), and does the right thing. I can't find any place > where that behavior for list() is documented, It is a cpython implementation detail that probably has changed with the versions. > but it's logical and experimentally, it seems to work. > Can anybody see any downside to this? No. Give it a try. -- Terry Jan Reedy From roy at panix.com Sun Mar 10 18:34:58 2013 From: roy at panix.com (Roy Smith) Date: Sun, 10 Mar 2013 18:34:58 -0400 Subject: Interesting list() un-optimization References: Message-ID: In article , Terry Reedy wrote: > > It turns out, we don't actually use QuerySet in our models. We've > > defined our own QuerySet subclass which adds a few convenience methods. > > Adding > > > > def __len__(self): > > raise NotImplemented > > > > to our subclass should do the job. It looks like list() respects that, > > calls __iter__(), and does the right thing. I can't find any place > > where that behavior for list() is documented, > > It is a cpython implementation detail that probably has changed with the > versions. Yeah, that's what I was afraid of. The "obvious" solution of: class QuerySet(mongoengine.queryset.QuerySet): def __init__(self, document, collection): super(QuerySet, self).__init__(document, collection) [...] del self.__len__ results in: [rest of stack dump elided] del self.__len__ AttributeError: __len__ which I don't understand. From steve+comp.lang.python at pearwood.info Sun Mar 10 19:35:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 23:35:50 GMT Subject: Interesting list() un-optimization References: Message-ID: <513d18d6$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Mar 2013 18:34:58 -0400, Roy Smith wrote: > Yeah, that's what I was afraid of. The "obvious" solution of: > > class QuerySet(mongoengine.queryset.QuerySet): > def __init__(self, document, collection): > super(QuerySet, self).__init__(document, collection) [...] > del self.__len__ > > results in: > > [rest of stack dump elided] > del self.__len__ > AttributeError: __len__ > > which I don't understand. You don't define a per-instance custom QuerySet attribute called __len__, so you can't delete it from the instance. The existing __len__ attribute is attached to the mongoengine queryset.QuerySet class, not the instance. You could monkeypatch the parent class, but that will probably break something else: del mongoengine.queryset.QuerySet.__len__ or you could try over-riding __len__ with a fake that pretends it doesn't exist: def __len__(self): raise AttributeError Try that and see it it works. (It may not.) -- Steven From roy at panix.com Sun Mar 10 19:50:22 2013 From: roy at panix.com (Roy Smith) Date: Sun, 10 Mar 2013 19:50:22 -0400 Subject: Interesting list() un-optimization References: <513d18d6$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <513d18d6$0$6512$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 10 Mar 2013 18:34:58 -0400, Roy Smith wrote: > > > Yeah, that's what I was afraid of. The "obvious" solution of: > > > > class QuerySet(mongoengine.queryset.QuerySet): > > def __init__(self, document, collection): > > super(QuerySet, self).__init__(document, collection) [...] > > del self.__len__ > > > > results in: > > > > [rest of stack dump elided] > > del self.__len__ > > AttributeError: __len__ > > > > which I don't understand. > > You don't define a per-instance custom QuerySet attribute called __len__, > so you can't delete it from the instance. > > The existing __len__ attribute is attached to the mongoengine > queryset.QuerySet class, not the instance. You could monkeypatch the > parent class, but that will probably break something else: > > del mongoengine.queryset.QuerySet.__len__ > > > or you could try over-riding __len__ with a fake that pretends it doesn't > exist: > > > def __len__(self): > raise AttributeError > > > Try that and see it it works. (It may not.) Yeah, that was one of the things I experimented with. It seems to work, but like most of these other things, I suspect it's version specific. If list() does: try: l = obj.__len__() except AttributeErrror: l = 0 then we're good. On the other hand, if it does: if obj.getattr('__len__', None): # etc then it fails. At this point, I'm thinking the monkeypatch is the right solution. From nagle at animats.com Thu Mar 7 01:33:34 2013 From: nagle at animats.com (John Nagle) Date: Wed, 06 Mar 2013 22:33:34 -0800 Subject: Unhelpful traceback Message-ID: Here's a traceback that's not helping: Traceback (most recent call last): File "InfoCompaniesHouse.py", line 255, in main() File "InfoCompaniesHouse.py", line 251, in main loader.dofile(infile) # load this file File "InfoCompaniesHouse.py", line 213, in dofile self.dofilezip(infilename) # do ZIP file File "InfoCompaniesHouse.py", line 198, in dofilezip self.dofilecsv(infile, infd) # as a CSV file File "InfoCompaniesHouse.py", line 182, in dofilecsv for fields in reader : # read entire CSV file UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 14: ordinal not in range(128) This is wierd, becuase "for fields in reader" isn't directly doing a decode. That's further down somewhere, and the backtrace didn't tell me where. The program is converting some .CSV files that come packaged in .ZIP files. The files are big, so rather than expanding them, they're read directly from the ZIP files and processed through the ZIP and CSV modules. Here's the code that's causing the error above: decoder = codecs.getreader('utf-8') with decoder(infdraw,errors="replace") as infd : with codecs.open(outfilename, encoding='utf-8', mode='w') as outfd : headerline = infd.readline() self.doheaderline(headerline) reader = csv.reader(infd, delimiter=',', quotechar='"') for fields in reader : pass Normally, the "pass" is a call to something that uses the data, but for test purposes, I put a "pass" in there. It still fails. With that "pass", nothing is ever written to the output file, and no "encoding" should be taking place. "infdraw" is a stream from the zip module, create like this: with inzip.open(zipelt.filename,"r") as infd : self.dofilecsv(infile, infd) This works for data records that are pure ASCII, but as soon as some non-ASCII character comes through, it fails. Where is the error being generated? I'm not seeing any place where there's a conversion to ASCII. Not even a print. John Nagle From bahamutzero8825 at gmail.com Thu Mar 7 01:57:42 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 07 Mar 2013 00:57:42 -0600 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: <51383A66.9070708@gmail.com> On 2013.03.07 00:33, John Nagle wrote: > This is wierd, becuase "for fields in reader" isn't directly > doing a decode. That's further down somewhere, and the backtrace > didn't tell me where. Looking at the csv module docs,the reader object iterates over the csvfile argument (which can be any iterator). I think that, in the case of a file object, it's not decoded until iteration. I've never used the csv module before though, so I could be wrong. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From clp2 at rebertia.com Thu Mar 7 02:04:00 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 6 Mar 2013 23:04:00 -0800 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: On Wed, Mar 6, 2013 at 10:33 PM, John Nagle wrote: > Here's a traceback that's not helping: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in > position 14: ordinal not in range(128) > The program is converting some .CSV files that come packaged in .ZIP > files. The files are big, so rather than expanding them, they're > read directly from the ZIP files and processed through the ZIP > and CSV modules. > This works for data records that are pure ASCII, but as soon as some > non-ASCII character comes through, it fails. I'd recommend using the `unicodecsv` package, which, unlike the std lib `csv` module, is properly Unicode-compatible: https://pypi.python.org/pypi/unicodecsv Cheers, Chris From davea at davea.name Thu Mar 7 08:10:17 2013 From: davea at davea.name (Dave Angel) Date: Thu, 07 Mar 2013 08:10:17 -0500 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: <513891B9.5080502@davea.name> On 03/07/2013 01:33 AM, John Nagle wrote: > Here's a traceback that's not helping: > A bit more context would be helpful. Starting with Python version. > Traceback (most recent call last): > File "InfoCompaniesHouse.py", line 255, in > main() > File "InfoCompaniesHouse.py", line 251, in main > loader.dofile(infile) # load this file > File "InfoCompaniesHouse.py", line 213, in dofile > self.dofilezip(infilename) # do ZIP file > File "InfoCompaniesHouse.py", line 198, in dofilezip > self.dofilecsv(infile, infd) # as a CSV file > File "InfoCompaniesHouse.py", line 182, in dofilecsv > for fields in reader : # read entire > CSV file > UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in > position 14: ordinal not in range(128) > > This is wierd, becuase "for fields in reader" isn't directly > doing a decode. That's further down somewhere, and the backtrace > didn't tell me where. > > The program is converting some .CSV files that come packaged in .ZIP > files. The files are big, so rather than expanding them, they're > read directly from the ZIP files and processed through the ZIP > and CSV modules. > > Here's the code that's causing the error above: > > decoder = codecs.getreader('utf-8') > with decoder(infdraw,errors="replace") as infd : > with codecs.open(outfilename, encoding='utf-8', mode='w') as > outfd : > headerline = infd.readline() > self.doheaderline(headerline) > reader = csv.reader(infd, delimiter=',', quotechar='"') > for fields in reader : > pass > > Normally, the "pass" is a call to something that > uses the data, but for test purposes, I put a "pass" in there. It still > fails. With that "pass", nothing is ever written to the > output file, and no "encoding" should be taking place. > > "infdraw" is a stream from the zip module, create like this: > > with inzip.open(zipelt.filename,"r") as infd : You probably need a 'rb' rather than 'r', since the file is not ASCII. > self.dofilecsv(infile, infd) > > This works for data records that are pure ASCII, but as soon as some > non-ASCII character comes through, it fails. > > Where is the error being generated? I'm not seeing any place > where there's a conversion to ASCII. Not even a print. > > John Nagle > > > > If that isn't enough, then please give the whole context, such as where zipelt and filename came from. And don't forget to specify Python version. Version 3.x treats nonbinary files very differently than 2.x -- DaveA From nagle at animats.com Thu Mar 7 13:42:56 2013 From: nagle at animats.com (John Nagle) Date: Thu, 07 Mar 2013 10:42:56 -0800 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: On 3/7/2013 5:10 AM, Dave Angel wrote: > On 03/07/2013 01:33 AM, John Nagle wrote: >> Here's a traceback that's not helping: >> > > A bit more context would be helpful. Starting with Python version. Sorry, Python 2.7. > > If that isn't enough, then please give the whole context, such as where > zipelt and filename came from. And don't forget to specify Python > version. Version 3.x treats nonbinary files very differently than 2.x Here it is, with some email wrap problems. John Nagle def dofilecsv(self, infilename, infdraw) : """ Loader for Companies House company data, with files already open. """ self.logger.info('Converting "%s"' % (infilename, )) # log (pathpart, filepart) = os.path.split(infilename) # split off file part to construct outputfile) (outfile, ext) = os.path.splitext(filepart) # remove extension outfile += ".sql" # add SQL suffix outfilename = os.path.abspath(os.path.join(self.options.destdir, outfile)) # ***NEED TO INSURE UNIQUE OUTFILENAME EVEN IF DUPLICATED IN ZIP FILES*** decoder = codecs.getreader('utf-8') # UTF-8 reader with decoder(infdraw,errors="replace") as infd : with codecs.open(outfilename, encoding='utf-8', mode='w') as outfd : headerline = infd.readline() # read header line self.doheaderline(headerline) # process header line reader = csv.reader(infd, delimiter=',', quotechar='"') # CSV file for fields in reader : # read entire CSV file self.doline(outfd, fields) # copy fields self.logstats(infilename) # log statistics of this file def dofilezip(self, infilename) : """ Do a ZIP file containing CSV files. """ try : inzip = zipfile.ZipFile(infilename, "r", allowZip64=True) # try to open zipdir = inzip.infolist() # get objects in file for zipelt in zipdir : # for all objects in file self.logger.debug('ZIP file "%s" contains "%s".' % (infilename, zipelt.filename)) (infile, ext) = os.path.splitext(zipelt.filename) # remove extension if ext.lower() == ".csv" : # if a CSV file with inzip.open(zipelt.filename,"r") as infd : # do this file self.dofilecsv(infile, infd) # as a CSV file else : self.logger.error('Non-CSV file in ZIP file: "%s"' % (zipelt.filename,)) self.errorcount += 1 # tally except zipfile.BadZipfile as message : # if trouble self.logger.error('Bad ZIP file: "%s"' % (infilename,)) # note trouble self.errorcount += 1 # tally def dofile(self, infilename) : """ Loader for Companies House company data """ (sink, ext) = os.path.splitext(infilename) # get extension if ext == ".zip" : # if .ZIP file self.dofilezip(infilename) # do ZIP file elif ext == ".csv" : self.logger.info('Converting "%s"' % (infilename,))# log with open(infilename, "rb") as infd : self.dofilecsv(infilename, infd) # do self.logstats(infilename) # log statistics of this file else : self.logger.error('File of unexpected type (not .csv or .zip): %s ' % (infilename,)) self.errorcount += 1 From nagle at animats.com Thu Mar 7 17:13:47 2013 From: nagle at animats.com (John Nagle) Date: Thu, 07 Mar 2013 14:13:47 -0800 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: On 3/7/2013 10:42 AM, John Nagle wrote: > On 3/7/2013 5:10 AM, Dave Angel wrote: >> On 03/07/2013 01:33 AM, John Nagle wrote: >>> Here's a traceback that's not helping: >>> >> >> A bit more context would be helpful. Starting with Python version. > > Sorry, Python 2.7. The trouble comes from here: decoder = codecs.getreader('utf-8') # UTF-8 reader with decoder(infdraw,errors="replace") as infd : It's not the CSV module that's blowing up. If I just feed the raw unconverted bytes from the ZIP module into the CSV module, the CSV module runs without complaint. I've tried 'utf-8', 'ascii', and 'windows-1252' as codecs. They all blow up. 'errors="replace"' doesn't help. John Nagle From ian.g.kelly at gmail.com Thu Mar 7 17:32:53 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Mar 2013 15:32:53 -0700 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: On Thu, Mar 7, 2013 at 3:13 PM, John Nagle wrote: > On 3/7/2013 10:42 AM, John Nagle wrote: >> On 3/7/2013 5:10 AM, Dave Angel wrote: >>> On 03/07/2013 01:33 AM, John Nagle wrote: >>>> Here's a traceback that's not helping: >>>> >>> >>> A bit more context would be helpful. Starting with Python version. >> >> Sorry, Python 2.7. > > The trouble comes from here: > > decoder = codecs.getreader('utf-8') # UTF-8 reader > with decoder(infdraw,errors="replace") as infd : > > It's not the CSV module that's blowing up. If I just feed the > raw unconverted bytes from the ZIP module into the CSV module, > the CSV module runs without complaint. > > I've tried 'utf-8', 'ascii', and 'windows-1252' as codecs. > They all blow up. 'errors="replace"' doesn't help. I believe that the csv module is expecting string data, not unicode. Since it receives unicode as a result of your decoder step, it tries to convert it to a string using str(), which implicitly tries to encode the data using the ascii codec, hence the error that you're seeing. From nagle at animats.com Thu Mar 7 16:23:13 2013 From: nagle at animats.com (John Nagle) Date: Thu, 07 Mar 2013 13:23:13 -0800 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: On 3/7/2013 5:10 AM, Dave Angel wrote: > On 03/07/2013 01:33 AM, John Nagle wrote: >> >> "infdraw" is a stream from the zip module, create like this: >> >> with inzip.open(zipelt.filename,"r") as infd : > > You probably need a 'rb' rather than 'r', since the file is not ASCII. > >> self.dofilecsv(infile, infd) >> >> This works for data records that are pure ASCII, but as soon as some >> non-ASCII character comes through, it fails. No, the ZIP module gives you back the bytes you put in. "rb" is not accepted there: File "InfoCompaniesHouse.py", line 197, in dofilezip with inzip.open(zipelt.filename,"rb") as infd : # do this file File "C:\python27\lib\zipfile.py", line 872, in open raise RuntimeError, 'open() requires mode "r", "U", or "rU"' RuntimeError: open() requires mode "r", "U", or "rU" "b" for files is about end of line handling (CR LF -> LF), anyway. John Nagle From davea at davea.name Thu Mar 7 19:23:20 2013 From: davea at davea.name (Dave Angel) Date: Thu, 07 Mar 2013 19:23:20 -0500 Subject: Unhelpful traceback In-Reply-To: References: Message-ID: <51392F78.1090607@davea.name> On 03/07/2013 04:23 PM, John Nagle wrote: > >> > > raise RuntimeError, 'open() requires mode "r", "U", or "rU"' > RuntimeError: open() requires mode "r", "U", or "rU" > > "b" for files is about end of line handling (CR LF -> LF), anyway. > Only for Python 2. Since originally you didn't specify, I took my best shot. If you omit the 'b' opening a binary file in Python 3, you'd get problems similar to yours. Text files will be converted to Unicode. That's one of the reasons that specifying the full environment is important. -- DaveA From nikos.gr33k at gmail.com Thu Mar 7 03:18:10 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 00:18:10 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 Message-ID: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> Today i switched to Python v3.2.3 on my remote web server at HostGator. My cgi-script which it works at python v2.6.6 now produces theses errors: --> --> Traceback (most recent call last): File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute r = self._query(query) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query rowcount = self._do_query(q) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "metrites.py", line 211, in cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (htmlpage,) ) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute self.errorhandler(self, exc, value) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass(errorvalue) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") Even cursor.execute changes in python v3 ? What are these errors about? From nikos.gr33k at gmail.com Thu Mar 7 04:06:27 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 01:06:27 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> Message-ID: <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> Any ideas about the error please? I can assure you all the statemnt are correct ebcause they work in python v2.6.6 From nikos.gr33k at gmail.com Thu Mar 7 06:27:03 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 03:27:03 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> Message-ID: <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> ?? ??????, 7 ??????? 2013 11:06:27 ?.?. UTC+2, ? ??????? ????? ???33? ??????: > Any ideas about the error please? > > > > I can assure you all the statemnt are correct ebcause they work in python v2.6.6 can someone help this issue so my webiste will get back on working plz? From gmx at ross.cx Thu Mar 7 06:51:42 2013 From: gmx at ross.cx (Michael Ross) Date: Thu, 07 Mar 2013 12:51:42 +0100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> Message-ID: On Thu, 07 Mar 2013 12:27:03 +0100, ????? ???33? wrote: > ?? ??????, 7 ??????? 2013 11:06:27 ?.?. UTC+2, ? ??????? ????? ???33? > ??????: >> Any ideas about the error please? >> >> >> >> I can assure you all the statemnt are correct ebcause they work in >> python v2.6.6 > > can someone help this issue so my webiste will get back on working plz? MySQLdb is python 2 only. "MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently supported. Python-3.0 will be supported in a future release." Maybe try this one: https://pypi.python.org/pypi/mysql-connector-python/1.0.9 Alternatively, forget about subprocess.check_output, call your metrites.py with os.system('python metrites.py some-temp-file') and have it write its output to some-temp-file, and read some-temp-file back into your template? From nikos.gr33k at gmail.com Thu Mar 7 07:25:58 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 04:25:58 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> Message-ID: <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> ?? ??????, 7 ??????? 2013 1:51:42 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Thu, 07 Mar 2013 12:27:03 +0100, ????? ???33? > > wrote: > > > > > ?? ??????, 7 ??????? 2013 11:06:27 ?.?. UTC+2, ? ??????? ????? ???33? > > > ??????: > > >> Any ideas about the error please? > > >> > > >> > > >> > > >> I can assure you all the statemnt are correct ebcause they work in > > >> python v2.6.6 > > > > > > can someone help this issue so my webiste will get back on working plz? > > > > MySQLdb is python 2 only. > > "MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently > > supported. Python-3.0 will be supported in a future release." > > > > Maybe try this one: > > https://pypi.python.org/pypi/mysql-connector-python/1.0.9 > > > > Alternatively, > > forget about subprocess.check_output, > > call your metrites.py with os.system('python metrites.py some-temp-file') > > and have it write its output to some-temp-file, > > and read some-temp-file back into your template? Yes its better for me to give upon python3 for the moment being, because all that hassle was for makeing the subprocess command run. Now i just followed your advice and tried: elif htmlpage.endswith('.py'): htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') but produced error tells me that: template undefined, htmldata = -1, counter = '
    ...st.gr/?show=stats"> 0 \n\t\t ' whay htmldata reeturn the value '-1' when os.sytem is executed? From gmx at ross.cx Thu Mar 7 08:06:37 2013 From: gmx at ross.cx (Michael Ross) Date: Thu, 07 Mar 2013 14:06:37 +0100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> Message-ID: On Thu, 07 Mar 2013 13:25:58 +0100, ????? ???33? wrote: > ?? ??????, 7 ??????? 2013 1:51:42 ?.?. UTC+2, ? ??????? Michael Ross > ??????: >> On Thu, 07 Mar 2013 12:27:03 +0100, ????? ???33? >> >> wrote: >> >> >> >> > ?? ??????, 7 ??????? 2013 11:06:27 ?.?. UTC+2, ? ??????? ????? ???33? >> >> > ??????: >> >> >> Any ideas about the error please? >> >> >> >> >> >> >> >> >> >> >> >> I can assure you all the statemnt are correct ebcause they work in >> >> >> python v2.6.6 >> >> > >> >> > can someone help this issue so my webiste will get back on working >> plz? >> >> >> >> MySQLdb is python 2 only. >> >> "MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently >> >> supported. Python-3.0 will be supported in a future release." >> >> >> >> Maybe try this one: >> >> https://pypi.python.org/pypi/mysql-connector-python/1.0.9 >> >> >> >> Alternatively, >> >> forget about subprocess.check_output, >> >> call your metrites.py with os.system('python metrites.py >> some-temp-file') >> >> and have it write its output to some-temp-file, >> >> and read some-temp-file back into your template? > > Yes its better for me to give upon python3 for the moment being, because > all that hassle was for makeing the subprocess command run. > > Now i just followed your advice and tried: > > elif htmlpage.endswith('.py'): > htmldata = os.system('/usr/bin/python ./metrites.py > /data/files/htmltemp') > > but produced error tells me that: > > template undefined, htmldata = -1, counter = '
    href="mailto:support at superhost.gr"> ...st.gr/?show=stats"> color=cyan> 0 \n\t\t ' > > whay htmldata reeturn the value '-1' when os.sytem is executed? Because "On Unix, the return value is the exit status of the process encoded in the format specified for wait()." It's in the documentation for os.system. Which you should have read before asking here. You may not intend it like that, but if you ask any and all errors here, you effectively ask the list to develop the software for you. Seriously this is beyond the scope of volunteer help for a commercial site. I'm bailing out. From nikos.gr33k at gmail.com Thu Mar 7 08:22:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 05:22:54 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> Message-ID: <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> Please tell me at least if i ahve any syntax error in this line: htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') please man its essential for my website to work otherwise 3 scripts i wrote would not be able to produce proper html output that then i need to append a string after them. her si what i want to do: if htmlpage.endswith('.html'): f = open( "/home/nikos/www/" + htmlpage ) htmldata = f.read() elif htmlpage.endswith('.py'): htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') counter = '''
    ?????? ??????????
    %s
    %s
    %s
    %s
    ''' % data[0] template = htmldata + counter print( template ) ====================== Please just that i like to do it myself ut i cant, i wont ask anyhting else. From nikos.gr33k at gmail.com Thu Mar 7 08:22:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 05:22:54 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> Message-ID: <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> Please tell me at least if i ahve any syntax error in this line: htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') please man its essential for my website to work otherwise 3 scripts i wrote would not be able to produce proper html output that then i need to append a string after them. her si what i want to do: if htmlpage.endswith('.html'): f = open( "/home/nikos/www/" + htmlpage ) htmldata = f.read() elif htmlpage.endswith('.py'): htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') counter = '''
    ??????? ?????????? %d
    ''' % data[0] template = htmldata + counter print( template ) ====================== Please just that i like to do it myself ut i cant, i wont ask anyhting else. From rosuav at gmail.com Thu Mar 7 08:43:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 00:43:58 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 12:22 AM, ????? ???33? wrote: > Please tell me at least if i ahve any syntax error in this line: > > htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') > > please man its essential for my website to work otherwise 3 scripts i wrote would not be able to produce proper html output Yes, there is. The variable name at the beginning is wrong. To understand why, look at the documentation for os.system(). If it's essential for your web site, why not pay someone to do the work for you? You want free support AND you're not willing to put effort into your questions. That's a bad combination. The sloppiness of your writing, coupled with a clear lack of preliminary research (eg checking the docs), suggests that you do not value the end result; you expect someone else to do everything, to wave a magic wand and voila, your web site works. That isn't how the world works. Quoting from http://www.catb.org/esr/faqs/smart-questions.html > == Before you ask == > Prepare your question. Think it through. Hasty-sounding questions get > hasty answers, or none at all. The more you do to demonstrate that having > put thought and effort into solving your problem before seeking help, the > more likely you are to actually get help. ... > == Write in clear, grammatical, correctly-spelled language == > ... If you can't be bothered to do that, we can't be bothered to pay attention. > Spend the extra effort to polish your language. It doesn't have to be stiff or > formal - in fact, hacker culture values informal, slangy and humorous > language used with precision. But it has to be precise; there has to be > some indication that you're thinking and paying attention. > ... if you write like a semi-literate boob you will very likely be ignored. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 08:56:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 05:56:54 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> Message-ID: <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running all the above fail: htmldata = os.system("python metrites.py '/data/files/htmltemp'") How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do: template = htmldata + counter os.system is very vague while i need specific help with this. if you provide me a link that describes my case of things i';; for sure read it. From nikos.gr33k at gmail.com Thu Mar 7 08:56:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 05:56:54 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> Message-ID: <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running all the above fail: htmldata = os.system("python metrites.py '/data/files/htmltemp'") How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do: template = htmldata + counter os.system is very vague while i need specific help with this. if you provide me a link that describes my case of things i';; for sure read it. From rosuav at gmail.com Thu Mar 7 09:01:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 01:01:13 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 12:56 AM, ????? ???33? wrote: > But iam tryign dayd for this i even tryign to chnage my 3 script to python v3.2.3 just to get subprocess up and running > > all the above fail: > > htmldata = os.system("python metrites.py '/data/files/htmltemp'") > > How can i tell system to send metritis.py's output to a temporary file called htmltemp so in the next step i can do what iam trying 3 days now to do: > > template = htmldata + counter > > os.system is very vague while i need specific help with this. > if you provide me a link that describes my case of things i';; for sure read it. You are panicking about specific problems. Take a deep breath, take a step back, and look at what's going on. If you've really been trying for three days to make this work, it won't cost you much more to spend three minutes polishing your email before you send it... or those same three minutes reading the docs and finding what you want. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 09:11:04 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:11:04 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> Message-ID: <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> ?? ??????, 7 ??????? 2013 4:01:13 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You are panicking about specific problems. Take a deep breath, take a > > step back, and look at what's going on. If you've really been trying > > for three days to make this work, it won't cost you much more to spend > > three minutes polishing your email before you send it... or those same > > three minutes reading the docs and finding what you want. Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it.... I think its an OS issue and not statment issue. iam starting to hink that maybe python metritis.py > /data/files/htmltemp might work. i will try this now as we speak.lets hope for God;s sake it will work! From nikos.gr33k at gmail.com Thu Mar 7 09:13:06 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:13:06 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> Message-ID: <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> I made some progress!!! Now the htmldata's value its not -1 but 256!!! look the error after trying this: htmldata = os.system("python metrites.py > '/data/private/htmltemp'") ==================== template undefined, htmldata = 256, counter = '
    ...st.gr/?show=stats"> 0 \n\t\t ' : unsupported operand type(s) for +: 'int' and 'str' args = ("unsupported operand type(s) for +: 'int' and 'str'",) message = "unsupported operand type(s) for +: 'int' and 'str'" From nikos.gr33k at gmail.com Thu Mar 7 09:13:06 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:13:06 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> Message-ID: <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> I made some progress!!! Now the htmldata's value its not -1 but 256!!! look the error after trying this: htmldata = os.system("python metrites.py > '/data/private/htmltemp'") ==================== template undefined, htmldata = 256, counter = '
    ...st.gr/?show=stats"> 0 \n\t\t ' : unsupported operand type(s) for +: 'int' and 'str' args = ("unsupported operand type(s) for +: 'int' and 'str'",) message = "unsupported operand type(s) for +: 'int' and 'str'" From rosuav at gmail.com Thu Mar 7 09:17:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 01:17:28 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:13 AM, ????? ???33? wrote: > I made some progress!!! Now the htmldata's value its not -1 but 256!!! > > look the error after trying this: > htmldata = os.system("python metrites.py > '/data/private/htmltemp'") Go check the docs for os.system() and understand why 'htmldata' is the wrong name for its return value. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 09:34:08 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:34:08 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> Message-ID: <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> Docs doesn't explain that i just take looked at http://docs.python.org/2/library/os.html#os.system I see that the return value of os.system its an indicator to as if the command inside os.system() returned successfully. So i guess ill be needing somethign like this: htmltemp = '/home/nikos/www/data/private/htmltemp' if htmlpage.endswith('.html'): f = open( "/home/nikos/www/" + htmlpage ) htmldata = f.read() elif htmlpage.endswith('.py'): os.system( 'python metrites.py > %s' ) % htmltemp f = open( htmltemp ) htmldata = f.read() template = htmldata + counter ============== which i just tried and now iam receiving this: : unsupported operand type(s) for %: 'int' and 'str' I'am very close to the solution now i cna feel it but please help a bit! From nikos.gr33k at gmail.com Thu Mar 7 09:34:08 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:34:08 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> Message-ID: <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> Docs doesn't explain that i just take looked at http://docs.python.org/2/library/os.html#os.system I see that the return value of os.system its an indicator to as if the command inside os.system() returned successfully. So i guess ill be needing somethign like this: htmltemp = '/home/nikos/www/data/private/htmltemp' if htmlpage.endswith('.html'): f = open( "/home/nikos/www/" + htmlpage ) htmldata = f.read() elif htmlpage.endswith('.py'): os.system( 'python metrites.py > %s' ) % htmltemp f = open( htmltemp ) htmldata = f.read() template = htmldata + counter ============== which i just tried and now iam receiving this: : unsupported operand type(s) for %: 'int' and 'str' I'am very close to the solution now i cna feel it but please help a bit! From rosuav at gmail.com Thu Mar 7 09:37:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 01:37:31 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:34 AM, ????? ???33? wrote: > os.system( 'python metrites.py > %s' ) % htmltemp > > : unsupported operand type(s) for %: 'int' and 'str' Simple parenthesis problem. Take a careful look at the line mentioned in the exception traceback (which you didn't share with us, but fortunately the error's pretty obvious) and see if you can find the problem. Hint: htmltemp is the str mentioned in the error. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 09:44:49 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:44:49 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> Message-ID: <8a39a8d9-4afa-4b35-b2ef-e4f21f5925de@googlegroups.com> ?? ??????, 7 ??????? 2013 4:37:31 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 8, 2013 at 1:34 AM, ????? ???33? wrote: > > > os.system( 'python metrites.py > %s' ) % htmltemp > > > > > > : unsupported operand type(s) for %: 'int' and 'str' > > > > Simple parenthesis problem. Take a careful look at the line mentioned > > in the exception traceback (which you didn't share with us, but > > fortunately the error's pretty obvious) and see if you can find the > > problem. > Hint: htmltemp is the str mentioned in the error. /home/nikos/public_html/cgi-bin/metrites.py in () 220 htmldata = f.read() 221 elif htmlpage.endswith('.py'): 222 os.system( 'python metrites.py > %s' ) % htmltemp 223 f = open( htmltemp ) 224 htmldata = f.read() os = , os.system = , htmltemp = '/home/nikos/www/data/private/htmltemp' : unsupported operand type(s) for %: 'int' and 'str' args = ("unsupported operand type(s) for %: 'int' and 'str'",) message = "unsupported operand type(s) for %: 'int' and 'str'" ?his is the complete traceback iam reading it and reading it all over but i just dont *see* what it tries to tell me. From nikos.gr33k at gmail.com Thu Mar 7 09:44:49 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:44:49 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> Message-ID: <8a39a8d9-4afa-4b35-b2ef-e4f21f5925de@googlegroups.com> ?? ??????, 7 ??????? 2013 4:37:31 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 8, 2013 at 1:34 AM, ????? ???33? wrote: > > > os.system( 'python metrites.py > %s' ) % htmltemp > > > > > > : unsupported operand type(s) for %: 'int' and 'str' > > > > Simple parenthesis problem. Take a careful look at the line mentioned > > in the exception traceback (which you didn't share with us, but > > fortunately the error's pretty obvious) and see if you can find the > > problem. > Hint: htmltemp is the str mentioned in the error. /home/nikos/public_html/cgi-bin/metrites.py in () 220 htmldata = f.read() 221 elif htmlpage.endswith('.py'): 222 os.system( 'python metrites.py > %s' ) % htmltemp 223 f = open( htmltemp ) 224 htmldata = f.read() os = , os.system = , htmltemp = '/home/nikos/www/data/private/htmltemp' : unsupported operand type(s) for %: 'int' and 'str' args = ("unsupported operand type(s) for %: 'int' and 'str'",) message = "unsupported operand type(s) for %: 'int' and 'str'" ?his is the complete traceback iam reading it and reading it all over but i just dont *see* what it tries to tell me. From rosuav at gmail.com Thu Mar 7 09:48:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 01:48:31 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <8a39a8d9-4afa-4b35-b2ef-e4f21f5925de@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> <08b2cc58-b3ec-4f4e-bd0e-863a17e7569f@googlegroups.com> <4fea8c12-8f63-43b8-90cc-8bc57858c2ef@googlegroups.com> <8a39a8d9-4afa-4b35-b2ef-e4f21f5925de@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:44 AM, ????? ???33? wrote: > /home/nikos/public_html/cgi-bin/metrites.py in () > 220 htmldata = f.read() > 221 elif htmlpage.endswith('.py'): > 222 os.system( 'python metrites.py > %s' ) % htmltemp > 223 f = open( htmltemp ) > 224 htmldata = f.read() > os = , os.system = , htmltemp = '/home/nikos/www/data/private/htmltemp' > : unsupported operand type(s) for %: 'int' and 'str' > args = ("unsupported operand type(s) for %: 'int' and 'str'",) > message = "unsupported operand type(s) for %: 'int' and 'str'" > > ?his is the complete traceback iam reading it and reading it all over but i just dont *see* what it tries to tell me. Try to get the default output from an exception, it's a lot more useful. In any case, line 222 is the one being highlighted; you get a couple of lines of context, but the middle one is where the error is. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 09:11:04 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:11:04 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> Message-ID: <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> ?? ??????, 7 ??????? 2013 4:01:13 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You are panicking about specific problems. Take a deep breath, take a > > step back, and look at what's going on. If you've really been trying > > for three days to make this work, it won't cost you much more to spend > > three minutes polishing your email before you send it... or those same > > three minutes reading the docs and finding what you want. Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it.... I think its an OS issue and not statment issue. iam starting to hink that maybe python metritis.py > /data/files/htmltemp might work. i will try this now as we speak.lets hope for God;s sake it will work! From rosuav at gmail.com Thu Mar 7 09:16:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 01:16:06 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> <7b413998-2a6f-41cb-9e6d-7ba5b006bad4@googlegroups.com> <12e70b6c-2dc6-4cb3-8731-a910a7621802@googlegroups.com> <667bb7bc-2d76-435c-a8f6-f92fb383bd20@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:11 AM, ????? ???33? wrote: > ?? ??????, 7 ??????? 2013 4:01:13 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > >> You are panicking about specific problems. Take a deep breath, take a >> >> step back, and look at what's going on. If you've really been trying >> >> for three days to make this work, it won't cost you much more to spend >> >> three minutes polishing your email before you send it... or those same >> >> three minutes reading the docs and finding what you want. > > Iam willing to read some document that describe what iam dealing with, please provid eme a link and aill read it.... http://www.google.com/ > I think its an OS issue and not statment issue. I think it's a pebkac issue. > iam starting to hink that maybe > > python metritis.py > /data/files/htmltemp > > might work. i will try this now as we speak.lets hope for God;s sake it will work! Tip: Next time, try it first, THEN post. This is not IRC. You don't need to tell us that you're trying, and that you're panicking still further. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 07:25:58 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 04:25:58 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <7bfe7117-d39d-48dc-9a6f-3d57484610a8@googlegroups.com> <213cf076-4163-44fd-a8b6-b25970da1bfa@googlegroups.com> Message-ID: <8a2af358-542c-45d3-b334-b4cb8f7cb7cf@googlegroups.com> ?? ??????, 7 ??????? 2013 1:51:42 ?.?. UTC+2, ? ??????? Michael Ross ??????: > On Thu, 07 Mar 2013 12:27:03 +0100, ????? ???33? > > wrote: > > > > > ?? ??????, 7 ??????? 2013 11:06:27 ?.?. UTC+2, ? ??????? ????? ???33? > > > ??????: > > >> Any ideas about the error please? > > >> > > >> > > >> > > >> I can assure you all the statemnt are correct ebcause they work in > > >> python v2.6.6 > > > > > > can someone help this issue so my webiste will get back on working plz? > > > > MySQLdb is python 2 only. > > "MySQL-3.23 through 5.0 and Python-2.3 through 2.7 are currently > > supported. Python-3.0 will be supported in a future release." > > > > Maybe try this one: > > https://pypi.python.org/pypi/mysql-connector-python/1.0.9 > > > > Alternatively, > > forget about subprocess.check_output, > > call your metrites.py with os.system('python metrites.py some-temp-file') > > and have it write its output to some-temp-file, > > and read some-temp-file back into your template? Yes its better for me to give upon python3 for the moment being, because all that hassle was for makeing the subprocess command run. Now i just followed your advice and tried: elif htmlpage.endswith('.py'): htmldata = os.system('/usr/bin/python ./metrites.py /data/files/htmltemp') but produced error tells me that: template undefined, htmldata = -1, counter = '
    ...st.gr/?show=stats"> 0 \n\t\t ' whay htmldata reeturn the value '-1' when os.sytem is executed? From nikos.gr33k at gmail.com Thu Mar 7 09:50:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:50:34 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> Message-ID: <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> os.system( 'python metrites.py > htmltemp' ) f = open( htmltemp ) htmldata = f.read() gives: f undefined, builtin open = , temp = '/home/nikos/www/data/private/htmltemp' : [Errno 2] ??? ??????? ?????? ?????? ? ?????????: '/home/nikos/www/data/private/htmltemp' args = (2, '\xc4\xe5\xed \xf5\xf0\xdc\xf1\xf7\xe5\xe9 \xf4\xdd\xf4\xef\xe9\xef \xe1\xf1\xf7\xe5\xdf\xef \xde \xea\xe1\xf4\xdc\xeb\xef\xe3\xef\xf2') errno = 2 filename = '/home/nikos/www/data/private/htmltemp' message = '' strerror = '\xc4\xe5\xed \xf5\xf0\xdc\xf1\xf7\xe5\xe9 \xf4\xdd\xf4\xef\xe9\xef \xe1\xf1\xf7\xe5\xdf\xef \xde \xea\xe1\xf4\xdc\xeb\xef\xe3\xef\xf2' Very weird! From nikos.gr33k at gmail.com Thu Mar 7 09:52:40 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 06:52:40 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: Why f gives back an error and doesnt open the filename that i give it as anvariable successfully? From nikos.gr33k at gmail.com Thu Mar 7 10:01:24 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 07:01:24 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: ?? ??????, 7 ??????? 2013 4:50:34 ?.?. UTC+2, ? ??????? ????? ???33? ??????: > os.system( 'python metrites.py > htmltemp' ) That is wrong now i realize, it takes htmltemp as the filename where what i need is to take it htmltemp's varibales value. Switching back to: os.system( 'python metrites.py > %s' ) % htmltemp f = open( htmltemp ) htmldata = f.read() but still donse see what iam doing wrong..... From rosuav at gmail.com Thu Mar 7 10:13:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 02:13:24 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 2:01 AM, ????? ???33? wrote: > os.system( 'python metrites.py > %s' ) % htmltemp Manually step through what this line should do. Follow the exact same rules Python will follow in evaluating this expression. http://docs.python.org/2/reference/expressions.html#operator-precedence http://docs.python.org/3/reference/expressions.html#operator-precedence As you'll see from footnote 8 or 5 (depending on which version of the docs), your percent operator is the same one listed in the table as a division operator. Now. Go through that expression, step by step. Walk through everything the Python interpreter does. Figure out exactly what happens first, second, third. Figure out when your percent operator gets handled. Then you'll know what's wrong with that line of code. You'll also gain a very useful understanding of Python, and more generally of the way most high level languages parse expressions. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 10:26:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 07:26:50 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: ?? ??????, 7 ??????? 2013 5:13:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 8, 2013 at 2:01 AM, ????? ???33? wrote: > > > os.system( 'python metrites.py > %s' ) % htmltemp > > > > Manually step through what this line should do. Follow the exact same > > rules Python will follow in evaluating this expression. > > > > http://docs.python.org/2/reference/expressions.html#operator-precedence > > http://docs.python.org/3/reference/expressions.html#operator-precedence > > > > As you'll see from footnote 8 or 5 (depending on which version of the > > docs), your percent operator is the same one listed in the table as a > > division operator. > > > > Now. Go through that expression, step by step. Walk through everything > > the Python interpreter does. Figure out exactly what happens first, > > second, third. Figure out when your percent operator gets handled. > > Then you'll know what's wrong with that line of code. > > > > You'll also gain a very useful understanding of Python, and more > > generally of the way most high level languages parse expressions. > > > > ChrisA I'am sorry to say i cant figure this out :( please enlight me. From rosuav at gmail.com Thu Mar 7 10:33:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 02:33:10 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 2:26 AM, ????? ???33? wrote: > ?? ??????, 7 ??????? 2013 5:13:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Fri, Mar 8, 2013 at 2:01 AM, ????? ???33? wrote: >> >> > os.system( 'python metrites.py > %s' ) % htmltemp >> >> >> >> Manually step through what this line should do. Follow the exact same >> >> rules Python will follow in evaluating this expression. >> >> >> >> http://docs.python.org/2/reference/expressions.html#operator-precedence >> >> http://docs.python.org/3/reference/expressions.html#operator-precedence >> >> >> >> As you'll see from footnote 8 or 5 (depending on which version of the >> >> docs), your percent operator is the same one listed in the table as a >> >> division operator. >> >> >> >> Now. Go through that expression, step by step. Walk through everything >> >> the Python interpreter does. Figure out exactly what happens first, >> >> second, third. Figure out when your percent operator gets handled. >> >> Then you'll know what's wrong with that line of code. >> >> >> >> You'll also gain a very useful understanding of Python, and more >> >> generally of the way most high level languages parse expressions. >> >> >> >> ChrisA > > I'am sorry to say i cant figure this out :( > please enlight me. You can figure it out, but it will take some effort. I will not enlighten you further. The documentation is all there; the answers are available. ChrisA From nikos.gr33k at gmail.com Thu Mar 7 10:26:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 07:26:50 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: ?? ??????, 7 ??????? 2013 5:13:24 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 8, 2013 at 2:01 AM, ????? ???33? wrote: > > > os.system( 'python metrites.py > %s' ) % htmltemp > > > > Manually step through what this line should do. Follow the exact same > > rules Python will follow in evaluating this expression. > > > > http://docs.python.org/2/reference/expressions.html#operator-precedence > > http://docs.python.org/3/reference/expressions.html#operator-precedence > > > > As you'll see from footnote 8 or 5 (depending on which version of the > > docs), your percent operator is the same one listed in the table as a > > division operator. > > > > Now. Go through that expression, step by step. Walk through everything > > the Python interpreter does. Figure out exactly what happens first, > > second, third. Figure out when your percent operator gets handled. > > Then you'll know what's wrong with that line of code. > > > > You'll also gain a very useful understanding of Python, and more > > generally of the way most high level languages parse expressions. > > > > ChrisA I'am sorry to say i cant figure this out :( please enlight me. From nikos.gr33k at gmail.com Thu Mar 7 10:57:33 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 07:57:33 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> ?? ??????, 7 ??????? 2013 5:33:10 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You can figure it out, but it will take some effort. I will not > > enlighten you further. The documentation is all there; the answers are > > available. I found it! I have placed 'htmltemp' within the os.system() call. Otherwise, os.system() returns a return value (int) which python then tries to concatenate with htmltemp (string). os.system( 'python metrites.py > %s' % htmltemp ) :-) From nikos.gr33k at gmail.com Thu Mar 7 10:57:33 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 07:57:33 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> ?? ??????, 7 ??????? 2013 5:33:10 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > You can figure it out, but it will take some effort. I will not > > enlighten you further. The documentation is all there; the answers are > > available. I found it! I have placed 'htmltemp' within the os.system() call. Otherwise, os.system() returns a return value (int) which python then tries to concatenate with htmltemp (string). os.system( 'python metrites.py > %s' % htmltemp ) :-) From joel.goldstick at gmail.com Thu Mar 7 13:57:18 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Mar 2013 13:57:18 -0500 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> Message-ID: On Thu, Mar 7, 2013 at 1:51 PM, rh wrote: > On Thu, 7 Mar 2013 07:57:33 -0800 (PST) > ????? ???33? wrote: > > > > I found it! I have placed 'htmltemp' within the os.system() call. > > Otherwise, os.system() returns a return value (int) which python then > > tries to concatenate with htmltemp (string). > > > > os.system( 'python metrites.py > %s' % htmltemp ) > > Can also do > sterrs = 'errorsout' > os.system( 'python metrites.py > {0} 2> {1}'.format(htmltemp,sterrs)) > > It's more 3ish, or 3ist or 3like. > > > > :-) > > -- > http://mail.python.org/mailman/listinfo/python-list > The content type situation is discussed here http://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2 -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Thu Mar 7 14:36:33 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Mar 2013 14:36:33 -0500 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> Message-ID: On Thu, Mar 7, 2013 at 1:57 PM, Joel Goldstick wrote: > > > > On Thu, Mar 7, 2013 at 1:51 PM, rh wrote: > >> On Thu, 7 Mar 2013 07:57:33 -0800 (PST) >> ????? ???33? wrote: >> > >> > I found it! I have placed 'htmltemp' within the os.system() call. >> > Otherwise, os.system() returns a return value (int) which python then >> > tries to concatenate with htmltemp (string). >> > >> > os.system( 'python metrites.py > %s' % htmltemp ) >> >> Can also do >> sterrs = 'errorsout' >> os.system( 'python metrites.py > {0} 2> {1}'.format(htmltemp,sterrs)) >> >> It's more 3ish, or 3ist or 3like. >> > >> > :-) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > The content type situation is discussed here > http://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2 > > -- > Joel Goldstick > http://joelgoldstick.com > So, I see you fixed the problem. How? -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Thu Mar 7 15:04:42 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 12:04:42 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> Message-ID: <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> ?? ??????, 7 ??????? 2013 9:36:33 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > ?So, I see you fixed the problem.? How? Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just d: os.system( 'python %s > %s' % (htmlpage, temp) ) f = open( temp ) htmldata = f.read() htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' ) From nikos.gr33k at gmail.com Thu Mar 7 15:04:42 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 12:04:42 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> Message-ID: <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> ?? ??????, 7 ??????? 2013 9:36:33 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > ?So, I see you fixed the problem.? How? Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just d: os.system( 'python %s > %s' % (htmlpage, temp) ) f = open( temp ) htmldata = f.read() htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' ) From ian.g.kelly at gmail.com Thu Mar 7 15:15:11 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Mar 2013 13:15:11 -0700 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 1:04 PM, ????? ???33? wrote: > ?? ??????, 7 ??????? 2013 9:36:33 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > >> So, I see you fixed the problem. How? > > Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just d: > > os.system( 'python %s > %s' % (htmlpage, temp) ) > f = open( temp ) > htmldata = f.read() > htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' ) If htmlpage is being pulled from the HTTP request as I think it is, then you have a code injection vulnerability here. Think what could happen if htmlpage were something like this: -c ''; rm -rf /; oops.py From nikos.gr33k at gmail.com Thu Mar 7 19:57:30 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 16:57:30 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> Message-ID: <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> ?? ??????, 7 ??????? 2013 10:15:11 ?.?. UTC+2, ? ??????? Ian ??????: > On Thu, Mar 7, 2013 at 1:04 PM, ????? ???33? wrote: > > > ?? ??????, 7 ??????? 2013 9:36:33 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > > > > > >> So, I see you fixed the problem. How? > > > > > > Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just d: > > > > > > os.system( 'python %s > %s' % (htmlpage, temp) ) > > > f = open( temp ) > > > htmldata = f.read() > > > htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' ) > > > > If htmlpage is being pulled from the HTTP request as I think it is, > > then you have a code injection vulnerability here. Think what could > > happen if htmlpage were something like this: > > > > -c ''; rm -rf /; oops.py Yes its being pulled by http request! But please try to do it, i dont think it will work! From nikos.gr33k at gmail.com Thu Mar 7 19:57:30 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 16:57:30 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> Message-ID: <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> ?? ??????, 7 ??????? 2013 10:15:11 ?.?. UTC+2, ? ??????? Ian ??????: > On Thu, Mar 7, 2013 at 1:04 PM, ????? ???33? wrote: > > > ?? ??????, 7 ??????? 2013 9:36:33 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > > > > > >> So, I see you fixed the problem. How? > > > > > > Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just d: > > > > > > os.system( 'python %s > %s' % (htmlpage, temp) ) > > > f = open( temp ) > > > htmldata = f.read() > > > htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' ) > > > > If htmlpage is being pulled from the HTTP request as I think it is, > > then you have a code injection vulnerability here. Think what could > > happen if htmlpage were something like this: > > > > -c ''; rm -rf /; oops.py Yes its being pulled by http request! But please try to do it, i dont think it will work! From vito.detullio at gmail.com Thu Mar 7 22:55:07 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Fri, 08 Mar 2013 04:55:07 +0100 Subject: An error when i switched from python v2.6.6 => v3.2.3 References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: ????? ???33? wrote: >> -c ''; rm -rf /; oops.py > > Yes its being pulled by http request! > > But please try to do it, i dont think it will work! try yourself and tell us what happened -- ZeD From nikos.gr33k at gmail.com Fri Mar 8 01:54:38 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 22:54:38 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: <2119e29e-da51-4c37-a0f5-26b70d907a53@googlegroups.com> ?? ?????????, 8 ??????? 2013 5:55:07 ?.?. UTC+2, ? ??????? Vito De Tullio ??????: > ????? ???33? wrote: > > > > >> -c ''; rm -rf /; oops.py > > > > > > Yes its being pulled by http request! > > > > > > But please try to do it, i dont think it will work! > > > > try yourself and tell us what happened > > > > -- > > ZeD What command should i issue to try code injection? someone tried it yesterday but it didnt work. From nikos.gr33k at gmail.com Fri Mar 8 01:54:38 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 22:54:38 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: <2119e29e-da51-4c37-a0f5-26b70d907a53@googlegroups.com> ?? ?????????, 8 ??????? 2013 5:55:07 ?.?. UTC+2, ? ??????? Vito De Tullio ??????: > ????? ???33? wrote: > > > > >> -c ''; rm -rf /; oops.py > > > > > > Yes its being pulled by http request! > > > > > > But please try to do it, i dont think it will work! > > > > try yourself and tell us what happened > > > > -- > > ZeD What command should i issue to try code injection? someone tried it yesterday but it didnt work. From nikos.gr33k at gmail.com Fri Mar 8 01:56:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 22:56:45 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> ?? ?????????, 8 ??????? 2013 5:55:07 ?.?. UTC+2, ? ??????? Vito De Tullio ??????: > ????? ???33? wrote: > > > > >> -c ''; rm -rf /; oops.py > > > > > > Yes its being pulled by http request! > > > > > > But please try to do it, i dont think it will work! > > > > try yourself and tell us what happened > > > > -- > > ZeD Someone with ip of: dslb-188-108-250-211.pools.arcor-ip.net Windows Opera 1 2013-03-08 03:19:18 as my cgi script tells me. i think it was Chris Angelico :-) From nikos.gr33k at gmail.com Fri Mar 8 01:56:45 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 22:56:45 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> ?? ?????????, 8 ??????? 2013 5:55:07 ?.?. UTC+2, ? ??????? Vito De Tullio ??????: > ????? ???33? wrote: > > > > >> -c ''; rm -rf /; oops.py > > > > > > Yes its being pulled by http request! > > > > > > But please try to do it, i dont think it will work! > > > > try yourself and tell us what happened > > > > -- > > ZeD Someone with ip of: dslb-188-108-250-211.pools.arcor-ip.net Windows Opera 1 2013-03-08 03:19:18 as my cgi script tells me. i think it was Chris Angelico :-) From rosuav at gmail.com Fri Mar 8 02:01:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 18:01:59 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 5:56 PM, ????? ???33? wrote: > Someone with ip of: > > dslb-188-108-250-211.pools.arcor-ip.net Windows Opera 1 2013-03-08 03:19:18 > > as my cgi script tells me. > > i think it was Chris Angelico :-) Nope, not me. As you'll be able to confirm in any number of ways, I'm in Australia. Also, I use Chrome. That's someone else! As a general rule, don't reveal people's IP addresses without permission or good reason; it's unnecessarily breaking privacy. ChrisA From nikos.gr33k at gmail.com Fri Mar 8 05:51:28 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 02:51:28 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> Message-ID: I must thank the tester of my webisites's security! He hacked it nicely and easily through tampering with 'htmlpage' variable's value! Now i'am validating htmlpage's input value and i don't beleive its hackable any more! Please feel free to try whoever want to! Thnk you all for your patience with me and support provided! From nikos.gr33k at gmail.com Fri Mar 8 05:51:28 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 02:51:28 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <93a09412-7d71-4c74-a5ae-9d135d544720@googlegroups.com> Message-ID: I must thank the tester of my webisites's security! He hacked it nicely and easily through tampering with 'htmlpage' variable's value! Now i'am validating htmlpage's input value and i don't beleive its hackable any more! Please feel free to try whoever want to! Thnk you all for your patience with me and support provided! From steve+comp.lang.python at pearwood.info Fri Mar 8 13:54:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2013 18:54:15 GMT Subject: An error when i switched from python v2.6.6 => v3.2.3 References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> Message-ID: <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 08 Mar 2013 04:55:07 +0100, Vito De Tullio wrote: > ????? ???33? wrote: > >>> -c ''; rm -rf /; oops.py >> >> Yes its being pulled by http request! >> >> But please try to do it, i dont think it will work! > > try yourself and tell us what happened That's not very nice. Please don't tell the newbies to destroy their system, no matter how tempting it might be. -- Steven From info at cravendot.gr Fri Mar 8 14:19:33 2013 From: info at cravendot.gr (info at cravendot.gr) Date: Fri, 8 Mar 2013 11:19:33 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> ?? ?????????, 8 ??????? 2013 8:54:15 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > On Fri, 08 Mar 2013 04:55:07 +0100, Vito De Tullio wrote: > > > > > ????? ???33? wrote: > > > > > >>> -c ''; rm -rf /; oops.py > > >> > > >> Yes its being pulled by http request! > > >> > > >> But please try to do it, i dont think it will work! > > > > > > try yourself and tell us what happened > > > > > > That's not very nice. > > > > Please don't tell the newbies to destroy their system, no matter how > > tempting it might be. > > > > > > > > > > -- > > Steven I dare anyone who wants to to mess with 'htmlpage' variable value's now! I made it unhackable i believe! I'am testing it myself 3 hours now and find it safe! Please feel free to try also! From ian.g.kelly at gmail.com Fri Mar 8 15:01:59 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Mar 2013 13:01:59 -0700 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 12:19 PM, wrote: > I dare anyone who wants to to mess with 'htmlpage' variable value's now! > > I made it unhackable i believe! > > I'am testing it myself 3 hours now and find it safe! > > Please feel free to try also! Okay, done. I was still able to read your source files, and I was still able to write a file to your webserver. All I had to do was change 'htmlpage' to 'page' in the example URLs I sent you before. Validating the 'htmlpage' field does nothing if you also switch the dispatch to the 'page' field. And as far as the validation goes, from what I can see in the source, it looks like you're just checking whether the string '.html' appears in it somewhere. It's not hard at all to craft a malicious page request that meets that. As a start, try checking that the file actually exists before doing anything with it, and that it is in one of the directories used by your web server. From ian.g.kelly at gmail.com Fri Mar 8 15:04:58 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Mar 2013 13:04:58 -0700 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:01 PM, Ian Kelly wrote: > On Fri, Mar 8, 2013 at 12:19 PM, wrote: >> I dare anyone who wants to to mess with 'htmlpage' variable value's now! >> >> I made it unhackable i believe! >> >> I'am testing it myself 3 hours now and find it safe! >> >> Please feel free to try also! > > Okay, done. I was still able to read your source files, and I was > still able to write a file to your webserver. All I had to do was > change 'htmlpage' to 'page' in the example URLs I sent you before. > Validating the 'htmlpage' field does nothing if you also switch the > dispatch to the 'page' field. > > And as far as the validation goes, from what I can see in the source, > it looks like you're just checking whether the string '.html' appears > in it somewhere. It's not hard at all to craft a malicious page > request that meets that. > > As a start, try checking that the file actually exists before doing > anything with it, and that it is in one of the directories used by > your web server. os.path.isfile will help with the former, while os.path.realname and os.path.dirname will help with the latter. From nikos.gr33k at gmail.com Fri Mar 8 15:31:53 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 12:31:53 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> Message-ID: <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> ?? ?????????, 8 ??????? 2013 10:01:59 ?.?. UTC+2, ? ??????? Ian ??????: > On Fri, Mar 8, 2013 at 12:19 PM, wrote: > > > I dare anyone who wants to to mess with 'htmlpage' variable value's now! > > > > > > I made it unhackable i believe! > > > > > > I'am testing it myself 3 hours now and find it safe! > > > > > > Please feel free to try also! > > > > Okay, done. I was still able to read your source files, and I was > > still able to write a file to your webserver. All I had to do was > > change 'htmlpage' to 'page' in the example URLs I sent you before. > > Validating the 'htmlpage' field does nothing if you also switch the > > dispatch to the 'page' field. > > > > And as far as the validation goes, from what I can see in the source, > > it looks like you're just checking whether the string '.html' appears > > in it somewhere. It's not hard at all to craft a malicious page > > request that meets that. > > > > As a start, try checking that the file actually exists before doing > > anything with it, and that it is in one of the directories used by > > your web server. Thank you very much for pointing my flaws once again! I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! I have added extra security by following some of your advice, i wonder if youc an hack it again! Fell free to try if i'am not tiring you please! From nikos.gr33k at gmail.com Fri Mar 8 15:31:53 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 12:31:53 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> Message-ID: <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> ?? ?????????, 8 ??????? 2013 10:01:59 ?.?. UTC+2, ? ??????? Ian ??????: > On Fri, Mar 8, 2013 at 12:19 PM, wrote: > > > I dare anyone who wants to to mess with 'htmlpage' variable value's now! > > > > > > I made it unhackable i believe! > > > > > > I'am testing it myself 3 hours now and find it safe! > > > > > > Please feel free to try also! > > > > Okay, done. I was still able to read your source files, and I was > > still able to write a file to your webserver. All I had to do was > > change 'htmlpage' to 'page' in the example URLs I sent you before. > > Validating the 'htmlpage' field does nothing if you also switch the > > dispatch to the 'page' field. > > > > And as far as the validation goes, from what I can see in the source, > > it looks like you're just checking whether the string '.html' appears > > in it somewhere. It's not hard at all to craft a malicious page > > request that meets that. > > > > As a start, try checking that the file actually exists before doing > > anything with it, and that it is in one of the directories used by > > your web server. Thank you very much for pointing my flaws once again! I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! I have added extra security by following some of your advice, i wonder if youc an hack it again! Fell free to try if i'am not tiring you please! From rosuav at gmail.com Fri Mar 8 16:37:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 08:37:11 +1100 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: On Sat, Mar 9, 2013 at 7:31 AM, ????? ???33? wrote: > I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! > > I have added extra security by following some of your advice, i wonder if youc an hack it again! > > Fell free to try if i'am not tiring you please! Something to think about: There are roughly seven billion people on this planet. You are just one of them; Steven is just one more. This entire mailing list/newsgroup amounts to the most miniscule fraction of the earth's population. There is NO WAY that you are the smartest or most devious person on Earth. Also, the three hours that you put in are *nothing* compared to the collective time that the rest of the world will spend fiddling with your site. Even if all of python-list/c.l.p spent a few hours trying to get around your site's security, that's still not a huge amount compared to the whole planet's deviousness. You cannot build web site security on the basis of "well, I couldn't get around it, and I tried for a few hours". I had this argument with my boss just yesterday; I pointed out that there was a place where user input was being put into an HTML attribute without being properly escaped (and demonstrated that putting A into the input was equivalent to putting A in), and he asked me how it could possibly be exploited. My response: That does not matter. The mere fact that I could provably show a difference WAS the problem. With that, a determined attacker could potentially figure out a real exploit; it does not matter that I wasn't able to do so. You need to change your thinking about security/safety. Instead of trying to filter/clean tainted input before passing it to a system() call, you need to either whitelist BRUTALLY first (eg insist that the string be one of a particular set of strings - and no, it's not sufficient to make sure that it has only characters from a particular set, though that's a good start), or just plain don't give tainted strings to os.system(). What you have is a MASSIVE potential attack vector. It's quite possibly unsalvageably dangerous. ChrisA From ian.g.kelly at gmail.com Fri Mar 8 19:26:56 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Mar 2013 17:26:56 -0700 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 1:31 PM, ????? ???33? wrote: > Thank you very much for pointing my flaws once again! > > I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! > > I have added extra security by following some of your advice, i wonder if youc an hack it again! > > Fell free to try if i'am not tiring you please! That seems to be better, although I want to stress that I did not try very hard. It's possible that somebody with more patience and imagination than myself might still find a way to fool your validation. From nagia.retsina at gmail.com Fri Mar 8 22:15:08 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 8 Mar 2013 19:15:08 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: <608b6264-921c-4d00-98cd-81b89f2dc20b@googlegroups.com> ?? ???????, 9 ??????? 2013 2:26:56 ?.?. UTC+2, ? ??????? Ian ??????: > On Fri, Mar 8, 2013 at 1:31 PM, ????? ???33? wrote: > > > Thank you very much for pointing my flaws once again! > > > > > > I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! > > > > > > I have added extra security by following some of your advice, i wonder if youc an hack it again! > > > > > > Fell free to try if i'am not tiring you please! > > > > That seems to be better, although I want to stress that I did not try > > very hard. It's possible that somebody with more patience and > > imagination than myself might still find a way to fool your > > validation. I'am glad the script has been made more secure after of course you enilghten me and i followed your advice. Here is what i did: # detect how 'index.html' is called and validate values of 'htmlpage' & 'page' if page and os.path.isfile( '/home/nikos/www/cgi-bin/' + page ): page = page elif form.getvalue('show') and os.path.isfile( htmlpage ): page = htmlpage.replace( '/home/nikos/public_html/', '' ) else: page = 'index.html' Now that you have the if structure's logic can you *still* fool the script? From nagia.retsina at gmail.com Fri Mar 8 22:15:08 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 8 Mar 2013 19:15:08 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: <608b6264-921c-4d00-98cd-81b89f2dc20b@googlegroups.com> ?? ???????, 9 ??????? 2013 2:26:56 ?.?. UTC+2, ? ??????? Ian ??????: > On Fri, Mar 8, 2013 at 1:31 PM, ????? ???33? wrote: > > > Thank you very much for pointing my flaws once again! > > > > > > I cant beleive how easy you hacked the webserver again and be able to read my cgi scripts source and write to cgi-bin too! > > > > > > I have added extra security by following some of your advice, i wonder if youc an hack it again! > > > > > > Fell free to try if i'am not tiring you please! > > > > That seems to be better, although I want to stress that I did not try > > very hard. It's possible that somebody with more patience and > > imagination than myself might still find a way to fool your > > validation. I'am glad the script has been made more secure after of course you enilghten me and i followed your advice. Here is what i did: # detect how 'index.html' is called and validate values of 'htmlpage' & 'page' if page and os.path.isfile( '/home/nikos/www/cgi-bin/' + page ): page = page elif form.getvalue('show') and os.path.isfile( htmlpage ): page = htmlpage.replace( '/home/nikos/public_html/', '' ) else: page = 'index.html' Now that you have the if structure's logic can you *still* fool the script? From nikos.gr33k at gmail.com Fri Mar 8 22:18:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 19:18:50 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: ?? ?????????, 8 ??????? 2013 11:37:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > There is NO WAY that you are the smartest or most devious person on > Earth. Also, the three hours that you put in are *nothing* compared to > the collective time that the rest of the world will spend fiddling > with your site. Even if all of python-list/c.l.p spent a few hours > trying to get around your site's security, that's still not a huge > amount compared to the whole planet's deviousness. I agree with you but i wonder why the world would want to dedicate hours for fiddling with my script? Why anyone should mess with my website http://superhost.gr ? From nikos.gr33k at gmail.com Fri Mar 8 22:18:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 19:18:50 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: ?? ?????????, 8 ??????? 2013 11:37:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > There is NO WAY that you are the smartest or most devious person on > Earth. Also, the three hours that you put in are *nothing* compared to > the collective time that the rest of the world will spend fiddling > with your site. Even if all of python-list/c.l.p spent a few hours > trying to get around your site's security, that's still not a huge > amount compared to the whole planet's deviousness. I agree with you but i wonder why the world would want to dedicate hours for fiddling with my script? Why anyone should mess with my website http://superhost.gr ? From breamoreboy at yahoo.co.uk Fri Mar 8 22:27:32 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 09 Mar 2013 03:27:32 +0000 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: On 09/03/2013 03:18, ????? ???33? wrote: > ?? ?????????, 8 ??????? 2013 11:37:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > >> There is NO WAY that you are the smartest or most devious person on >> Earth. Also, the three hours that you put in are *nothing* compared to >> the collective time that the rest of the world will spend fiddling >> with your site. Even if all of python-list/c.l.p spent a few hours >> trying to get around your site's security, that's still not a huge >> amount compared to the whole planet's deviousness. > > I agree with you but i wonder why the world would want to dedicate hours for fiddling with my script? Why anyone should mess with my website http://superhost.gr ? > Because hackers love hacking? But I suspect they might give you a miss as too easy, preferring to take on the theoretically challenging places such as UK MOD, Pentagon, GCHQ, NSA, MI5 and MI6. Note however that it's difficult to hack some of these people as of course they don't actually exist :) -- Cheers. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Mar 9 00:05:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Mar 2013 05:05:08 GMT Subject: An error when i switched from python v2.6.6 => v3.2.3 References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> Message-ID: <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> On Fri, 08 Mar 2013 19:18:50 -0800, ????? ???33? wrote: > I agree with you but i wonder why the world would want to dedicate hours > for fiddling with my script? Why anyone should mess with my website > http://superhost.gr ? What makes you think it would be hours? For somebody who knows what they are doing, it is probably more like minutes. And as for why... - because they think it's funny; - because they get pleasure from vandalising other people's property; - to prove that they can do it; - to punish you for being naive and foolish; - to get control of your webserver, so they can store files on it without your knowledge; - or launch attacks on other people's websites; - or to encrypt your data and charge you money to decrypt it; - or some other reason that I cannot think of. -- Steven From nikos.gr33k at gmail.com Sat Mar 9 02:56:04 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 23:56:04 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> ?? ???????, 9 ??????? 2013 7:05:08 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > On Fri, 08 Mar 2013 19:18:50 -0800, ????? ???33? wrote: > > > > > I agree with you but i wonder why the world would want to dedicate hours > > > for fiddling with my script? Why anyone should mess with my website > > > http://superhost.gr ? > > > > > > What makes you think it would be hours? For somebody who knows what they > > are doing, it is probably more like minutes. > > > > And as for why... > > > > - because they think it's funny; > > > > - because they get pleasure from vandalising other people's property; > > > > - to prove that they can do it; > > > > - to punish you for being naive and foolish; > > > > - to get control of your webserver, so they can store files on it without > > your knowledge; > > > > - or launch attacks on other people's websites; > > > > - or to encrypt your data and charge you money to decrypt it; > > > > - or some other reason that I cannot think of. > > > > > > > > -- > > Steven I see, didn think of those reason apart form the fact that they cna prove they can do it! But as i have it now more security improved they can't :-) From breamoreboy at yahoo.co.uk Sat Mar 9 07:43:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 09 Mar 2013 12:43:52 +0000 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> Message-ID: On 09/03/2013 07:56, ????? ???33? wrote: > ?? ???????, 9 ??????? 2013 7:05:08 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: >> On Fri, 08 Mar 2013 19:18:50 -0800, ????? ???33? wrote: >> >> >> >>> I agree with you but i wonder why the world would want to dedicate hours >> >>> for fiddling with my script? Why anyone should mess with my website >> >>> http://superhost.gr ? >> >> >> >> >> >> What makes you think it would be hours? For somebody who knows what they >> >> are doing, it is probably more like minutes. >> >> >> >> And as for why... >> >> >> >> - because they think it's funny; >> >> >> >> - because they get pleasure from vandalising other people's property; >> >> >> >> - to prove that they can do it; >> >> >> >> - to punish you for being naive and foolish; >> >> >> >> - to get control of your webserver, so they can store files on it without >> >> your knowledge; >> >> >> >> - or launch attacks on other people's websites; >> >> >> >> - or to encrypt your data and charge you money to decrypt it; >> >> >> >> - or some other reason that I cannot think of. >> >> >> >> >> >> >> >> -- >> >> Steven > > I see, didn think of those reason apart form the fact that they cna prove they can do it! > > But as i have it now more security improved they can't :-) > Red flag to a bull. Would you also please read section 2 of this http://wiki.python.org/moin/GoogleGroupsPython to prevent all of your posts having an excessive number of quoted blank lines. -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Sat Mar 9 09:16:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 06:16:47 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> Message-ID: <1d7f174d-f4a8-4960-b0b4-178bf53cd86c@googlegroups.com> Is there a way to see anserws to my posts via ThunderBird that doesn't hve this formatting issue? From nikos.gr33k at gmail.com Sat Mar 9 09:16:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 06:16:47 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> Message-ID: <1d7f174d-f4a8-4960-b0b4-178bf53cd86c@googlegroups.com> Is there a way to see anserws to my posts via ThunderBird that doesn't hve this formatting issue? From rustompmody at gmail.com Sat Mar 9 10:20:27 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 9 Mar 2013 07:20:27 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <1a79c210-3c50-43bb-8a78-5d5ef60922ec@googlegroups.com> <85b5c606-a1c7-480b-a900-622f61751b87@googlegroups.com> <513ac303$0$6512$c3e8da3$5496439d@news.astraweb.com> <41dab159-ebe5-4676-8482-609df1736542@googlegroups.com> Message-ID: On Mar 9, 7:16?pm, ????? ???33? wrote: > Is there a way to see anserws to my posts via ThunderBird that doesn't hve this formatting issue? I had posted a suggestion to get back to 'old google groups' here. Usually if you (can) switch to the old these problems vanish http://mail.python.org/pipermail/python-list/2012-October/633460.html [According to Alex it seems you may have to actively select the new before you can select the old] From nagia.retsina at gmail.com Fri Mar 8 15:54:43 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 8 Mar 2013 12:54:43 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: ?? ?????????, 8 ??????? 2013 8:54:15 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > >>> -c ''; rm -rf /; oops.py > Please don't tell the newbies to destroy their system, no matter how > tempting it might be. What that "-c ''" options i keep seeing in the attempts to pass bogus info in my 'page' variable? And hows oops.py relevant? Such file doesnt nto exist in my webssever. From emile at fenx.com Fri Mar 8 17:13:01 2013 From: emile at fenx.com (emile) Date: Fri, 08 Mar 2013 14:13:01 -0800 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/08/2013 12:54 PM, nagia.retsina at gmail.com wrote: > ?? ?????????, 8 ??????? 2013 8:54:15 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > >>>>> -c ''; rm -rf /; oops.py > >> Please don't tell the newbies to destroy their system, no matter how >> tempting it might be. > > What that "-c ''" options i keep seeing in the attempts to pass bogus info in my 'page' variable? > > And hows oops.py relevant? Such file doesnt nto exist in my webssever. > You're certainly right about that -- particularly by the time it's attempted. :) Emile From ian.g.kelly at gmail.com Fri Mar 8 19:18:42 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Mar 2013 17:18:42 -0700 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 8, 2013 at 1:54 PM, wrote: > ?? ?????????, 8 ??????? 2013 8:54:15 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > >> >>> -c ''; rm -rf /; oops.py > >> Please don't tell the newbies to destroy their system, no matter how >> tempting it might be. > > What that "-c ''" options i keep seeing in the attempts to pass bogus info in my 'page' variable? > > And hows oops.py relevant? Such file doesnt nto exist in my webssever. The command that gets run is "python %s > %s", where the page variable is substituted in for the first %s. If you perform that substitution, you will get: python -c ''; rm -rf /; oops.py > /path/to/some/temp/file So the -c is an option to Python. It means that instead of reading a script, Python should run commands passed on the command line in the next argument. That's the ''. It's empty, so what this instructs Python is to do nothing at all. The second command in this shell script is "rm -rf /". I assume you know what that would do. The third command is "oops.py > /path/to/some/tempfile". The fact that oops.py does not exist is not important, because the attacker does not care what this command does. The payload of the attack was already delivered in the second command. The only reason for this is because it ends in .py, which is what the web server is looking for when deciding whether to run a script. The word "oops" here is just for levity. From nikos.gr33k at gmail.com Fri Mar 8 22:17:13 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 19:17:13 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <99eae754-5074-4f08-8d36-9578eb41d57e@googlegroups.com> ?? ???????, 9 ??????? 2013 2:18:42 ?.?. UTC+2, ? ??????? Ian ??????: > So the -c is an option to Python. It means that instead of reading a > script, Python should run commands passed on the command line in the > next argument. That's the ''. It's empty, so what this instructs > Python is to do nothing at all. > The second command in this shell script is "rm -rf /". I assume you > know what that would do. Thank you for explaining but i'am not sure i ahve understand this part. Can you please elaborate more? From breamoreboy at yahoo.co.uk Fri Mar 8 22:33:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 09 Mar 2013 03:33:09 +0000 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <99eae754-5074-4f08-8d36-9578eb41d57e@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> <99eae754-5074-4f08-8d36-9578eb41d57e@googlegroups.com> Message-ID: On 09/03/2013 03:17, ????? ???33? wrote: > ?? ???????, 9 ??????? 2013 2:18:42 ?.?. UTC+2, ? ??????? Ian ??????: > >> So the -c is an option to Python. It means that instead of reading a >> script, Python should run commands passed on the command line in the >> next argument. That's the ''. It's empty, so what this instructs >> Python is to do nothing at all. >> The second command in this shell script is "rm -rf /". I assume you >> know what that would do. > > Thank you for explaining but i'am not sure i ahve understand this part. > Can you please elaborate more? > I confess to knowing very little about *nix commands, but I believe the second command referenced above does something like delete everything on your hard drive. Not that this is a problem as your improved security ensures that this can't happen, doesn't it? -- Cheers. Mark Lawrence From nikos.gr33k at gmail.com Fri Mar 8 22:17:13 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 19:17:13 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <33f153b4-4f54-429a-a92d-387b679bf758@googlegroups.com> <20130307105137.a6cae268f7f074fbf5017b1d@lavabit.com> <0074be2d-1f52-4626-bf53-fd9591f16bf7@googlegroups.com> <98cd9065-94b0-4fb6-b2fd-6ed96880242d@googlegroups.com> <513a33d7$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <99eae754-5074-4f08-8d36-9578eb41d57e@googlegroups.com> ?? ???????, 9 ??????? 2013 2:18:42 ?.?. UTC+2, ? ??????? Ian ??????: > So the -c is an option to Python. It means that instead of reading a > script, Python should run commands passed on the command line in the > next argument. That's the ''. It's empty, so what this instructs > Python is to do nothing at all. > The second command in this shell script is "rm -rf /". I assume you > know what that would do. Thank you for explaining but i'am not sure i ahve understand this part. Can you please elaborate more? From gordon at panix.com Thu Mar 7 10:55:58 2013 From: gordon at panix.com (John Gordon) Date: Thu, 7 Mar 2013 15:55:58 +0000 (UTC) Subject: An error when i switched from python v2.6.6 => v3.2.3 References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: In =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= writes: > Switching back to: > os.system( 'python metrites.py > %s' ) % htmltemp > f =3D open( htmltemp ) > htmldata =3D f.read()=09 > but still donse see what iam doing wrong..... You have the close-parentheses in the wrong place. The line should be: os.system( 'python metrites.py > %s' % htmltemp ) -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From nikos.gr33k at gmail.com Thu Mar 7 11:00:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 08:00:31 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> Message-ID: <4e3c3750-605f-4d91-af21-a1c22d89912f@googlegroups.com> ?? ??????, 7 ??????? 2013 5:55:58 ?.?. UTC+2, ? ??????? John Gordon ??????: > In =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= writes: > > > > > Switching back to: > > > > > os.system( 'python metrites.py > %s' ) % htmltemp > > > f =3D open( htmltemp ) > > > htmldata =3D f.read()=09 > > > > > but still donse see what iam doing wrong..... > > > > You have the close-parentheses in the wrong place. The line should be: > > > > os.system( 'python metrites.py > %s' % htmltemp ) > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon at panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" Yes thank you, i found it myself and moment later i also saw your post! I'am very excites i discoverd it myself! Now instead of receiving proper html output i receive this: Go to http://superhost.gr please and click the 1st image you see on the top. Instead for the pelatologio.py html output to appear + counter string i see weird formatting, if you want please take a look. From nikos.gr33k at gmail.com Thu Mar 7 11:22:25 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 7 Mar 2013 08:22:25 -0800 (PST) Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: <4e3c3750-605f-4d91-af21-a1c22d89912f@googlegroups.com> References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <4e3c3750-605f-4d91-af21-a1c22d89912f@googlegroups.com> Message-ID: I have fixed this! Still ahve allok and you will see that in both of my images they appear in the firstpage of superhost.gr the output of .py files appear fine except of that ehen a visitor click on my first 2 image links he also sees as first line this: print ( "Content-type: text/html; charset=utf-8\n" ) this is because the above code is a header and its contained to every cgi .py file that i generate html ouput from via os.system() Can this be somehow eliminated? From joel.goldstick at gmail.com Thu Mar 7 12:41:48 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Mar 2013 12:41:48 -0500 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <4e3c3750-605f-4d91-af21-a1c22d89912f@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 11:22 AM, ????? ???33? wrote: > I have fixed this! > Still ahve allok and you will see that in both of my images they appear in > the firstpage of superhost.gr > > the output of .py files appear fine except of that ehen a visitor click on > my first 2 image links he also sees as first line this: > > print ( "Content-type: text/html; charset=utf-8\n" ) > > this is because the above code is a header and its contained to every cgi > .py file that i generate html ouput from via os.system() > > Can this be somehow eliminated? > -- > That page is not valid html. View the source in your browser to see -- it has no tag, no , no . fix that stuff > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Thu Mar 7 13:50:35 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 7 Mar 2013 13:50:35 -0500 Subject: An error when i switched from python v2.6.6 => v3.2.3 In-Reply-To: References: <8e17232e-5b24-4040-9215-c4bd89f34fa2@googlegroups.com> <622d4a2d-0014-4254-b211-c8fd66510f74@googlegroups.com> <4e3c3750-605f-4d91-af21-a1c22d89912f@googlegroups.com> Message-ID: On Thu, Mar 7, 2013 at 12:41 PM, Joel Goldstick wrote: > > > > On Thu, Mar 7, 2013 at 11:22 AM, ????? ???33? wrote: > >> I have fixed this! >> Still ahve allok and you will see that in both of my images they appear >> in the firstpage of superhost.gr >> >> the output of .py files appear fine except of that ehen a visitor click >> on my first 2 image links he also sees as first line this: >> >> print ( "Content-type: text/html; charset=utf-8\n" ) >> >> this is because the above code is a header and its contained to every cgi >> .py file that i generate html ouput from via os.system() >> >> Can this be somehow eliminated? >> > This may have to do with the configuration of your server. There may be differences in how to do that for python 2.x and python 3.x. I can't help you more than that > -- >> > > That page is not valid html. View the source in your browser to see -- it > has no tag, no , no . fix that stuff > >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Joel Goldstick > http://joelgoldstick.com > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Thu Mar 7 04:23:20 2013 From: svenito at gmail.com (Sven) Date: Thu, 7 Mar 2013 09:23:20 +0000 Subject: iterating over a list as if it were a circular list Message-ID: I was wondering what the best approach for the following might be. Say you have a list P of points and another list N of other items. You can always assume that len(N) <= len(P) Now I would like to iterate over P and place one N at each point. However if you run out of N I'd like to restart from N[0] and carry on until all the points have been populated. So far I've got for point in points: -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 7 04:28:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2013 20:28:02 +1100 Subject: iterating over a list as if it were a circular list In-Reply-To: References: Message-ID: On Thu, Mar 7, 2013 at 8:23 PM, Sven wrote: > Now I would like to iterate over P and place one N at each point. However if > you run out of N I'd like to restart from N[0] and carry on until all the > points have been populated. Check out itertools.cycle, it should do what you want. ChrisA From clp2 at rebertia.com Thu Mar 7 04:31:51 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 7 Mar 2013 01:31:51 -0800 Subject: iterating over a list as if it were a circular list In-Reply-To: References: Message-ID: On Mar 7, 2013 1:24 AM, "Sven" wrote: > > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can always assume that > > len(N) <= len(P) > > Now I would like to iterate over P and place one N at each point. However if you run out of N I'd like to restart from N[0] and carry on until all the points have been populated. Untested due to the late hour: import itertools for p, n in itertools.izip(P, itertools.cycle(N)): # do whatever -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Thu Mar 7 04:34:46 2013 From: svenito at gmail.com (Sven) Date: Thu, 7 Mar 2013 09:34:46 +0000 Subject: iterating over a list as if it were a circular list In-Reply-To: References: Message-ID: On 7 March 2013 09:31, Chris Rebert wrote: > On Mar 7, 2013 1:24 AM, "Sven" wrote: > > > > I was wondering what the best approach for the following might be. > > > > Say you have a list P of points and another list N of other items. You > can always assume that > > > > len(N) <= len(P) > > > > Now I would like to iterate over P and place one N at each point. > However if you run out of N I'd like to restart from N[0] and carry on > until all the points have been populated. > > Untested due to the late hour: > > import itertools > > for p, n in itertools.izip(P, itertools.cycle(N)): > # do whatever > I knew there was a more sensible way to do it. Thanks. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Thu Mar 7 04:27:42 2013 From: svenito at gmail.com (Sven) Date: Thu, 7 Mar 2013 09:27:42 +0000 Subject: iterating over a list as if it were a circular list Message-ID: Stupid keyboard shortcuts, sent it too early. Apologies I was wondering what the best approach for the following might be. Say you have a list P of points and another list N of other items. You can always assume that len(N) <= len(P) Now I would like to iterate over P and place one N at each point. However if you run out of N I'd like to restart from N[0] and carry on until all the points have been populated. So far I've got (pseudo code) i = 0 for point in points: put N[i] at point if i > len(N): i = 0 is this the most pythonic way to accomplish this? Additionally, what if I wanted to pull a random element from N, but I want to ensure all elements from N have been used before starting to pick already chosen random elements again. So far I thought of duplicating the list and removing the randomly chosen elements from the list, and when it's empty, re-copying it. But that seems a little "wrong" if you know what I mean. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Mar 7 04:38:32 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 7 Mar 2013 01:38:32 -0800 Subject: iterating over a list as if it were a circular list In-Reply-To: References: Message-ID: On Mar 7, 2013 1:29 AM, "Sven" wrote: > > Stupid keyboard shortcuts, sent it too early. Apologies > > > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can always assume that > > len(N) <= len(P) > > Now I would like to iterate over P and place one N at each point. However if you run out of N I'd like to restart from N[0] and carry on until all the points have been populated. > Additionally, what if I wanted to pull a random element from N, but I want to ensure all elements from N have been used before starting to pick already chosen random elements again. > So far I thought of duplicating the list and removing the randomly chosen elements from the list, and when it's empty, re-copying it. But that seems a little "wrong" if you know what I mean. Just iterate over the list in order, and random.shuffle() the list each time you reach the end of it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu Mar 7 08:37:07 2013 From: roy at panix.com (Roy Smith) Date: Thu, 07 Mar 2013 08:37:07 -0500 Subject: iterating over a list as if it were a circular list References: Message-ID: In article , Sven wrote: > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can > always assume that > > len(N) <= len(P) > > Now I would like to iterate over P and place one N at each point. However > if you run out of N I'd like to restart from N[0] and carry on until all > the points have been populated. > So far I've got > > for point in points: I'm not completely following what you're trying to do, but I think what you're looking for is some combination of zip() and itertools.cycle(). pairs = zip(P, cycle(N)) From news at blinne.net Thu Mar 7 18:49:04 2013 From: news at blinne.net (Alexander Blinne) Date: Fri, 08 Mar 2013 00:49:04 +0100 Subject: iterating over a list as if it were a circular list In-Reply-To: References: Message-ID: <51392771$0$6583$9b4e6d93@newsspool3.arcor-online.net> Am 07.03.2013 10:27, schrieb Sven: > Now I would like to iterate over P and place one N at each point. > However if you run out of N I'd like to restart from N[0] and carry on > until all the points have been populated. > So far I've got (pseudo code) > > i = 0 > for point in points: > put N[i] at point > if i > len(N): > i = 0 > > is this the most pythonic way to accomplish this? Sounds like http://docs.python.org/3/library/itertools.html#itertools.repeat to me. > Additionally, what if I wanted to pull a random element from N, but I > want to ensure all elements from N have been used before starting to > pick already chosen random elements again. > So far I thought of duplicating the list and removing the randomly > chosen elements from the list, and when it's empty, re-copying it. But > that seems a little "wrong" if you know what I mean. This can be done with http://docs.python.org/3/library/random.html#random.shuffle untested: import random def repeated_random_permutation(iterable): pool = list(iterable) while True: random.shuffle(pool) yield from pool Greetings From news at blinne.net Thu Mar 7 18:50:25 2013 From: news at blinne.net (Alexander Blinne) Date: Fri, 08 Mar 2013 00:50:25 +0100 Subject: iterating over a list as if it were a circular list In-Reply-To: <51392771$0$6583$9b4e6d93@newsspool3.arcor-online.net> References: <51392771$0$6583$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <513927c1$0$6583$9b4e6d93@newsspool3.arcor-online.net> Am 08.03.2013 00:49, schrieb Alexander Blinne: > http://docs.python.org/3/library/itertools.html#itertools.repeat obviously I was aiming for http://docs.python.org/2/library/itertools.html#itertools.cycle here.... Greetings From steve+comp.lang.python at pearwood.info Fri Mar 8 12:59:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2013 17:59:42 GMT Subject: iterating over a list as if it were a circular list References: Message-ID: <513a270d$0$30001$c3e8da3$5496439d@news.astraweb.com> On Thu, 07 Mar 2013 09:27:42 +0000, Sven wrote: > Additionally, what if I wanted to pull a random element from N, but I > want to ensure all elements from N have been used before starting to > pick already chosen random elements again. So far I thought of > duplicating the list and removing the randomly chosen elements from the > list, and when it's empty, re-copying it. But that seems a little > "wrong" if you know what I mean. An infinite generator is probably the best solution: import random def sample_without_replacement(alist): blist = alist[:] # Copy the list. while True: random.shuffle(blist) for value in blist: yield value Notice that I make a copy of the list before shuffling. That avoids side- effects where calling sample_without_replacement on a list modifies it. To use it, you do something like this: it = sample_without_replacement([1, 2, 3, 4, 5, 6]) next(it) => prints a random value next(it) => and a second random value To grab twenty random values all at once, you can either do this: it = sample_without_replacement([1, 2, 3, 4, 5, 6]) values = [next(it) for i in range(20)] or this: import itertools it = sample_without_replacement([1, 2, 3, 4, 5, 6]) values = itertools.islice(it, 20) -- Steven From sferencik at gmail.com Thu Mar 7 06:02:03 2013 From: sferencik at gmail.com (sferencik at gmail.com) Date: Thu, 7 Mar 2013 03:02:03 -0800 (PST) Subject: 3.3.1 release date? Message-ID: <9655cbb1-863c-4dc0-900f-8a47934b89ad@googlegroups.com> Hi, When is the 3.3.1 final due? I have found this [http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem up to date. Is there a better source of this info? Thanks, Sam From tjreedy at udel.edu Thu Mar 7 06:57:09 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 07 Mar 2013 06:57:09 -0500 Subject: 3.3.1 release date? In-Reply-To: <9655cbb1-863c-4dc0-900f-8a47934b89ad@googlegroups.com> References: <9655cbb1-863c-4dc0-900f-8a47934b89ad@googlegroups.com> Message-ID: On 3/7/2013 6:02 AM, sferencik at gmail.com wrote: > Hi, > > When is the 3.3.1 final due? I have found this > [http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem > up to date. Is there a better source of this info? No. There are lingering issues that were expected to be resolved already, but have not been. -- Terry Jan Reedy From sferencik at gmail.com Fri Mar 8 04:14:09 2013 From: sferencik at gmail.com (sferencik at gmail.com) Date: Fri, 8 Mar 2013 01:14:09 -0800 (PST) Subject: 3.3.1 release date? In-Reply-To: References: <9655cbb1-863c-4dc0-900f-8a47934b89ad@googlegroups.com> Message-ID: On Thursday, March 7, 2013 12:57:09 PM UTC+1, Terry Reedy wrote: > On 3/7/2013 6:02 AM, sferencik at gmail.com wrote: > > > Hi, > > > > > > When is the 3.3.1 final due? I have found this > > > [http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem > > > up to date. Is there a better source of this info? > > > > No. There are lingering issues that were expected to be resolved > > already, but have not been. > > > > -- > > Terry Jan Reedy Thanks, Terry. Do you have an idea if this is a matter of days or weeks or months? (I'm asking because the Release Schedule at python.org says 3.3.1 final is due on March 2. Is this indicative of it being really close now?) Thanks, Sam From sferencik at gmail.com Fri Mar 8 04:14:09 2013 From: sferencik at gmail.com (sferencik at gmail.com) Date: Fri, 8 Mar 2013 01:14:09 -0800 (PST) Subject: 3.3.1 release date? In-Reply-To: References: <9655cbb1-863c-4dc0-900f-8a47934b89ad@googlegroups.com> Message-ID: On Thursday, March 7, 2013 12:57:09 PM UTC+1, Terry Reedy wrote: > On 3/7/2013 6:02 AM, sferencik at gmail.com wrote: > > > Hi, > > > > > > When is the 3.3.1 final due? I have found this > > > [http://python.org/dev/peps/pep-0398/#id1], but the info doesn't seem > > > up to date. Is there a better source of this info? > > > > No. There are lingering issues that were expected to be resolved > > already, but have not been. > > > > -- > > Terry Jan Reedy Thanks, Terry. Do you have an idea if this is a matter of days or weeks or months? (I'm asking because the Release Schedule at python.org says 3.3.1 final is due on March 2. Is this indicative of it being really close now?) Thanks, Sam From jabba.laci at gmail.com Thu Mar 7 10:19:53 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 7 Mar 2013 16:19:53 +0100 Subject: Python source to C++ and/or Java Message-ID: Hi, As a university project, I would like to work on an automated converter that transforms a Python source code to C++ or Java (not yet decided but I would vote on Java since it seems less complicated). Do you know if it's already done? What other similar projects are you aware of? And most importantly: where could I start this project? Could you give some ideas/tips? The converter doesn't have to recognize everything. First we want to build a simple prototype. Thanks, Laszlo From alec.taylor6 at gmail.com Thu Mar 7 10:25:30 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 8 Mar 2013 02:25:30 +1100 Subject: Python source to C++ and/or Java In-Reply-To: References: Message-ID: Saw a talk at a Python usergroup today which talked about: Ply http://www.dabeaz.com/ply/ But you're probably looking for Cython. Python can run of the JRE e.g.: see Jython. There was also another one that you can use to build C extensions with, it was MP... something On Fri, Mar 8, 2013 at 2:19 AM, Jabba Laci wrote: > Hi, > > As a university project, I would like to work on an automated > converter that transforms a Python source code to C++ or Java (not yet > decided but I would vote on Java since it seems less complicated). > Do you know if it's already done? What other similar projects are you aware of? > > And most importantly: where could I start this project? Could you give > some ideas/tips? > > The converter doesn't have to recognize everything. First we want to > build a simple prototype. > > Thanks, > > Laszlo > -- > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Thu Mar 7 10:33:05 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Mar 2013 16:33:05 +0100 Subject: Python source to C++ and/or Java References: Message-ID: Jabba Laci wrote: > As a university project, I would like to work on an automated > converter that transforms a Python source code to C++ or Java (not yet > decided but I would vote on Java since it seems less complicated). > Do you know if it's already done? What other similar projects are you > aware of? https://pypi.python.org/pypi/Shed Skin/ """ An Optimizing (restricted) Python-to-C++ Compiler Shed Skin is an experimental (restricted) Python-to-C++ compiler. It accepts pure but implicitly statically typed Python (2.4-2.6) programs and generates optimized C++ code. [...] """ From tufancakiroglu at hotmail.com Thu Mar 7 11:15:51 2013 From: tufancakiroglu at hotmail.com (Tufan Cakiroglu) Date: Thu, 7 Mar 2013 08:15:51 -0800 (PST) Subject: Cloudicy.com - New Social Network Message-ID: Hi. I am owner of www.cloudicy.com Cloudicy.com is a new cloud dictionary and website. Its a kind of Social Network. Users can create topics on website and post informations, suggestions, comments and critiques for posts. I need users (for manage posts and testing) and PHP developers. Please contact with me Tufan ?ak?ro?lu tufancakiroglu at cloudicy.com www.cloudicy.com From rosuav at gmail.com Thu Mar 7 11:25:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 03:25:42 +1100 Subject: Cloudicy.com - New Social Network In-Reply-To: References: Message-ID: On Fri, Mar 8, 2013 at 3:15 AM, Tufan Cakiroglu wrote: > Hi. I am owner of www.cloudicy.com > > Cloudicy.com is a new cloud dictionary and website. Its a kind of Social Network. Users can create topics on website and post informations, suggestions, comments and critiques for posts. > > I need users (for manage posts and testing) and PHP developers. And this is applicable to Python... how? ChrisA From shiuanb at gmail.com Thu Mar 7 14:20:58 2013 From: shiuanb at gmail.com (Shiuan Butler) Date: Thu, 7 Mar 2013 11:20:58 -0800 (PST) Subject: April 5 conference on Python in Finance (NYC) Message-ID: <4a9d7e5e-6470-4a97-845f-7e713798fb55@googlegroups.com> As Python programmers, you may be interested in participating in an upcoming "Python in Finance" conference, an all-day event taking place in New York on the 5th of April (www.python-in-finance.com). The event brings together 300+ Python practitioners with a who's who line up of speakers from the world of Python and finance: Travis Oliphant (Numpy), Wes McKinney (Pandas), Andreas Kloeckner (PyCUDA and PyOpenCL), Peter Wang (Chaco) ... the list goes on. And I am very excited to announce that Claudia Perlich, Chief Scientist at m6d, will be giving the keynote address to kick off the event; Claudia's list of achievements include being a three-time winner of the KDD cup, and numerous and notable contributions in the Machine Learning, Data Mining and Predictive Modeling worlds. It's going to be an informative, exciting and fun day of great speakers mixed with practitioners of "Python in Finance". We have managed to get some great sponsors for the event to keep the attendance fee at a rock bottom rate of less than three hundred dollars; not bad for an all-day event in New York city with lunch thrown in! I have a special offer just for you; use the code "QUANT" at www.python-in-finance.com and save 25% off. The event is filling up fast so if you plan on coming, register soon; and be sure to let your friends and colleagues know about the event. Shiuan Butler www.python-in-finance.com From johnnyukpo at gmail.com Thu Mar 7 15:25:42 2013 From: johnnyukpo at gmail.com (johnnyukpo at gmail.com) Date: Thu, 7 Mar 2013 12:25:42 -0800 (PST) Subject: Need help deriving a convertion function on python Message-ID: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> Good day, I have a computer programming assignment. I am completely lost and i need some help. These are the questions that are confusing me (a) Write a function which converts from gallons to cups2 (b) Now we?d like to be able to convert from cups to milliliters, since metric measurements are easier to convert between. Implement a function which does this. (c) We?d also like to be able to easily convert gallons into milliliters, so implement a function which does this From rosuav at gmail.com Thu Mar 7 15:40:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Mar 2013 07:40:26 +1100 Subject: Need help deriving a convertion function on python In-Reply-To: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> References: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 7:25 AM, wrote: > Good day, > > I have a computer programming assignment. I am completely lost and i need some help. > > These are the questions that are confusing me > (a) Write a function which converts from gallons to cups2 > (b) Now we?d like to be able to convert from cups to milliliters, since metric measurements > are easier to convert between. Implement a function which does this. > (c) We?d also like to be able to easily convert gallons into milliliters, so implement a > function which does this Here's a good place to start: http://docs.python.org/3/tutorial/ After that, think about your task as three sub-tasks: 1) Get and parse input - what does your human need to tell your program? 2) Processing - the actual conversion, the meaty mathematical stuff 3) Produce output - what does your program report to your human? Then start work on any one of the three. If you get stuck, move on to one of the others. Once you've put some code together, test it, play with it, and refine it. And if you get stuck, THEN come and ask for help; but first, try to solve the problem yourself. The purpose of this assignment is to help you learn to write code, so we're not going to simply give you the code :) By the way, you may find the python-tutor list more suitable, if you feel your questions are particularly basic: http://mail.python.org/mailman/listinfo/tutor The Python tutorial really is a very good place to start. I'm seriously considering giving it to a ten-year-old girl, granting her just IDLE and a web browser, and seeing what she can accomplish in a day. ChrisA From davea at davea.name Thu Mar 7 19:07:43 2013 From: davea at davea.name (Dave Angel) Date: Thu, 07 Mar 2013 19:07:43 -0500 Subject: Need help deriving a convertion function on python In-Reply-To: References: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> Message-ID: <51392BCF.3010008@davea.name> On 03/07/2013 03:40 PM, Chris Angelico wrote: > On Fri, Mar 8, 2013 at 7:25 AM, wrote: >> Good day, >> >> I have a computer programming assignment. I am completely lost and i need some help. >> >> These are the questions that are confusing me > > By the way, you may > find the python-tutor list more suitable, if you feel your questions > are particularly basic: > http://mail.python.org/mailman/listinfo/tutor > Actually his brother 'akuma upko' (sharing the same account) posted the same question on Python-tutor 2 minutes before johnny posted it here. -- DaveA From rantingrickjohnson at gmail.com Thu Mar 7 17:15:27 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 7 Mar 2013 14:15:27 -0800 (PST) Subject: Need help deriving a convertion function on python In-Reply-To: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> References: <891bd56d-5821-4268-8fa2-ba54e3a08d22@googlegroups.com> Message-ID: <9c5a5287-6d8d-48c0-86a8-bebb935e2499@googlegroups.com> On Thursday, March 7, 2013 2:25:42 PM UTC-6, johnn... at gmail.com wrote: > I have a computer programming assignment. I am completely > lost and i need some help. These are the questions that > are confusing me > > (a) Write a function which converts from gallons to cups2 How can we help you if we have no idea of what level of programming experience you have attained. Can you write functions? Can you declare variables? What about mathematics? If you can already do all these things then make an attempt to accomplish problem "(a)" and then ask us a specific question when you run into trouble. > (b) Now we?d like to be able to convert from cups to > milliliters, since metric measurements are easier to > convert between. Implement a function which does this. > > (c) We?d also like to be able to easily convert gallons > into milliliters, so implement a function which does this In due time grasshopper. First make an attempt to solve problem "(a)". Chris gave some great advice however i would like to insert a "step 0" into his "advice list" (this is python after all ;-). * STEP 0: Learn how to convert from gallons to cups using a pencil and paper only. * STEP 1: Read docs and learn about functions (if applicable). * STEP 2: Try to write a python function that will take one parameter (representing the number of gallons) and then perform the mathematical equations required to deduce the number of cups in a gallon, THEN return the result. From subhabangalore at gmail.com Thu Mar 7 15:48:06 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Thu, 7 Mar 2013 12:48:06 -0800 (PST) Subject: Python and Hidden Markov Model Message-ID: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Dear Group, I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? Thanking you in Advance, Regards, Subhabrata. From davea at davea.name Thu Mar 7 19:12:06 2013 From: davea at davea.name (Dave Angel) Date: Thu, 07 Mar 2013 19:12:06 -0500 Subject: Python and Hidden Markov Model In-Reply-To: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> References: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Message-ID: <51392CD6.9080005@davea.name> On 03/07/2013 03:48 PM, subhabangalore at gmail.com wrote: > Dear Group, > > I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? > I'm sorry, but I'm having trouble figuring out what you're asking for. You said there are packages that could help, but that you want to learn more by doing it from scratch. So what then are you asking for, if not packages, sample code or something that's not "from scratch" ? -- DaveA From oscar.j.benjamin at gmail.com Thu Mar 7 19:55:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 8 Mar 2013 00:55:52 +0000 Subject: Python and Hidden Markov Model In-Reply-To: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> References: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Message-ID: On 7 March 2013 20:48, wrote: > Dear Group, > > I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? This question is not really appropriate on this list. Since this isn't the first time you've asked relatively specialist questions here, I'll suggest that you consider asking somewhere else in future. I would start by looking at lists that are dedicated to scientific programming. Whether you ask here or somewhere else you'll need to be clearer about what you actually want to do and why you are asking the list. Are you looking to run stochastic simulations? Or is your problem to do with model validation or inference of hidden state using data? Or something else? Are you thinking of discrete or continuous time Markov systems? Why are you currently unable to do whatever it is that you wanted to do? Oscar From subhabangalore at gmail.com Fri Mar 8 00:26:54 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Thu, 7 Mar 2013 21:26:54 -0800 (PST) Subject: Python and Hidden Markov Model In-Reply-To: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> References: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Message-ID: On Friday, March 8, 2013 2:18:06 AM UTC+5:30, subhaba... at gmail.com wrote: > Dear Group, > > > > I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? > > > > Thanking you in Advance, > > Regards, > > Subhabrata. Dear Sir, Thank you for your kind reply. I agree with most of your points but I differ slightly also. My problem is over model validation on continuous time Markov system. Generally, I understand the theory and can run the kits like HMM.py or Scikit-learn. The problem is if I can not fit the data in run time I would be at the mercy of the kit. So I wanted to know the coding of the computation. I am specifically looking at the small python example of Forward, Backward and Viterbi calculation. I tried to surf the web but did not help much. I do not know much of Scientific forum. I thought as HMM.py, NLTK, Scikit-learn are Python implementations so there would be lot of people in the room who would know it. And I got people like you, so I can not say I am wrong! Regards, Subhabrata. From oscar.j.benjamin at gmail.com Fri Mar 8 09:29:39 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 8 Mar 2013 14:29:39 +0000 Subject: Python and Hidden Markov Model In-Reply-To: References: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Message-ID: On 8 March 2013 05:26, wrote: > On Friday, March 8, 2013 2:18:06 AM UTC+5:30, subhaba... at gmail.com wrote: >> >> I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? > > My problem is over model validation on continuous time Markov system. > Generally, I understand the theory and can run the kits like HMM.py or Scikit-learn. > The problem is if I can not fit the data in run time I would be at the mercy of the kit. > So I wanted to know the coding of the computation. If those projects can do what you want then why not just look at their code? > I am specifically looking at the small python example of Forward, Backward and Viterbi > calculation. I tried to surf the web but did not help much. How about these two (both in Python): http://en.wikipedia.org/wiki/Viterbi_algorithm#Example http://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm#Python_example > I do not know much of Scientific forum. Try scipy-user as a start (someone there may know of a better mailing list): http://mail.scipy.org/mailman/listinfo/scipy-user > I thought as HMM.py, NLTK, Scikit-learn are Python implementations so there would be lot > of people in the room who would know it. > And I got people like you, so I can not say I am wrong! Python as a programming language is used for many different things. I doubt that many people on this list will know what a Hidden Markov Model is. While I do know what they are, I have never done anything with them in Python or otherwise. However, if you ask in the right place, I'm sure that you will find people who have done similar things in Python. Oscar From subhabangalore at gmail.com Fri Mar 8 12:53:02 2013 From: subhabangalore at gmail.com (Subhabrata) Date: Fri, 8 Mar 2013 09:53:02 -0800 (PST) Subject: Python and Hidden Markov Model References: <1c2a4627-4000-456a-9a5a-c61c3069b98f@googlegroups.com> Message-ID: <9b1001dc-0adb-4203-ad84-87d929e9b61f@l4g2000pbn.googlegroups.com> On Mar 8, 7:29?pm, Oscar Benjamin wrote: > On 8 March 2013 05:26, ? wrote: > > > On Friday, March 8, 2013 2:18:06 AM UTC+5:30, subhaba... at gmail.com wrote: > > >> I was trying to learn Hidden Markov Model. In Python there are various packages, but I was willing to do some basic calculation starting from the scratch so that I can learn the model very aptly. Do you know of any thing such? > > > My problem is over model validation on continuous time Markov system. > > Generally, I understand the theory and can run the kits like HMM.py or Scikit-learn. > > The problem is if I can not fit the data in run time I would be at the mercy of the kit. > > So I wanted to know the coding of the computation. > > If those projects can do what you want then why not just look at their code? > > > I am specifically looking at the small python example of Forward, Backward and Viterbi > > calculation. I tried to surf the web but did not help much. > > How about these two (both in Python):http://en.wikipedia.org/wiki/Viterbi_algorithm#Examplehttp://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm#Pytho... > > > I do not know much of Scientific forum. > > Try scipy-user as a start (someone there may know of a better mailing list):http://mail.scipy.org/mailman/listinfo/scipy-user > > > I thought as HMM.py, NLTK, Scikit-learn are Python implementations so there would be lot > > of people in the room who would know it. > > And I got people like you, so I can not say I am wrong! > > Python as a programming language is used for many different things. I > doubt that many people on this list will know what a Hidden Markov > Model is. While I do know what they are, I have never done anything > with them in Python or otherwise. However, if you ask in the right > place, I'm sure that you will find people who have done similar things > in Python. > > Oscar Thank you Sir for your kind time. I would surely check them. Regards, Subhabrata. From victor.stinner at gmail.com Thu Mar 7 16:29:14 2013 From: victor.stinner at gmail.com (Victor Stinner) Date: Thu, 7 Mar 2013 22:29:14 +0100 Subject: pytracemalloc 0.7: new tool to track memory leaks in Python Message-ID: Hi, Wyplay is proud to announce the release of a new tool to track Python memory allocations: "pytracemalloc". https://pypi.python.org/pypi/pytracemalloc https://github.com/wyplay/pytracemalloc pytracemalloc provides the following information: - Allocated size and number of allocations per file, or optionally per file and line number - Compute the average size of memory allocations - Compute delta between two "snapshots" - Get the source of a memory allocation: filename and line number It helps to track memory leaks: show directly in which Python files the memory increases. Example of pytracemalloc output (compact): 2013-02-28 23:40:18: Top 5 allocations per file #1: .../Lib/test/regrtest.py: 3998 KB #2: .../Lib/unittest/case.py: 2343 KB #3: .../ctypes/test/__init__.py: 513 KB #4: .../Lib/encodings/__init__.py: 525 KB #5: .../Lib/compiler/transformer.py: 438 KB other: 32119 KB Total allocated size: 39939 KB Example of pytracemalloc output (full): 2013-03-04 01:01:55: Top 10 allocations per file and line #1: .../2.7/Lib/linecache.py:128: size=408 KiB (+408 KiB), count=5379 (+5379), average=77 B #2: .../unittest/test/__init__.py:14: size=401 KiB (+401 KiB), count=6668 (+6668), average=61 B #3: .../2.7/Lib/doctest.py:506: size=319 KiB (+319 KiB), count=197 (+197), average=1 KiB #4: .../Lib/test/regrtest.py:918: size=429 KiB (+301 KiB), count=5806 (+3633), average=75 B #5: .../Lib/unittest/case.py:332: size=162 KiB (+136 KiB), count=452 (+380), average=367 B #6: .../Lib/test/test_doctest.py:8: size=105 KiB (+105 KiB), count=1125 (+1125), average=96 B #7: .../Lib/unittest/main.py:163: size=77 KiB (+77 KiB), count=1149 (+1149), average=69 B #8: .../Lib/test/test_types.py:7: size=75 KiB (+75 KiB), count=1644 (+1644), average=46 B #9: .../2.7/Lib/doctest.py:99: size=64 KiB (+64 KiB), count=1000 (+1000), average=66 B #10: .../Lib/test/test_exceptions.py:6: size=56 KiB (+56 KiB), count=932 (+932), average=61 B 3023 more: size=1580 KiB (+1138 KiB), count=12635 (+7801), average=128 B Total: size=3682 KiB (+3086 KiB), count=36987 (+29908), average=101 B To install pytracemalloc, you need to patch and recompile your own version of Python to be able to hook all Python memory allocations. -- Wyplay was created in March 2006 in the south of France. Independent, Europe-based, and internationally recognized, Wyplay?s TV-centric software solutions power the world?s most popular operator and consumer electronic brand names. Targeted products includes: Connected-HDTVs, Media Center CE devices, HD IPTV boxes, DVB-S/C/T HD STBs, and in-home media-HDD products. http://www.wyplay.com/ Victor From gerson.kurz at gmail.com Fri Mar 8 02:23:42 2013 From: gerson.kurz at gmail.com (gerson.kurz at gmail.com) Date: Thu, 7 Mar 2013 23:23:42 -0800 (PST) Subject: Linking with static libraries for Python standard components such as OpenSSL Message-ID: <84193dbe-3256-4815-b828-7ce7bd90d388@googlegroups.com> I am rebuilding Python 2.7.4 using Visual Studio 2010. As part of that, I wanted to build with a current OpenSSL version (1.0.1e) and an updated SQLite version. What I noted: the projects in the main workspace (at least in PCBuild) directly include the source code of dependent libraries. Can somebody please explain the rationale behind that? Wouldn't it be better to instead link with static libraries of these projects? Exhibit A: _ssl.pyd requires a Perl interpreter to build. (Perl! Anathema!) Instead, _ssl.pyd could very well link with the Win32 binaries for OpenSSL? Exhibit B: _bsddb.pyd includes a ton of files from Berkley DB, with their filenames. Alas, newer versions of Berkley DB have slightly changed filenames, so the project needs to be changed to adjust for a newer version of Berkley DB. From tjreedy at udel.edu Fri Mar 8 05:03:23 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 08 Mar 2013 05:03:23 -0500 Subject: Linking with static libraries for Python standard components such as OpenSSL In-Reply-To: <84193dbe-3256-4815-b828-7ce7bd90d388@googlegroups.com> References: <84193dbe-3256-4815-b828-7ce7bd90d388@googlegroups.com> Message-ID: On 3/8/2013 2:23 AM, gerson.kurz at gmail.com wrote: > I am rebuilding Python 2.7.4 using Visual Studio 2010. As part of > that, I wanted to build with a current OpenSSL version (1.0.1e) and > an updated SQLite version. > > What I noted: the projects in the main workspace (at least in > PCBuild) directly include the source code of dependent libraries. Can > somebody please explain the rationale behind that? > > Wouldn't it be better to instead link with static libraries of these > projects? > > Exhibit A: _ssl.pyd requires a Perl interpreter to build. (Perl! > Anathema!) Instead, _ssl.pyd could very well link with the Win32 > binaries for OpenSSL? If you can make that work, open an issue and submit a patch. I have not gotten perl, so I am not building ssl. > Exhibit B: _bsddb.pyd includes a ton of files from Berkley DB, with > their filenames. Alas, newer versions of Berkley DB have slightly > changed filenames, so the project needs to be changed to adjust for a > newer version of Berkley DB. The it would not work with older versions? This sort of constant hassle is why bsddb is not part of 3.x. -- Terry Jan Reedy From jitu.icfai at gmail.com Fri Mar 8 07:36:40 2013 From: jitu.icfai at gmail.com (jitendra gupta) Date: Fri, 8 Mar 2013 18:06:40 +0530 Subject: Unit test cases for Object intraction using mox/unittest Message-ID: Hi I need to write the unit test cases for similary kind of sitution. I need to write the unit test case for Foo.testCall. for both case true or false. I am unalbe to do that. kindly please help me on this. as function is not returning any thing. from google i got mox is good for this case. but i did not found any solution for this case ****************** Enter.py ******************** from run import RunComp def enter(): runC = RunComp("ComName", "~/pathToHome") """ This is based on some database condition we are passing name true or false """ foo = Foo(true) foo.testCall(runC) if __name__ == "__main__": enter() ************************************************** ***************** foo.py************************ Class Foo(): def __init__(self, found): self.found = found def testCall(self, SomeClassObject): if self.found: RunCompObject.call_run("codeRun -s " + self.found) else: RunCompObject.call_run("codeRun") ************************************************* ************** run.py ************************** from subprocess import call class RunComp(object): def __init__(self, com, home): self.comp = comp self.home = home def call_and_raise(*args, **kwargs): if call(*args, **kwargs): raise RuntimeError("LDF command failed!") def call_run(self, command): if self.comp: command = " ".join((command,myldfrc)) call(command, cwd=self.home) ************************************************* Thanks & Regards Jitu -------------- next part -------------- An HTML attachment was scrubbed... URL: From prquinn at gmail.com Fri Mar 8 09:04:33 2013 From: prquinn at gmail.com (prquinn at gmail.com) Date: Fri, 8 Mar 2013 06:04:33 -0800 (PST) Subject: Tkinter GUI Question-Infinite Loop Message-ID: <732589c8-7322-4b11-96dd-99808d40fc6f@googlegroups.com> Greetings, I'm trying to run a simple Tkinter program that opens a program when you click a button. The code is listed below. I use a command to call a program that then calls a fortran program. However, when I click on the button, it opens the program but the menu of the program i'm calling goes into an infinite loop......the offending code seems to be in the button1Click module. Any help is greatly appreciated. Thanks from Tkinter import * import os, sys from win32com.client import Dispatch xlApp=Dispatch('Excel.Application') _PSSBINPATH=r"C:\Program Files\PTI\PSSE32\PSSBIN" os.environ['PATH']=_PSSBINPATH+';'+os.environ['PATH'] sys.path.insert(0,_PSSBINPATH) import redirect; redirect.psse2py() import psspy class MyApp: def __init__(self, parent): self.myParent = parent ### (7) remember my parent, the root self.myContainer1 = Frame(parent) self.myContainer1.pack() self.button1 = Button(self.myContainer1) self.button1.configure(text="OK", background= "green") self.button1.pack(side=LEFT) self.button1.bind("", self.button1Click) ### (1) self.button2 = Button(self.myContainer1) self.button2.configure(text="Cancel", background="red") self.button2.pack(side=RIGHT) self.button2.bind("", self.button2Click) ### (2) def button1Click(self,event): ### (3) psspy.runiplanfile(r"C:\MNTACT\Contingency Program\work\contingency-31-4.irf") if self.button1["background"] == "green": ### (4) self.button1["background"] = "yellow" else: self.button1["background"] = "green" def button2Click(self, event): ### (5) self.myParent.destroy() ### (6) root = Tk() myapp = MyApp(root) root.mainloop() From python at mrabarnett.plus.com Fri Mar 8 11:12:14 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 08 Mar 2013 16:12:14 +0000 Subject: Tkinter GUI Question-Infinite Loop In-Reply-To: <732589c8-7322-4b11-96dd-99808d40fc6f@googlegroups.com> References: <732589c8-7322-4b11-96dd-99808d40fc6f@googlegroups.com> Message-ID: <513A0DDE.4060709@mrabarnett.plus.com> On 08/03/2013 14:04, prquinn at gmail.com wrote: > Greetings, > > I'm trying to run a simple Tkinter program that opens a program when > you click a button. The code is listed below. I use a command to > call a program that then calls a fortran program. However, when I > click on the button, it opens the program but the menu of the program > i'm calling goes into an infinite loop......the offending code seems > to be in the button1Click module. > > Any help is greatly appreciated. > You say "the menu *of the program i'm calling* goes into an infinite loop" (my emphasis), so perhaps the problem isn't in _your_ code. Try something simpler like this: import psspy psspy.runiplanfile(r"C:\MNTACT\Contingency Program\work\contingency-31-4.irf") Does the program you're calling still go into an infinite loop? From gabor.a.halasz at gmail.com Fri Mar 8 09:07:25 2013 From: gabor.a.halasz at gmail.com (gabor.a.halasz at gmail.com) Date: Fri, 8 Mar 2013 06:07:25 -0800 (PST) Subject: Missing logging output in Python Message-ID: Hi, I would like to enable loggin in my script using the logging module that comes with Python 2.7.3. I have the following few lines setting up logging in my script, but for whatever reason I don't seem to get any output to stdout or to a file provided to the basicConfig method. Any ideas? # cinfiguring logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)8s %(message)s', datefmt='%Y-%m-%d\t%H:%M:%s', filename=config["currentLoop"], filemode='a') # define a Handler that writes INFO messages to sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set format that is cleaber for console use formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) From matt at tplus1.com Tue Mar 12 07:33:40 2013 From: matt at tplus1.com (W. Matthew Wilson) Date: Tue, 12 Mar 2013 07:33:40 -0400 Subject: Missing logging output in Python In-Reply-To: References: Message-ID: I made that code into a program like this: ### BEGIN import logging def configure_logging(): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)8s %(message)s', datefmt='%Y-%m-%d\t%H:%M:%s', filename='/tmp/logfun.log', filemode='a') # define a Handler that writes INFO messages to sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set format that is cleaber for console use formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) if __name__ == '__main__': configure_logging() logging.debug('a') logging.info('b') logging.warn('c') logging.error('d') logging.critical('e') ### END and when I run the program, I get INFO and greater messages to stderr: $ python logfun.py root : INFO b root : WARNING c root : ERROR d root : CRITICAL e and I get this stuff in the log file: $ cat /tmp/logfun.log 2013-03-12 07:31:1363087862 root DEBUG a 2013-03-12 07:31:1363087862 root INFO b 2013-03-12 07:31:1363087862 root WARNING c 2013-03-12 07:31:1363087862 root ERROR d 2013-03-12 07:31:1363087862 root CRITICAL e In other words, your code works! Maybe you should check permissions on the file you are writing to. Matt On Fri, Mar 8, 2013 at 9:07 AM, wrote: > Hi, > > I would like to enable loggin in my script using the logging module that > comes with Python 2.7.3. > > I have the following few lines setting up logging in my script, but for > whatever reason I don't seem to get any output to stdout or to a file > provided to the basicConfig method. > > Any ideas? > > # cinfiguring logging > logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s > %(levelname)8s %(message)s', > datefmt='%Y-%m-%d\t%H:%M:%s', > filename=config["currentLoop"], filemode='a') > # define a Handler that writes INFO messages to sys.stderr > console = logging.StreamHandler() > console.setLevel(logging.INFO) > # set format that is cleaber for console use > formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') > # tell the handler to use this format > console.setFormatter(formatter) > # add the handler to the root logger > logging.getLogger('').addHandler(console) > -- > http://mail.python.org/mailman/listinfo/python-list > -- W. Matthew Wilson matt at tplus1.com http://tplus1.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From slc at publicus.net Fri Mar 8 09:29:48 2013 From: slc at publicus.net (Steven Clift) Date: Fri, 8 Mar 2013 08:29:48 -0600 Subject: Has anyone here checked out GroupServer lately? Message-ID: We are a user of this python-based GPL maillist/web forum platform: http://groupserver.org I'd be interested in folks thoughts about it. We'd like to see the development community grow. The main difference with Mailman is that it is more of a balance between web and e-mail, while still accessible via e-mail at the core. Steven Clift E-Democracy.org From sdeibel at wingware.com Fri Mar 8 11:36:15 2013 From: sdeibel at wingware.com (Stephan Deibel) Date: Fri, 08 Mar 2013 11:36:15 -0500 Subject: ANN: Wing IDE 4.1.12 released Message-ID: <513A137F.3000202@wingware.com> Hi, Wingware has released version 4.1.12 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: * Support for Python 2.6 and 2.7 running on cygwin * List SHA1 hashes on the downloads page * Show perspectives key bindings in Load Perspective sub-menu * Fix several color-related regressions * Fix extract refactoring when toplevel source is indented * Return focus to editor after refactoring operations * 6 other bug fixes and minor improvements For a complete change log see http://wingware.com/pub/wingide/4.1.12/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at sales at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com From nikos.gr33k at gmail.com Fri Mar 8 11:35:09 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 08:35:09 -0800 (PST) Subject: I cant understand this error when i click a link on my website Message-ID: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /home/nikos/public_html/cgi-bin/metrites.py in () 12 13 htmlpage = form.getvalue('htmlpage') 14 if re.search( r'(.html|.py)', htmlpage ): 15 htmlpage = htmlpage.replace( '/home/nikos/public_html/', '' ) 16 else: re = , re.search = , htmlpage = ['/home/nikos/public_html/index.html', 'pelatologio.py'] /usr/lib64/python2.6/re.py in search(pattern='(.html|.py)', string=['/home/nikos/public_html/index.html', 'pelatologio.py'], flags=0) 140 """Scan through string looking for a match to the pattern, returning 141 a match object, or None if no match was found.""" 142 return _compile(pattern, flags).search(string) 143 144 def sub(pattern, repl, string, count=0): global _compile = , pattern = '(.html|.py)', flags = 0, ).search undefined, string = ['/home/nikos/public_html/index.html', 'pelatologio.py'] : expected string or buffer args = ('expected string or buffer',) message = 'expected string or buffer' ============================== The code worksmy webpoage appear when i http://superhost.gr but whne i click a link on it for exmaple the 1st imaeg shown i get this error, and in evry link too. From rosuav at gmail.com Fri Mar 8 11:46:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 03:46:35 +1100 Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: On Sat, Mar 9, 2013 at 3:35 AM, ????? ???33? wrote: > 15 htmlpage = htmlpage.replace( '/home/nikos/public_html/', '' ) > re = , re.search = , htmlpage = ['/home/nikos/public_html/index.html', 'pelatologio.py'] > : expected string or buffer The regular expression functions expect a string (or a buffer), but you're passing it a list. Learning to read exception tracebacks is one of the important parts of becoming a competent programmer. ChrisA From nikos.gr33k at gmail.com Fri Mar 8 11:50:37 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 08:50:37 -0800 (PST) Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: ?? ?????????, 8 ??????? 2013 6:46:35 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Mar 9, 2013 at 3:35 AM, ????? ???33? wrote: > > > 15 htmlpage = htmlpage.replace( '/home/nikos/public_html/', '' ) > > > re = , re.search = , htmlpage = ['/home/nikos/public_html/index.html', 'pelatologio.py'] > > > : expected string or buffer > > > > The regular expression functions expect a string (or a buffer), but > > you're passing it a list. > > > > Learning to read exception tracebacks is one of the important parts of > > becoming a competent programmer. > > > > ChrisA but that same exact code is executed withour errors when someone is http://superhost.gr the erro is produces when he is requesting a link from that page... From nikos.gr33k at gmail.com Fri Mar 8 11:50:37 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 8 Mar 2013 08:50:37 -0800 (PST) Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: ?? ?????????, 8 ??????? 2013 6:46:35 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Mar 9, 2013 at 3:35 AM, ????? ???33? wrote: > > > 15 htmlpage = htmlpage.replace( '/home/nikos/public_html/', '' ) > > > re = , re.search = , htmlpage = ['/home/nikos/public_html/index.html', 'pelatologio.py'] > > > : expected string or buffer > > > > The regular expression functions expect a string (or a buffer), but > > you're passing it a list. > > > > Learning to read exception tracebacks is one of the important parts of > > becoming a competent programmer. > > > > ChrisA but that same exact code is executed withour errors when someone is http://superhost.gr the erro is produces when he is requesting a link from that page... From svenito at gmail.com Fri Mar 8 12:04:29 2013 From: svenito at gmail.com (Sven) Date: Fri, 8 Mar 2013 17:04:29 +0000 Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: On 8 March 2013 16:50, ????? ???33? wrote: > > > but that same exact code is executed withour errors when someone is > http://superhost.gr > > the erro is produces when he is requesting a link from that page... > -- > But with different arguments. It's http://superhost.gr/?htmlpage=files.py http://superhost.gr/ and the arguments to your regex are coming up as "string=['/home/nikos/public_html/index.html', 'files.py']" which is clearly a list of strings. In the case of http://superhost.gr/ it's probably just a single string -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Mar 8 12:24:40 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 08 Mar 2013 17:24:40 +0000 Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: <513A1ED8.9060901@mrabarnett.plus.com> On 08/03/2013 17:04, Sven wrote: > On 8 March 2013 16:50, ????? ???33? > wrote: > > > > but that same exact code is executed withour errors when someone is > http://superhost.gr > > the erro is produces when he is requesting a link from that page... > -- > > > But with different arguments. It's > http://superhost.gr/?htmlpage=files.py http://superhost.gr/ and the > arguments to your regex are coming up as > "string=['/home/nikos/public_html/index.html', 'files.py']" which is > clearly a list of strings. > In the case of http://superhost.gr/ it's probably just a single string > The documentation for getvalue says """If the submitted form data contains more than one field with the same name, the object retrieved by form[key] is not a FieldStorage or MiniFieldStorage instance but a list of such instances. Similarly, in this situation, form.getvalue(key) would return a list of strings.""" This suggests that the webpage may in fact have 2 fields with the name "htmlpage". From info at cravendot.gr Fri Mar 8 14:16:43 2013 From: info at cravendot.gr (info at cravendot.gr) Date: Fri, 8 Mar 2013 11:16:43 -0800 (PST) Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: <42390196-c6cd-42b2-95a1-f654b80c06df@googlegroups.com> ?? ?????????, 8 ??????? 2013 7:04:29 ?.?. UTC+2, ? ??????? sven ??????: > On 8 March 2013 16:50, ????? ???33? wrote: > > > > > > > > > but that same exact code is executed withour errors when someone is http://superhost.gr > > > > the erro is produces when he is requesting a link from that page... > > -- > > > > But with different arguments. It's http://superhost.gr/?htmlpage=files.py ?http://superhost.gr/ and the arguments to your regex are coming up as "string=['/home/nikos/public_html/index.html', 'files.py']" which is clearly a list of strings. > > In the case of?http://superhost.gr/ it's probably just a single string > > -- > ./Sven Thanks i have fixed the problem just now after 3 hours! From info at cravendot.gr Fri Mar 8 14:16:43 2013 From: info at cravendot.gr (info at cravendot.gr) Date: Fri, 8 Mar 2013 11:16:43 -0800 (PST) Subject: I cant understand this error when i click a link on my website In-Reply-To: References: Message-ID: <42390196-c6cd-42b2-95a1-f654b80c06df@googlegroups.com> ?? ?????????, 8 ??????? 2013 7:04:29 ?.?. UTC+2, ? ??????? sven ??????: > On 8 March 2013 16:50, ????? ???33? wrote: > > > > > > > > > but that same exact code is executed withour errors when someone is http://superhost.gr > > > > the erro is produces when he is requesting a link from that page... > > -- > > > > But with different arguments. It's http://superhost.gr/?htmlpage=files.py ?http://superhost.gr/ and the arguments to your regex are coming up as "string=['/home/nikos/public_html/index.html', 'files.py']" which is clearly a list of strings. > > In the case of?http://superhost.gr/ it's probably just a single string > > -- > ./Sven Thanks i have fixed the problem just now after 3 hours! From wolfgang.maier at biologie.uni-freiburg.de Fri Mar 8 11:45:03 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 8 Mar 2013 16:45:03 +0000 (UTC) Subject: itertools.filterfalse - what is it good for Message-ID: Dear all, can anybody point out a situation where you really need itertools.filterfalse() ? So far, I couldn't think of a case where you couldn't replace it with a generator expression/if combination. e.g., a=filterfalse(lambda x: x%2, range(1,101)) b=(i for i in range(1,101) if not i % 2) do not return the same object type, but otherwise are achieving the same thing. What am I missing here? For sure filterfalse exists for a reason? Best, Wolfgang From neilc at norwich.edu Fri Mar 8 12:02:55 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Mar 2013 17:02:55 GMT Subject: itertools.filterfalse - what is it good for References: Message-ID: On 2013-03-08, Wolfgang Maier wrote: > Dear all, > can anybody point out a situation where you really need > itertools.filterfalse() ? So far, I couldn't think of a case > where you couldn't replace it with a generator expression/if > combination. e.g., > > a=filterfalse(lambda x: x%2, range(1,101)) > b=(i for i in range(1,101) if not i % 2) > > do not return the same object type, but otherwise are achieving > the same thing. What am I missing here? For sure filterfalse > exists for a reason? It must exist for reasons of convenience and efficiency only. It can trivially be replaced by filter in all cases (at least in Python 3), but it saves you from a possibly slow extra function indirection, and also from needing to define one at all. -- Neil Cerutti From miki.tebeka at gmail.com Sat Mar 9 15:30:11 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 9 Mar 2013 12:30:11 -0800 (PST) Subject: itertools.filterfalse - what is it good for In-Reply-To: References: Message-ID: > can anybody point out a situation where you really need itertools.filterfalse() ? Sometimes you get the predicate as a parameter to another function. This way if you want to filter out things you can easily do it. Other language (such as Clojure) have a "complement" function that removes the need of filterfalse. For example (Python 3): def percent_spam(is_spam, documents): n_spam = sum(1 for _ in filter(is_spam, documents)) n_ham = sum(1 for _ in filterfalse(is_spam, documents)) return float(n_spam) / (n_ham + n_spam) From miki.tebeka at gmail.com Sat Mar 9 15:30:11 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 9 Mar 2013 12:30:11 -0800 (PST) Subject: itertools.filterfalse - what is it good for In-Reply-To: References: Message-ID: > can anybody point out a situation where you really need itertools.filterfalse() ? Sometimes you get the predicate as a parameter to another function. This way if you want to filter out things you can easily do it. Other language (such as Clojure) have a "complement" function that removes the need of filterfalse. For example (Python 3): def percent_spam(is_spam, documents): n_spam = sum(1 for _ in filter(is_spam, documents)) n_ham = sum(1 for _ in filterfalse(is_spam, documents)) return float(n_spam) / (n_ham + n_spam) From tjreedy at udel.edu Sat Mar 9 00:57:16 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Mar 2013 00:57:16 -0500 Subject: itertools.filterfalse - what is it good for In-Reply-To: References: Message-ID: On 3/8/2013 11:45 AM, Wolfgang Maier wrote: > Dear all, > can anybody point out a situation where you really need itertools.filterfalse() ? > So far, I couldn't think of a case where you couldn't replace it with a > generator expression/if combination. > e.g., > > a=filterfalse(lambda x: x%2, range(1,101)) > b=(i for i in range(1,101) if not i % 2) > > do not return the same object type, but otherwise are achieving the same thing. > What am I missing here? For sure filterfalse exists for a reason? I believe itertools existed before generator expressions. They are meant to work together. filterfalse is the complement of iterator filter on True, which was in itertools before it replaced the old built-in filter that return a list. All of the functional versions work best is you already have a function instead of defining one in place. The comprehension works best if one has just an expression and not a function. -- Terry Jan Reedy From roy at panix.com Fri Mar 8 13:41:27 2013 From: roy at panix.com (Roy Smith) Date: Fri, 08 Mar 2013 13:41:27 -0500 Subject: Why are timezone aware and naive datetimes not distinct classes? Message-ID: To make a long (and painful) story short, I've got a (large) list of datetimes, and was getting some bizarre errors working with it. One of the things I tried while debugging the problem was verifying that all the elements of the list were indeed datetimes: In [59]: set(type(foo) for foo in x) Out[59]: set([datetime.datetime]) Well, it turns out, one of them was a timezone-aware datetime, and all the others were naive! I finally figured it out when I tried max(x) and got TypeError: can't compare offset-naive and offset-aware datetimes So, the question is, WHY aren't aware and naive datetimes separate classes? They share many attributes and methods, but not all. It seems like they should both be subclasses of some common BaseDatetime. Was not splitting them into two classes a deliberate design decision? From nobody at nowhere.com Fri Mar 8 16:33:40 2013 From: nobody at nowhere.com (Nobody) Date: Fri, 08 Mar 2013 21:33:40 +0000 Subject: Why are timezone aware and naive datetimes not distinct classes? References: Message-ID: On Fri, 08 Mar 2013 13:41:27 -0500, Roy Smith wrote: > So, the question is, WHY aren't aware and naive datetimes separate > classes? They share many attributes and methods, but not all. They share all attributes and methods. You could just as well ask why positive and negative floats aren't separate classes (based upon the fact that e.g. math.sqrt() and math.log() raise domain errors for negative floats). Just because certain operations aren't defined for all values (or all combinations of values), that doesn't make the values where those operations aren't defined into a distinct type. From rosuav at gmail.com Fri Mar 8 17:01:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 09:01:17 +1100 Subject: Why are timezone aware and naive datetimes not distinct classes? In-Reply-To: References: Message-ID: On Sat, Mar 9, 2013 at 8:33 AM, Nobody wrote: > On Fri, 08 Mar 2013 13:41:27 -0500, Roy Smith wrote: > >> So, the question is, WHY aren't aware and naive datetimes separate >> classes? They share many attributes and methods, but not all. > > They share all attributes and methods. > > You could just as well ask why positive and negative floats aren't > separate classes (based upon the fact that e.g. math.sqrt() and math.log() > raise domain errors for negative floats). > > Just because certain operations aren't defined for all values (or all > combinations of values), that doesn't make the values where those > operations aren't defined into a distinct type. They represent different things, though. A naive datetime is kinda like an integer - an abstract thing that has meaning only as the programmer gives it meaning; an aware datetime unambiguously represents an instant in time. SQL has completely different data types for "TIMESTAMP WITHOUT TIME ZONE" and "TIMESTAMP WITH TIME ZONE". As I see it, a naive datetime simply does not have a timezone. The fact that it may have an attribute that's set to None doesn't mean that it "shares all attributes" with aware datetimes; if they were implemented completely separately (without even a common base class), the most obvious difference would be the complete absence of timezone attribute on the naive type. Conceptually, Roy's notion of a common base class makes good sense. But I can't speak for the Python datetime module as I've hardly used it; there may be practical considerations that mean the current model works better. All I can say is, there's definitely more difference between aware and naive datetimes than there is between positive and negative floats. ChrisA From nobody at nowhere.com Sat Mar 9 14:14:55 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 09 Mar 2013 19:14:55 +0000 Subject: Why are timezone aware and naive datetimes not distinct classes? References: Message-ID: On Sat, 09 Mar 2013 09:01:17 +1100, Chris Angelico wrote: > As I see it, a naive datetime simply does not have a timezone. The distinction between aware and naive isn't whether the .tzinfo member is None, but whether self.utcoffset() returns None (which can occur either if self.tzinfo is None or if self.tzinfo.utcoffset(self) returns None). IOW, an "aware" time/datetime can be converted to a UTC time/datetime, a "naive" one can't, although it can still have a timezone which isn't referenced to UTC. The distinction may actually matter for times in the far future, as you can't reliably predict how or when timezone defintions will change. Converting a future datetime to UTC based upon the current timezone rules is at best an estimate. For this reason, "appointments" should always be kept in local time, so that you don't get errors if the timezone rules (or the timezone) change between the time an appointment is made and the time it occurs. From roy at panix.com Sat Mar 9 14:40:14 2013 From: roy at panix.com (Roy Smith) Date: Sat, 09 Mar 2013 14:40:14 -0500 Subject: Why are timezone aware and naive datetimes not distinct classes? References: Message-ID: In article , Nobody wrote: > The distinction may actually matter for times in the far future, as you > can't reliably predict how or when timezone defintions will change. Sadly, this is true. > For this reason, "appointments" should always be > kept in local time, so that you don't get errors if the timezone rules > (or the timezone) change between the time an appointment is made and the > time it occurs. Well, sort of. Future scheduled activities (which I assume is what you mean by "appointments") should be kept in whatever timezone makes sense for that activity. For example, I'm on NASA's mailing list to receive alerts when the ISS is going to be visible to the naked eye at my location. The last one said: > Time: Wed Feb 27 6:17 PM, Visible: 4 min, Max Height: 54 degrees, > Appears: W, Disappears: SE If I wanted to put that on my calendar, I really should convert it to UTC and record it that way. If the folks who mess with these things were to suddenly decide to move when DST starts, the space station isn't going to adjust its orbit to accommodate that. Likewise, let's say I make an appointment to have a phone call with somebody in Caliornia (I'm in New York) at some future date. I put on my calendar "Call with Joe, 5 PM". Joe puts on his, "Call with Roy, 2 PM". The idiots in Albany and/or Sacramento decide to mess with the timezones and one state changes the rules. We're going to miss our phone call. Had we both recorded the arranged time in UTC, we'd get to talk to each other. From nobody at nowhere.com Sat Mar 9 18:38:37 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 09 Mar 2013 23:38:37 +0000 Subject: Why are timezone aware and naive datetimes not distinct classes? References: Message-ID: On Sat, 09 Mar 2013 14:40:14 -0500, Roy Smith wrote: > Future scheduled activities (which I assume is what you > mean by "appointments") should be kept in whatever timezone makes sense > for that activity. For example, I'm on NASA's mailing list to receive > alerts when the ISS is going to be visible to the naked eye at my > location. The last one said: > >> Time: Wed Feb 27 6:17 PM, Visible: 4 min, Max Height: 54 degrees, >> Appears: W, Disappears: SE > > If I wanted to put that on my calendar, I really should convert it to > UTC and record it that way. Indeed; that is an appropriate use of UTC. > Likewise, let's say I make an appointment to have a phone call with > somebody in Caliornia (I'm in New York) at some future date. I put on > my calendar "Call with Joe, 5 PM". Joe puts on his, "Call with Roy, 2 > PM". The idiots in Albany and/or Sacramento decide to mess with the > timezones and one state changes the rules. We're going to miss our > phone call. Had we both recorded the arranged time in UTC, we'd get to > talk to each other. Maybe. But if the time was chosen so as not to conflict with other activites, changes to timezone(s) will often result in corresponding changes to schedules, meaning that one or both parties will no longer be available at the original UTC time (or even at any time, if both have busy schedules). Which is why "future scheduled activities" which require multiple people to physically meet at a specific place and time are normally scheduled in terms of "the /de jure/ timezone of that location, as applicable on that date", rather than in UTC or even a named timezone. Similarly, the policies of a corporation which operates in multiple timezones within a single country may dictate times which are common (in HH:MM terms) to all locations but which are interpreted according to each location's /de jure/ timezone (e.g. fast food chains' "breakfast" menus). From rosuav at gmail.com Sat Mar 9 17:28:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Mar 2013 09:28:32 +1100 Subject: Why are timezone aware and naive datetimes not distinct classes? In-Reply-To: References: Message-ID: On Sun, Mar 10, 2013 at 6:14 AM, Nobody wrote: > On Sat, 09 Mar 2013 09:01:17 +1100, Chris Angelico wrote: > >> As I see it, a naive datetime simply does not have a timezone. > > The distinction between aware and naive isn't whether the .tzinfo member > is None, but whether self.utcoffset() returns None (which can occur either > if self.tzinfo is None or if self.tzinfo.utcoffset(self) returns None). > > IOW, an "aware" time/datetime can be converted to a UTC time/datetime, a > "naive" one can't, although it can still have a timezone which isn't > referenced to UTC. I stand corrected. Though the distinction I made in my first paragraph is still valid: an aware datetime represents an instant in time, a naive one is a tagged piece of arbitrary data. On Sun, Mar 10, 2013 at 6:40 AM, Roy Smith wrote: > Future scheduled activities (which I assume is what you > mean by "appointments") should be kept in whatever timezone makes sense > for that activity. Agreed; and in some specific circumstances, it's even possible to fight the whole mess of timezones. My online Dungeons and Dragons group schedules everything on UTC - for example, the server quotes the current time as Sat 22:26, and I have a session at Sun 02:00, so anyone can figure out how long until session without worrying about timezones or Daylight Robbery Time. Of course, that _does_ come at a cost; mainly it's the USA-based players who get confused (which surprises me somewhat, tbh). ChrisA From awilliam at whitemice.org Mon Mar 11 13:27:11 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Mon, 11 Mar 2013 13:27:11 -0400 Subject: Why are timezone aware and naive datetimes not distinct classes? In-Reply-To: References: Message-ID: <1363022831.5160.19.camel@localhost> On Fri, 2013-03-08 at 13:41 -0500, Roy Smith wrote: > To make a long (and painful) story short, I've got a (large) list of > datetimes, and was getting some bizarre errors working with it. One of > the things I tried while debugging the problem was verifying that all > the elements of the list were indeed datetimes: > In [59]: set(type(foo) for foo in x) > Out[59]: set([datetime.datetime] Because date/time management in Python is *@*&@R&*(R *@&Y terrible! Period, full-stop, awful, crappy, lousy, and aggravating. The design is haphazard and error inducing. Pass through the list once and convert them all the UTC [or I suppose, make them all naive]. BTW, this page is a life and sanity saver: And one of my own tricks is posted here: > Well, it turns out, one of them was a timezone-aware datetime, and all > the others were naive! I finally figured it out when I tried Welcome! -- Adam Tauno Williams GPG D95ED383 Systems Administrator, Python Developer, LPI / NCLA From djc at kangoo.invalid Mon Mar 11 16:32:15 2013 From: djc at kangoo.invalid (djc) Date: Mon, 11 Mar 2013 20:32:15 +0000 Subject: Why are timezone aware and naive datetimes not distinct classes? In-Reply-To: References: Message-ID: On 11/03/13 17:27, Adam Tauno Williams wrote: > Because date/time management in Python is *@*&@R&*(R *@&Y terrible! > Period, full-stop, awful, crappy, lousy, and aggravating. The design is > haphazard and error inducing. +1 -- djc From khudo.anastasia at gmail.com Fri Mar 8 14:01:04 2013 From: khudo.anastasia at gmail.com (khudo.anastasia at gmail.com) Date: Fri, 8 Mar 2013 11:01:04 -0800 (PST) Subject: crypto program in python. Message-ID: Hi every every body, Today I have to submit my assignment for Computer Science, And I am absolutely stuck in writing the code. Please help me in soon possible. The main idea of the program is encode and decode the text. that wot the instructor gave us so far. Sample Run Here's a sample run of the basic program in action. SECRET DECODER MENU 0) Quit 1) Encode 2) Decode What do you want to do? 1 text to be encoded: python rocks AQULEWKEMNJ SECRET DECODER MENU 0) Quit 1) Encode 2) Decode What do you want to do? 2 code to be decyphered: AQULEWKEMNJ PYTHONROCKS SECRET DECODER MENU 0) Quit 1) Encode 2) Decode What do you want to do? 0 Thanks for doing secret spy stuff with me. ----------------------------------- and alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "XPMGTDHLYONZBWEARKJUFSCIQV" def main(): keepGoing = True while keepGoing: response = menu() if response == "1": plain = raw_input("text to be encoded: ") print encode(plain) elif response == "2": coded = raw_input("code to be decyphered: ") print decode(coded) elif response == "0": print "Thanks for doing secret spy stuff with me." keepGoing = False else: print "I don't know what you want to do..." ------------------- I am confused about menu and the str function if you can help me with this code it will be awesome thank you!!! From neilc at norwich.edu Fri Mar 8 14:07:55 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Mar 2013 19:07:55 GMT Subject: crypto program in python. References: Message-ID: On 2013-03-08, khudo.anastasia at gmail.com wrote: > Hi every every body, > Today I have to submit my assignment for Computer Science, And > I am absolutely stuck in writing the code. Please help me in > soon possible. > > The main idea of the program is encode and decode the text. > that wot the instructor gave us so far. > > Sample Run > > Here's a sample run of the basic program in action. > > SECRET DECODER MENU > > 0) Quit > 1) Encode > 2) Decode > > What do you want to do? 1 > text to be encoded: python rocks > AQULEWKEMNJ > > > SECRET DECODER MENU > > 0) Quit > 1) Encode > 2) Decode > > What do you want to do? 2 > code to be decyphered: AQULEWKEMNJ > PYTHONROCKS > > > SECRET DECODER MENU > > 0) Quit > 1) Encode > 2) Decode > > What do you want to do? 0 > Thanks for doing secret spy stuff with me. > ----------------------------------- > and > > > alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > key = "XPMGTDHLYONZBWEARKJUFSCIQV" > > def main(): > keepGoing = True > while keepGoing: > response = menu() > if response == "1": > plain = raw_input("text to be encoded: ") > print encode(plain) > elif response == "2": > coded = raw_input("code to be decyphered: ") > print decode(coded) > elif response == "0": > print "Thanks for doing secret spy stuff with me." > keepGoing = False > else: > print "I don't know what you want to do..." > > ------------------- > > I am confused about menu and the str function if you can help > me with this code it will be awesome thank you!!! I believe your instructor intends you to start with the skeleton of the program provided above. Complete it by writing the missing functions: menu, decode, and encode. -- Neil Cerutti From khudo.anastasia at gmail.com Fri Mar 8 14:12:35 2013 From: khudo.anastasia at gmail.com (khudo.anastasia at gmail.com) Date: Fri, 8 Mar 2013 11:12:35 -0800 (PST) Subject: crypto program in python. In-Reply-To: References: Message-ID: <79311e2f-37a4-4050-b9fa-d0084c092c5f@googlegroups.com> On Friday, March 8, 2013 2:07:55 PM UTC-5, Neil Cerutti wrote: > On 2013-03-08, khudo.anastasia at gmail.com wrote: > > > Hi every every body, > > > Today I have to submit my assignment for Computer Science, And > > > I am absolutely stuck in writing the code. Please help me in > > > soon possible. > > > > > > The main idea of the program is encode and decode the text. > > > that wot the instructor gave us so far. > > > > > > Sample Run > > > > > > Here's a sample run of the basic program in action. > > > > > > SECRET DECODER MENU > > > > > > 0) Quit > > > 1) Encode > > > 2) Decode > > > > > > What do you want to do? 1 > > > text to be encoded: python rocks > > > AQULEWKEMNJ > > > > > > > > > SECRET DECODER MENU > > > > > > 0) Quit > > > 1) Encode > > > 2) Decode > > > > > > What do you want to do? 2 > > > code to be decyphered: AQULEWKEMNJ > > > PYTHONROCKS > > > > > > > > > SECRET DECODER MENU > > > > > > 0) Quit > > > 1) Encode > > > 2) Decode > > > > > > What do you want to do? 0 > > > Thanks for doing secret spy stuff with me. > > > ----------------------------------- > > > and > > > > > > > > > alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > > > key = "XPMGTDHLYONZBWEARKJUFSCIQV" > > > > > > def main(): > > > keepGoing = True > > > while keepGoing: > > > response = menu() > > > if response == "1": > > > plain = raw_input("text to be encoded: ") > > > print encode(plain) > > > elif response == "2": > > > coded = raw_input("code to be decyphered: ") > > > print decode(coded) > > > elif response == "0": > > > print "Thanks for doing secret spy stuff with me." > > > keepGoing = False > > > else: > > > print "I don't know what you want to do..." > > > > > > ------------------- > > > > > > I am confused about menu and the str function if you can help > > > me with this code it will be awesome thank you!!! > > > > I believe your instructor intends you to start with the skeleton > > of the program provided above. Complete it by writing the missing > > functions: menu, decode, and encode. > > > > -- > > Neil Cerutti that is where I confused, I am not sure how to do it, I started but nothing works. And the tutorials at the internet not helpful. If you could write me the code for the decode function, that would be awesome, and other i can do by myself. thanks From neilc at norwich.edu Fri Mar 8 14:32:24 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 8 Mar 2013 19:32:24 GMT Subject: crypto program in python. References: <79311e2f-37a4-4050-b9fa-d0084c092c5f@googlegroups.com> Message-ID: On 2013-03-08, khudo.anastasia at gmail.com wrote: >> I believe your instructor intends you to start with the >> skeleton of the program provided above. Complete it by writing >> the missing functions: menu, decode, and encode. > > that is where I confused, I am not sure how to do it, I started > but nothing works. And the tutorials at the internet not > helpful. If you could write me the code for the decode > function, that would be awesome, and other i can do by myself. Thanks for being honest. But I cannot agree to write any code for you. Can you post an example of something you tried that didn't work? -- Neil Cerutti From khudo.anastasia at gmail.com Fri Mar 8 14:35:33 2013 From: khudo.anastasia at gmail.com (khudo.anastasia at gmail.com) Date: Fri, 8 Mar 2013 11:35:33 -0800 (PST) Subject: crypto program in python. In-Reply-To: References: <79311e2f-37a4-4050-b9fa-d0084c092c5f@googlegroups.com> Message-ID: On Friday, March 8, 2013 2:32:24 PM UTC-5, Neil Cerutti wrote: > On 2013-03-08, khudo.anastasia at gmail.com > > wrote: > > >> I believe your instructor intends you to start with the > > >> skeleton of the program provided above. Complete it by writing > > >> the missing functions: menu, decode, and encode. > > > > > > that is where I confused, I am not sure how to do it, I started > > > but nothing works. And the tutorials at the internet not > > > helpful. If you could write me the code for the decode > > > function, that would be awesome, and other i can do by myself. > > > > Thanks for being honest. But I cannot agree to write any code for > > you. > > > > Can you post an example of something you tried that didn't work? > > > > -- > > Neil Cerutti print (' SECRET DECODER MENU') print (' 1) Encode') print (' 2) Decode') print (' 3) Quit') response = raw_input (" What do you want to do? ") print response import alpha def menu(): while response is "1" or "2" or "3": if response not in ('1', '2', '3'): print ("I don't know what you want to do...") continue From joel.goldstick at gmail.com Fri Mar 8 14:40:38 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 8 Mar 2013 14:40:38 -0500 Subject: crypto program in python. In-Reply-To: References: <79311e2f-37a4-4050-b9fa-d0084c092c5f@googlegroups.com> Message-ID: On Fri, Mar 8, 2013 at 2:32 PM, Neil Cerutti wrote: > On 2013-03-08, khudo.anastasia at gmail.com > wrote: > >> I believe your instructor intends you to start with the > >> skeleton of the program provided above. Complete it by writing > >> the missing functions: menu, decode, and encode. > > > > that is where I confused, I am not sure how to do it, I started > > but nothing works. And the tutorials at the internet not > > helpful. If you could write me the code for the decode > > function, that would be awesome, and other i can do by myself. > > Thanks for being honest. But I cannot agree to write any code for > you. > > Can you post an example of something you tried that didn't work? > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list > First, think about how to do this without writing code. alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "XPMGTDHLYONZBWEARKJUFSCIQV" The example shows "python rocks" being turned into AQULEWKEMNJ Do you see from the two strings how that works? If you can see that, write a description of how you encode a message. Bring that back with some code that does the same and you will get help -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip at pobox.com Fri Mar 8 15:28:30 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Mar 2013 14:28:30 -0600 Subject: itertools doc example "consume" Message-ID: I've never really used itertools before. While trying to figure out how to break a list up into equal pieces, I came across the consume function in the examples here: http://docs.python.org/2/library/itertools.html It seems to me that it should return whatever it consumes from the list. I thought you would call it like this: for chunk in consume(range(30), 5): print chunk and see it print something like [0, 1, 2, 3, 4] [5, 6, 7, 8, 9] ... [25, 26, 27, 28, 29] If I call it like this: lst = range(30) consume(lst, 5) it doesn't actually consume anything from lst. Am I missing something, or is that example missing a return or yield statement? Thanks, Skip From ian.g.kelly at gmail.com Fri Mar 8 15:41:12 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Mar 2013 13:41:12 -0700 Subject: itertools doc example "consume" In-Reply-To: References: Message-ID: On Fri, Mar 8, 2013 at 1:28 PM, Skip Montanaro wrote: > I've never really used itertools before. While trying to figure out > how to break a list up into equal pieces, I came across the consume > function in the examples here: > > http://docs.python.org/2/library/itertools.html > > It seems to me that it should return whatever it consumes from the > list. I thought you would call it like this: > > for chunk in consume(range(30), 5): > print chunk > > and see it print something like > > [0, 1, 2, 3, 4] > [5, 6, 7, 8, 9] > ... > [25, 26, 27, 28, 29] That's what the 'grouper' recipe does. The 'consume' recipe is just for removing unwanted things from the front of an iterator. > If I call it like this: > > lst = range(30) > consume(lst, 5) > > it doesn't actually consume anything from lst. Am I missing > something, or is that example missing a return or yield statement? Depending on your Python version lst is either a range object or a list, neither of which is an iterator. If you pass to consume an iterable object that is not an iterator, it will implicitly obtain an iterator for it, consume from the iterator, and then discard the iterator, with no effect on the original object. In general the itertools functions will work equally well on iterators and other iterables, but consume is special in that what it does is only relevant to iterators. From skip at pobox.com Fri Mar 8 16:43:21 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Mar 2013 21:43:21 +0000 (UTC) Subject: itertools doc example "consume" References: Message-ID: Ian Kelly gmail.com> writes: > Depending on your Python version lst is either a range object or a > list, neither of which is an iterator. If you pass to consume an > iterable object that is not an iterator, it will implicitly obtain an > iterator for it, consume from the iterator, and then discard the > iterator, with no effect on the original object. > > In general the itertools functions will work equally well on iterators > and other iterables, but consume is special in that what it does is > only relevant to iterators. Thanks for the explanation. I clearly still need to grapple with this stuff a bit... Skip From rpdooling at gmail.com Fri Mar 8 16:07:59 2013 From: rpdooling at gmail.com (Rick Dooling) Date: Fri, 8 Mar 2013 13:07:59 -0800 (PST) Subject: Any other screenwriters? Message-ID: Hello all, I am an amateur Python person, and I usually learn just enough to make one writing tool or another as I go, because mainly I'm a writer, not a programmer. Recently, I've been exploring a markdown syntax called Fountain for screenwriters http://fountain.io/syntax https://github.com/nyousefi/Fountain There are several apps that purportedly will allow screenwriters to convert plain text files to PDFs that follow screenwriting format. They cannot replace the $250 programs we use once production begins, but they are good enough for working drafts until production begins. However, most of these programs are "apps" with closed GUIs, and of course I'm looking for a way to do the same thing with Python and call it from the command-line or from within Vim To that end, I would like to take this Ruby script (which works pretty well, but throws errors in Mac OS X; some Ruby ones and some Prince ones) and convert it to Python so I can fix it myself, because I don't know Ruby at all, and would rather work in Python. https://github.com/olivertaylor/Textplay Any pointers? Thanks a bunch, Rick Dooling From rosuav at gmail.com Fri Mar 8 16:51:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 08:51:44 +1100 Subject: Any other screenwriters? In-Reply-To: References: Message-ID: On Sat, Mar 9, 2013 at 8:07 AM, Rick Dooling wrote: > To that end, I would like to take this Ruby script (which works pretty well, but throws errors in Mac OS X; some Ruby ones and some Prince ones) and convert it to Python so I can fix it myself, because I don't know Ruby at all, and would rather work in Python. > > https://github.com/olivertaylor/Textplay Hmm. You're looking at a fairly detailed markup language, and a potentially buggy third-party implementation of it. Are you able to go from the https://github.com/nyousefi/Fountain code instead? Given that you don't know Ruby at all, you'd be no worse off there, and it seems to be the "reference implementation". Porting either version to Python is going to be a big job, unfortunately. However, given that the reference implementation seems to have been written for a Mac, you have a reasonable chance of being able to execute the code, run the tests, and play with it, while you develop your own version. That's a *huge* help in porting - you can implement piece by piece, comparing in detail both the code and the output of each subsection. Alternatively, can you get the xcode version to run directly? (I'm not a Mac person and have no idea whether this is at all possible.) Can you call on it, in some way, and thus write just a wrapper around the outside? Might be a smaller job. Ultimately, you're working with a markup format. That means it's all text in, fiddle fiddle, text out... a workflow that Python's pretty good at handling. But you may be letting yourself in for a fairly big job :) ChrisA From richarddooling at gmail.com Fri Mar 8 17:42:18 2013 From: richarddooling at gmail.com (richarddooling at gmail.com) Date: Fri, 8 Mar 2013 14:42:18 -0800 (PST) Subject: Any other screenwriters? In-Reply-To: References: Message-ID: <81d3d055-c81c-4c89-aae7-b2afba44e71b@googlegroups.com> Thank you, Chris. I was trying to avoid the xcode since I know didley about that too, but I'll download it and see if I can get it to run. THANKS AGAIN Rick On Friday, March 8, 2013 3:51:44 PM UTC-6, Chris Angelico wrote: > On Sat, Mar 9, 2013 at 8:07 AM, Rick Dooling wrote: > > > To that end, I would like to take this Ruby script (which works pretty well, but throws errors in Mac OS X; some Ruby ones and some Prince ones) and convert it to Python so I can fix it myself, because I don't know Ruby at all, and would rather work in Python. > > > > > > https://github.com/olivertaylor/Textplay > > > > Hmm. You're looking at a fairly detailed markup language, and a > > potentially buggy third-party implementation of it. Are you able to go > > from the https://github.com/nyousefi/Fountain code instead? Given that > > you don't know Ruby at all, you'd be no worse off there, and it seems > > to be the "reference implementation". > > > > Porting either version to Python is going to be a big job, > > unfortunately. However, given that the reference implementation seems > > to have been written for a Mac, you have a reasonable chance of being > > able to execute the code, run the tests, and play with it, while you > > develop your own version. That's a *huge* help in porting - you can > > implement piece by piece, comparing in detail both the code and the > > output of each subsection. > > > > Alternatively, can you get the xcode version to run directly? (I'm not > > a Mac person and have no idea whether this is at all possible.) Can > > you call on it, in some way, and thus write just a wrapper around the > > outside? Might be a smaller job. > > > > Ultimately, you're working with a markup format. That means it's all > > text in, fiddle fiddle, text out... a workflow that Python's pretty > > good at handling. But you may be letting yourself in for a fairly big > > job :) > > > > ChrisA From richarddooling at gmail.com Fri Mar 8 17:42:18 2013 From: richarddooling at gmail.com (richarddooling at gmail.com) Date: Fri, 8 Mar 2013 14:42:18 -0800 (PST) Subject: Any other screenwriters? In-Reply-To: References: Message-ID: <81d3d055-c81c-4c89-aae7-b2afba44e71b@googlegroups.com> Thank you, Chris. I was trying to avoid the xcode since I know didley about that too, but I'll download it and see if I can get it to run. THANKS AGAIN Rick On Friday, March 8, 2013 3:51:44 PM UTC-6, Chris Angelico wrote: > On Sat, Mar 9, 2013 at 8:07 AM, Rick Dooling wrote: > > > To that end, I would like to take this Ruby script (which works pretty well, but throws errors in Mac OS X; some Ruby ones and some Prince ones) and convert it to Python so I can fix it myself, because I don't know Ruby at all, and would rather work in Python. > > > > > > https://github.com/olivertaylor/Textplay > > > > Hmm. You're looking at a fairly detailed markup language, and a > > potentially buggy third-party implementation of it. Are you able to go > > from the https://github.com/nyousefi/Fountain code instead? Given that > > you don't know Ruby at all, you'd be no worse off there, and it seems > > to be the "reference implementation". > > > > Porting either version to Python is going to be a big job, > > unfortunately. However, given that the reference implementation seems > > to have been written for a Mac, you have a reasonable chance of being > > able to execute the code, run the tests, and play with it, while you > > develop your own version. That's a *huge* help in porting - you can > > implement piece by piece, comparing in detail both the code and the > > output of each subsection. > > > > Alternatively, can you get the xcode version to run directly? (I'm not > > a Mac person and have no idea whether this is at all possible.) Can > > you call on it, in some way, and thus write just a wrapper around the > > outside? Might be a smaller job. > > > > Ultimately, you're working with a markup format. That means it's all > > text in, fiddle fiddle, text out... a workflow that Python's pretty > > good at handling. But you may be letting yourself in for a fairly big > > job :) > > > > ChrisA From rantingrickjohnson at gmail.com Fri Mar 8 22:41:57 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 8 Mar 2013 19:41:57 -0800 (PST) Subject: Any other screenwriters? In-Reply-To: References: Message-ID: <8aa5c3d0-a008-4423-b2c2-0e70b442a256@googlegroups.com> On Friday, March 8, 2013 3:07:59 PM UTC-6, Rick Dooling wrote: > I am an amateur Python person, and I usually learn just > enough to make one writing tool or another as I go, > because mainly I'm a writer, not a programmer. Recently, > I've been exploring a markdown syntax called Fountain for > screenwriters First impression of Fountain: TOTAL CRAP! I surly hope this "Fountain" markup is a joke and people are not actually using it to write anything. Fountain's feeble attempts to solve the "plain text" markup problem are an abomination at best, and an insidious evil at worse! ============================================================ Problem 1 ============================================================ Take for example their redefining of the simple and ubiquitous "emphasis markups" of: /italic/ *bold* */bold italic/* _underline_ To this crap: *italics* **bold** ***bold italics*** _underline_ ...are they joking? ============================================================ Problem 2 ============================================================ Their "dual dialog" structure is another folly. "Dual dialog" is so rare that it /hardly/ requires a unique syntactical element. Consider the Fountain solution via this small short story: ACTOR_1 Hey, check out that hot chick over there! ACTOR_2 Where? (ACTOR_1 slaps ACTOR_2 on the head and points) ACTOR_1 Over there you idiot! (feeling a bit hot from all the walking, hot chick opens the top two buttons on her blouse to allow some fresh air in; revealing her ample cleavage) ACTOR_1 Whoa! ACTOR_2 ^ Whoa! Two glaring problems with this syntax: A) i don't know that both actors are speaking simultaneously until *AFTER* i read _both_ lines B) a simple ampersand would have sufficed: ACTOR_1 & ACTOR_2 Whoa! There are so many more absurdities that i do not have time to list. If i were you, i would consider a ground-up project that focused on consistency and a very, *VERY* intuitive markdown structure. I could pull a better structure and syntax out of my arse. A simple ASCII text editor with a few "custom modes" is all you need to produce intuitive raw text screen plays that *almost* mimic the real thing. > There are several apps that purportedly will allow > screenwriters to convert plain text files to PDFs that > follow screenwriting format. They cannot replace the $250 > programs we use once production begins, but they are good > enough for working drafts until production begins. Well, $250 dollars is not a lot of money you know, especially if you are using the software for professionally. > However, most of these programs are "apps" with closed > GUIs, and of course I'm looking for a way to do the same > thing with Python and call it from the command-line or > from within Vim > > To that end, I would like to take this Ruby script (which > works pretty well, but throws errors in Mac OS X; some > Ruby ones and some Prince ones) and convert it to Python > so I can fix it myself, because I don't know Ruby at all, > and would rather work in Python. Ruby and Python are very similar. Have you made any attempts to translate (any portions of) the code yet? From richarddooling at gmail.com Sat Mar 9 00:36:05 2013 From: richarddooling at gmail.com (richarddooling at gmail.com) Date: Fri, 8 Mar 2013 21:36:05 -0800 (PST) Subject: Any other screenwriters? In-Reply-To: <8aa5c3d0-a008-4423-b2c2-0e70b442a256@googlegroups.com> References: <8aa5c3d0-a008-4423-b2c2-0e70b442a256@googlegroups.com> Message-ID: On Friday, March 8, 2013 9:41:57 PM UTC-6, Rick Johnson wrote: > First impression of Fountain: TOTAL CRAP! Noted. But it seems to be the syntax the screenwriters and their programmers have settled on for now. It's all working pretty well. Just no Python or command-line implementations yet. I didn't post seeking help to make a new markdown system for screenwriters. That would surely be out of my league. > Well, $250 dollars is not a lot of money you know, especially if you are using the software for professionally. Sorry if I was unclear. Sure. I have several programs like this and yes we use them once production starts, but it's nice to be able to work in your text editor for as long as possible. Faster. More versatility. So everybody is looking for a fast way to make PDFs in screenplay format from simple markdown text. > Ruby and Python are very similar. Have you made any attempts to translate (any portions of) the code yet? No, but I may. Especially if those regexes in the Ruby script will work in Python. I'll try. Thanks, Rick From rantingrickjohnson at gmail.com Sat Mar 9 18:07:02 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Mar 2013 15:07:02 -0800 (PST) Subject: Any other screenwriters? In-Reply-To: References: <8aa5c3d0-a008-4423-b2c2-0e70b442a256@googlegroups.com> Message-ID: On Friday, March 8, 2013 11:36:05 PM UTC-6, richard... at gmail.com wrote: > Noted. But it seems to be the syntax the screenwriters and > their programmers have settled on for now. It's all > working pretty well. Just no Python or command-line > implementations yet. I didn't post seeking help to make a > new markdown system for screenwriters. That would surely > be out of my league. Well *everything* will perpetually be "out of your league" until you start challenging yourself to learn new things. > Sorry if I was unclear. Sure. I have several programs like > this and yes we use them once production starts, but it's > nice to be able to work in your text editor for as long as > possible. Faster. More versatility. I agree. > So everybody is looking for a fast way to make PDFs in > screenplay format from simple markdown text. Well, well. This is your golden opportunity Rick. You seem to have found a niche problem that needs solving, but more importantly, you have experience as a screen writer (and programmer (hobbyist or not)) giving you valuable insight into what features can improve the workflow of a simple ASCII markdown syntax. And, lucky for you, making the translation from Ruby to Python does not require you to become highly proficient with Ruby, NO, once you understand a few key differences you can start translating code into something usable. I think the greatest barrier to learning Ruby is that it has too many ways to achieve the same result[1], which is opposite of Python's philosophy[2]. A few aspects that can trip you up are: * White-space is NOT significant * String literals delimited by using single quote chars are raw, and string literals delimited by double quote chars are not. * Module encapsulation is NOT automatic like in Python, instead, it must be explicitly declared using "module [code here] end" syntax! Another side effect of this is if you write (what you think is a function) in global namespace, you are actually writing a method for "Object", and since "Object" is inherited by almost everything in Ruby, now ALL those subclasses contain your new so-called "function"; Ha! Talk about an introspection nightmare! So be sure to encapsulate that code fella. * Ruby uses the "if-elsif-else" progression, whereas Python uses "if-elif-else". There is also a "case" statement available in Ruby. ============================================================ * Object Oriented Programming ============================================================ Ruby is more Object oriented than Python (which can be a good thing!), for instance, no more global function nightmare! Objects have methods and methods exist where they should! RUBY: sequence.map{|item| item+1} PYTHON_1: map(lambda item:item+1, sequence) # via list comprehension: PYTHON_2: [item+1 for item in sequence] # via generator expressions! PYTHON_3: (item+1 for item in sequence) Hmm, seems old Tim Toady is like a plague of, well... toads! Another side effect of Rubys strong OOP is that you can intelligently chain: sequence.map{|x| x+1}.uniq.sort.length ...if you tried that in Python, it would be a mess only a devoted lisper could appreciate: len(set(map(lambda x:x+1, sorted(sequence)))) o_O ?Ay, caramba! ============================================================ * Ruby Blocks can be written many *MANY* ways ============================================================ Blocks in ruby will "most likely" use curly braces like this: sequence.each{|item| do_something_with(item)} ...but they could also legally use the "do..end" delimiters like this: sequence.each do |item| do_something_with(item) end ...or even look exactly like Python code!: for item in sequence do_something_with(item) end Mama-Mia! That's three ways of accomplishing the exact same thing, and the worse part is, these could even be intermixed in the same script file! ============================================================ REFERENCES ============================================================ [1] ThereIsMoreThanOneWayToDoIt (affectionately referred to as: "Tim Toady") http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it [2] The Python Zen http://www.python.org/dev/peps/pep-0020/ From debacle at debian.org Sat Mar 9 04:42:08 2013 From: debacle at debian.org (W. Martin Borgert) Date: Sat, 9 Mar 2013 10:42:08 +0100 Subject: Trelby (was: Any other screenwriters?) In-Reply-To: References: Message-ID: <20130309094208.GA17400@fama.tangosoft.com> On 2013-03-08 13:07, Rick Dooling wrote: > However, most of these programs are "apps" with closed GUIs, and of course I'm looking for a way to do the same thing with Python and call it from the command-line or from within Vim You should consider taking a look at Trelby. It is free software (GPL2) and written in Python. While it is a GUI program, you can import (txt, fdx, celtx, astx, fountain, fadein) and export (pdf, rtf, fdx, html, foutain, txt), so using vi for editing should just work. I have no practical experience with the program, however. If you try it, you should probably take a snapshot from github, not the latest release 2.2, because it seems, they fixed some installation issues. While I have no experience in screenwriting yet, the program seems to run fine for me on Debian Linux. Find Trelby here: http://www.trelby.org/ From richarddooling at gmail.com Sun Mar 10 10:53:28 2013 From: richarddooling at gmail.com (richarddooling at gmail.com) Date: Sun, 10 Mar 2013 07:53:28 -0700 (PDT) Subject: Any other screenwriters? In-Reply-To: References: Message-ID: <307b10a4-89f8-4402-9ca7-d1c3923e3cda@googlegroups.com> Thanks all! I have the ruby script working pretty well and may indeed just tamper with that and perhaps learn a little ruby along the way. The goal is a command-line converter, hence Trelby would be nice as a converter of last resort, but I would never use it as an editor. The whole point is to stay in Vim as long as possible. Writers are just like programmers. We write, we run it (and then read the PDF) and then we debug (edit). It's this cycle that is so nice in, say, LaTeX or markdown where you can turn the file you are working on into a PDF, read a few paragraphs, edit, turn it into a new PDF, repeat forever. Thanks for all of the good advice. Rick From cjw at ncf.ca Fri Mar 8 19:48:28 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Fri, 08 Mar 2013 19:48:28 -0500 Subject: Apparent magic number problem Message-ID: I have a program that I wish to run in both Python 2.7 and Python 3.2 The program runs correctly under each version, but it runs more slowly under 3.2. This is probably due to the fact that the .pyc file is created for the Python 2.7 execution. When Python 3.2 is run it fails to create a new .pyc file and if the 2.7 .pyc is offered directly a magic number problem is reported. Is there a bug here? it seems to me that the Magic Number exception should lead to a new compile of the program. Colin W. From steve+comp.lang.python at pearwood.info Sat Mar 9 00:22:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Mar 2013 05:22:59 GMT Subject: Apparent magic number problem References: Message-ID: <513ac732$0$6512$c3e8da3$5496439d@news.astraweb.com> On Fri, 08 Mar 2013 19:48:28 -0500, Colin J. Williams wrote: > I have a program that I wish to run in both Python 2.7 and Python 3.2 > > The program runs correctly under each version, but it runs more slowly > under 3.2. Without knowing what your program does, it is impossible to comment on why it is slower under 3.2. > This is probably due to the fact that the .pyc file is created for the > Python 2.7 execution. I doubt it. > When Python 3.2 is run it fails to create a new .pyc file and if the 2.7 > .pyc is offered directly a magic number problem is reported. What do you mean, "offered directly"? Can you show exactly how you are running the program? > Is there a bug here? it seems to me that the Magic Number exception > should lead to a new compile of the program. Certainly not. Consider what that would mean. Suppose I try to run a .pyc file directly: python32 myprogram.pyc If myprogram.pyc is compiled for the correct version, it will run. If it is not, then an error occurs. You want Python to recompile that. But consider what that would mean: - Python would have to *guess* which .py file it should compile. Just because it can find something called "myprogram.py", doesn't mean that it is the right file. You might have renamed the file after compiling it, or moved it into a different folder. Who knows? - After guessing what file to compile, it would have to compile it, and *delete* the existing .pyc file, overwriting it with the newly compiled version. This potentially loses data. - And finally it would run the brand new .pyc file, which could do something *completely different* from the .pyc file you thought you were running. Python only compiles files when you import them, or if you use a tool like compileall. Merely running a file does not compile it. Likewise, if you run: python myprogram.py any myprogram.pyc file is ignored. .pyc files are only used if you directly run them, or if you import them. -- Steven From __peter__ at web.de Sat Mar 9 03:51:31 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Mar 2013 09:51:31 +0100 Subject: Apparent magic number problem References: Message-ID: Colin J. Williams wrote: > The program runs correctly under each version, but it runs more slowly > under 3.2. > This is probably due to the fact that the .pyc file is created for the > Python 2.7 execution. > When Python 3.2 is run it fails to create a new .pyc file and if the 2.7 > .pyc is offered directly a magic number problem is reported. (1) .pyc files are only created if a module is imported (2) The 2.7 .pyc file is put alongside the .py file whereas the 3.2 .pyc is put into the __pycache__ subfolder. No clash can occur. A simple example: $ ls mod.py $ cat mod.py print("hello world") Run it; no pyc is created: $ python2.7 mod.py hello world $ ls mod.py Import it using 2.7: $ python2.7 -c 'import mod' hello world $ ls mod.py mod.pyc Import it using 3.2: $ python3.2 -c 'import mod' hello world $ ls mod.py mod.pyc __pycache__ $ ls __pycache__/ mod.cpython-32.pyc Run the compiled code: $ python2.7 mod.pyc hello world $ python3.2 __pycache__/mod.cpython-32.pyc hello world But I'm with Steven, it's unlikely that the module compilation phase is responsible for a noticeable slowdown. From cjw at ncf.ca Sat Mar 9 10:16:38 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 09 Mar 2013 10:16:38 -0500 Subject: Apparent magic number problem In-Reply-To: References: Message-ID: On 09/03/2013 3:51 AM, Peter Otten wrote: > Colin J. Williams wrote: >> The program runs correctly under each version, but it runs more slowly >> under 3.2. > >> This is probably due to the fact that the .pyc file is created for the >> Python 2.7 execution. > >> When Python 3.2 is run it fails to create a new .pyc file and if the 2.7 >> .pyc is offered directly a magic number problem is reported. > > (1) .pyc files are only created if a module is imported > (2) The 2.7 .pyc file is put alongside the .py file whereas the 3.2 .pyc is > put into the __pycache__ subfolder. No clash can occur. > > A simple example: > > $ ls > mod.py > $ cat mod.py > print("hello world") > > Run it; no pyc is created: > > $ python2.7 mod.py > hello world > $ ls > mod.py > > Import it using 2.7: > > $ python2.7 -c 'import mod' > hello world > $ ls > mod.py mod.pyc > > Import it using 3.2: > > $ python3.2 -c 'import mod' > hello world > $ ls > mod.py mod.pyc __pycache__ > $ ls __pycache__/ > mod.cpython-32.pyc > > Run the compiled code: > > $ python2.7 mod.pyc > hello world > $ python3.2 __pycache__/mod.cpython-32.pyc > hello world > > But I'm with Steven, it's unlikely that the module compilation phase is > responsible for a noticeable slowdown. > > Thanks to Steven and Peter for their responses. My main problem appears to be with: Profile with Python 2.7 11 25.736 2.340 25.736 2.340 {numpy.linalg.lapack_lite.dgesv} Profile with Python 3.2 11 152.111 13.828 152.111 13.828 {built-in method dgesv} In other words, the Python 3.2 linear equation solve takes longer than with Python 2.7. I'll pursue this with the numpy folk. There also appears to be a problem with the generation of the .pyc. Please see the example below: rem temp.bat dir *.pyc del *.pyc C:\python32\python.exe profiler.py Intel P4 2.8GHz 2MB Ram 221 GB Free Disk cjw> prof3.txt dir *.pyc This is executed with: tmp.bat > tmp.lst profiler.py contains: #------------------------------------------------------------------------------- # Name: profiler.py # Purpose: # # Author: cjw # # Created: 17/02/2013 # Copyright: (c) cjw 2013 # Licence: #------------------------------------------------------------------------------- import cProfile as p, pstats as s, sys def main(): v= sys.version statsFile= 'FPSStats' + v[0] + v[2] + '.txt' p.run('import testFPSpeed; testFPSpeed.main()', statsFile) t= s.Stats(statsFile) t.strip_dirs().sort_stats('cumulative').print_stats(40) pass if __name__ == '__main__': main() tmp.lst contains: C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>rem temp.bat C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>del *.pyc C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>C:\python32\python.exe profiler.py Intel P4 2.8GHz 2MB Ram 221 GB Free Disk cjw 1>prof3.txt C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>rem temp.bat C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>del *.pyc C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>C:\python32\python.exe profiler.py Intel P4 2.8GHz 2MB Ram 221 GB Free Disk cjw 1>prof3.txt C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi tmp.lst contains: C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>rem temp.bat C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>del *.pyc C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>C:\python32\python.exe profiler.py Intel P4 2.8GHz 2MB Ram 221 GB Free Disk cjw 1>prof3.txt C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi>dir *.pyc Volume in drive C has no label. Volume Serial Number is D001-FAC4 Directory of C:\Documents and Settings\cjw.P4A\My Documents\devpy\raspi From this we see that no .pys was reported for testFPSpeed.py. However, looking at the directory itself. the .pyc is in fact created. Thus, the .pyc is, if necessary, generated upon the import of a .py and so this does not explain the time difference between 2.7 and 3.2. Thanks to Steven for pointing to the __cache__ directory, I find no reference to it in the docs. Colin W. PS I wish we could format the text in these messages. From __peter__ at web.de Sun Mar 10 06:56:13 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 10 Mar 2013 11:56:13 +0100 Subject: Apparent magic number problem References: Message-ID: Colin J. Williams wrote: > My main problem appears to be with: > > Profile with Python 2.7 > 11 25.736 2.340 25.736 2.340 > {numpy.linalg.lapack_lite.dgesv} > > Profile with Python 3.2 > 11 152.111 13.828 152.111 13.828 {built-in method dgesv} > > In other words, the Python 3.2 linear equation solve takes longer than > with Python 2.7. I'll pursue this with the numpy folk. That seems to be a more promising route for further research than byte code compilation. > There also appears to be a problem with the generation of the .pyc. > Please see the example below: Sorry, the signal-to-noise ratio is too low for me to bother with that. From Kene.Meniru at illom.org Fri Mar 8 22:06:28 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Fri, 08 Mar 2013 22:06:28 -0500 Subject: Running external module and accessing the created objects Message-ID: Program summary: I have a module called user.py that imports another module called app.py. Functions in app.py are used in user.py to describe 3D objects. These objects are saved in another object described in doc.py. app.py contains a function called view(). When called in user.py, it signals the end of object descriptions. Presently all objects contained in doc.py are exported to either POV-Ray or OpenSCAD file format depending on the argument given to view(). My Issues: I have decided I want to provide a preview of the objects using opengl (pyglet). So I am trying to create another module called appwin.py which the user can launch with user.py as an argument. When each object is described in user.py, I want the user to be able to switch to appwin.py, provide a signal that makes appwin.py redraw the screen to show any modifications (perhaps with the enter key). I do not want to invest much time with appwin.py now as I am still coding app.py. Right now, appwin.py just subclasses pyglet.window.Window(). I do not want to merge app.py and appwin.py. I want them to be two separate applications because I want to retain the option of either console or many different window interfaces. The problem then is: How can I run appwin.py which will then execute user.py to create the objects to be saved in doc.py. Then when view() is encountered to be able to access the objects stored in doc.py in appwin.py? Any ideas will help. -- Kene :::::::::::::::::: KeMeniru at gmail.com From steve+comp.lang.python at pearwood.info Sat Mar 9 03:03:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Mar 2013 08:03:31 GMT Subject: Running external module and accessing the created objects References: Message-ID: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> On Fri, 08 Mar 2013 22:06:28 -0500, Kene Meniru wrote: > Program summary: > > I have a module called user.py that imports another module called > app.py. Functions in app.py are used in user.py to describe 3D objects. > These objects are saved in another object described in doc.py. What do you mean, "objects are saved in another object"? > app.py contains a function called view(). When called in user.py, it > signals the end of object descriptions. Presently all objects contained > in doc.py are exported to either POV-Ray or OpenSCAD file format > depending on the argument given to view(). > > My Issues: > > I have decided I want to provide a preview of the objects using opengl > (pyglet). So I am trying to create another module called appwin.py which > the user can launch with user.py as an argument. What happens if the user launches appwin with a different argument? If appwin can only take one, compulsory, argument, then it's silly to require it as an argument. Just have appwin automatically import user.py, and do whatever it needs. > When each object is > described in user.py, I want the user to be able to switch to appwin.py, > provide a signal that makes appwin.py redraw the screen to show any > modifications (perhaps with the enter key). This makes no sense to me. Are you saying that appwin opens a text editor that allows the user to edit the user.py source code? > I do not want to invest much time with appwin.py now as I am still > coding app.py. Right now, appwin.py just subclasses > pyglet.window.Window(). > > I do not want to merge app.py and appwin.py. I want them to be two > separate applications because I want to retain the option of either > console or many different window interfaces. Making them a single module still retains the option of console or many different window interfaces. > The problem then is: > > How can I run appwin.py which will then execute user.py to create the > objects to be saved in doc.py. I don't know. How does user.py create the objects? Suppose it users a function called "create". Then you would do this in appwin: import user user.create() > Then when view() is encountered to be > able to access the objects stored in doc.py in appwin.py? What do you mean by "view() is encounted"? How would you access the objects stored in doc.py? Suppose you access them using a list called "list_of_objects". Then in appwin.py: import doc for obj in doc.list_of_objects: do_something_with(obj) where you have to write the function "do_something_with", to do whatever it is you want to do. By the way, calling a module "doc" which is not for *documentation* is a bad idea. -- Steven From Kene.Meniru at illom.org Sat Mar 9 06:05:52 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 06:05:52 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > What do you mean, "objects are saved in another object"? > doc.py has a dictionary. When the user describes a wall, it is passed to the doc object to be saved in the dictionary. > > What happens if the user launches appwin with a different argument? > > If appwin can only take one, compulsory, argument, then it's silly to > require it as an argument. Just have appwin automatically import user.py, > and do whatever it needs. > I guess my description does not come across well. I thought user.py sounded like it is, a user created file. It will be named differently for each user to created different types of 3D objects. It does not make sense to expect every user to name their design file the same. So there will have to be a differently named single argument for buildeswin. > > This makes no sense to me. Are you saying that appwin opens a text editor > that allows the user to edit the user.py source code? > No. appwin opens an opengl (pyglet.window.Window()) graphics window as I mentioned. > > I don't know. How does user.py create the objects? Suppose it users a > function called "create". Then you would do this in appwin: > > > import user > user.create() > I have tried importing "user.py" and/or "app.py". However there is no single command to call. My program is designed to assist in the building design process. It is a big program and the creation of building components takes quite a few steps. I do not want to support these steps in a graphics window which is why the user uses any text editor they prefer to create "user.py". I want "appwin.py" (which has a graphics window) to be able to access objects stored in "doc.py" (which has a dictionary) after a command like "python user.py" so that the objects saved in "doc.py" after execution can be retrieved and drawn in "appwin.py". > What do you mean by "view() is encounted"? > This is a command that the user can enter in user.py. app.py will then encounter this command as python parses the file. > How would you access the objects stored in doc.py? Suppose you access > them using a list called "list_of_objects". Then in appwin.py: > > import doc > for obj in doc.list_of_objects: > do_something_with(obj) > I have tried this but there are no objects found in the dictionary in doc.py. I am guessing that I have to execute appwin.py so that it shares the same namespace with user.py or maybe a way to access that namespace. This is the reason for my question. > where you have to write the function "do_something_with", to do whatever > it is you want to do. > > > -- Kene :::::::::::::::::: KeMeniru at gmail.com From rosuav at gmail.com Sat Mar 9 06:47:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2013 22:47:52 +1100 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 9, 2013 at 10:05 PM, Kene Meniru wrote: > I have tried importing "user.py" and/or "app.py". However there is no > single command to call. I haven't followed the thread in detail, but I gather you're trying to import a file with a variable name? Instead of 'import user', try: user = __import__("foobar") You can then replace the quoted string with whatever you need (note, leave off the .py extension). In your code, it'll be as if you did: import foobar as user but with the flexibility of using whatever run-time-chosen name you need. ChrisA From davea at davea.name Sat Mar 9 07:02:28 2013 From: davea at davea.name (Dave Angel) Date: Sat, 09 Mar 2013 07:02:28 -0500 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513B24D4.4020801@davea.name> On 03/09/2013 06:05 AM, Kene Meniru wrote: > > (lots of stuff that was more confusing to me than helpful) You use the words launch, encountered, execute, and others in ways that do not make sense to me, or are at least ambiguous. You have an explicitly named user.py, which apparently is *not* generally named that. I could give you lots of random facts and suggestions, and one of the might hit home. For example the __import__() function can import a module that you don't know the name of ahead of time. It's not often the right answer, though, so I hesitate to suggest it. For another example, if you import a module by two different names, or if you import the "module" that is your starting script, then you can end up with two instances of such a module, with all sorts of negative implications about global data or class attributes stored in that module, or even more subtle problems. For a final example, having a circular import tree can cause problems if any of those imports have any global code (like class initialization, defining constants, etc.). It's generally much better to define a strict hierarchy of who imports whom. But I think instead that it'd be better for you to make a clearer statement about how your code is structured. I'm guessing that all of this is intended to be in one executable -- no child processes, etc. So don't say launch, say import, or function-call, or whatever you are really doing. I'm guessing that you're running this on Python 3.3 under Linux. I'm guessing that "user.py" is one possible name that a particular user calls his script. And that script is what he runs on the Python commandline. python user.py And that script calls functions in app.py, doc.py, and/or appwin.py. And that currently, you're trying to import user.py from one of your own modules, for purposes of either callback functions or global data access. That's a mistake. When you import your *script* (using __import__() as suggested above) you get a new copy of the script, and new copies of all its global data. I can't even guess how you're intending to mix the commandline stuff of app.py with gui stuff in one or more appwin.py variants. You'll have to be explicit, if it even matters yet. I suggest that rather than responding to these points, you restate your problem, in one place, with coherent detail that eliminates these guesses and replaces them with reality. Start with the environment this is running in, and the commandline typically used to launch the code, and the interdepencies of the various modules. -- DaveA From steve+comp.lang.python at pearwood.info Sat Mar 9 06:34:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Mar 2013 11:34:10 GMT Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513b1e32$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sat, 09 Mar 2013 06:05:52 -0500, Kene Meniru wrote: > I thought user.py sounded like it is, a user created file. No. It sounded like a file called literally "user.py". As for the rest, I shall think about it, and hopefully either I or someone else will write back later with suggestions. P.S. your posts have the followup header set to Gmane. Please do not do that. Many people are reading this via the comp.lang.python newsgroup, or via email. -- Steven From Kene.Meniru at illom.org Sat Mar 9 10:34:53 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 10:34:53 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: OK. Sorry to have caused all the confusion. Let me try this again. To use my program the user needs a script file I will call user.py. Functions from my program must be imported into this file with something like "from myapp import *". myapp.py is a module in my program that has all the functions that the user needs to describe building components. There is also a main controller object that is imported into myapp.py module called app. When python parses user.py module, the functions the user has provided creates building components which are then saved in a dictionary located in an object called doc that is part of my program. The user is free to use the functions in myapp.py to describe building components. When this process is complete or when the user wants to view their work-in-progress, they have to place a function called view() on the last line in user.py. This function currently exports the components into POV-Ray or OpenSCAD format. These are CAD programs that read script files to render or create images of the described artifacts. So this means that to view their work the user needs to run python on user.py to export the building and then run POV-Ray or OpenSCAD on the exported file to see the building. I want to make it possible for the user to preview the building components without having to use the external rendering programs. I can currently have the app object provide this preview but it means that the user will have to process user.py with python then exit the graphic window each time they need to see changes. So the solution I am looking for is to have a graphic window open that watches user.py for changes. If there is a change the graphic window updates the rendition of the created components without further intervention by the user. However this means that the graphic must somehow run python to parse user.py and then be able to access the objects stored in doc so that the coordinates can be used to update the view. This is where I am having difficulty. I hope this is clearer. -- Kene :::::::::::::::::: KeMeniru at gmail.com From davea at davea.name Sat Mar 9 11:12:56 2013 From: davea at davea.name (Dave Angel) Date: Sat, 09 Mar 2013 11:12:56 -0500 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513B5F88.9060002@davea.name> On 03/09/2013 10:34 AM, Kene Meniru wrote: > OK. Sorry to have caused all the confusion. Let me try this again. > Thank you very much. This is much clearer, though it's not all here. > To use my program the user needs a script file I will call user.py. > Functions from my program must be imported into this file with > something like "from myapp import *". And does the user run this script by doing python user.py > > myapp.py is a module in my program that has all the functions that the > user needs to describe building components. There is also a main > controller object that is imported into myapp.py module called app. > > When python parses user.py module, You presumably mean, "When Python runs the script user.py" > the functions the user has provided > creates building components which are then saved in a dictionary > located in an object called doc that is part of my program. What program is that? Looks to me like you're writing a series of modules, a framework perhaps, that is invoked by the user script. > > The user is free to use the functions in myapp.py to describe building > components. When this process is complete or when the user wants to > view their work-in-progress, they have to place a function called > view() on the last line in user.py. Don't you mean the code in user.py has to *call* the function app.view() when they're all done with defining the components? That has nothing to do with being the last line. > This function currently exports You mean writes files into the file system? > the components into POV-Ray or OpenSCAD format. These are CAD programs > that read script files to render or create images of the described > artifacts. So this means that to view their work the user needs to run > python on user.py to export the building and then run POV-Ray or > OpenSCAD on the exported file to see the building. At that point, the user.py script has completed, and Python is done, right? > > I want to make it possible for the user to preview the building > components without having to use the external rendering programs. I > can currently have the app object provide this preview but it means > that the user will have to process user.py with python then exit the > graphic window each time they need to see changes. What changes are those? You can't change a script while it's executing. Could you clarify this so I can rethink the following paragraph? > > So the solution I am looking for is to have a graphic window open that > watches user.py for changes. If there is a change the graphic window > updates the rendition of the created components without further > intervention by the user. However this means that the graphic must > somehow run python to parse user.py and then be able to access the > objects stored in doc so that the coordinates can be used to update > the view. This is where I am having difficulty. > > I hope this is clearer. > -- DaveA From Kene.Meniru at illom.org Sat Mar 9 11:56:49 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 11:56:49 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513B5F88.9060002@davea.name> Message-ID: Dave Angel wrote: > On 03/09/2013 10:34 AM, Kene Meniru wrote: >> To use my program the user needs a script file I will call user.py. >> Functions from my program must be imported into this file with >> something like "from myapp import *". > > And does the user run this script by doing > python user.py > Yes >> >> myapp.py is a module in my program that has all the functions that the >> user needs to describe building components. There is also a main >> controller object that is imported into myapp.py module called app. >> >> When python parses user.py module, > > You presumably mean, "When Python runs the script user.py" > When the user types and enters at the command line: "python user.py" >> the functions the user has provided >> creates building components which are then saved in a dictionary >> located in an object called doc that is part of my program. > > What program is that? Looks to me like you're writing a series of > modules, a framework perhaps, that is invoked by the user script. > Yes. I am writing many functions and classes in many modules that work together. >> >> The user is free to use the functions in myapp.py to describe building >> components. When this process is complete or when the user wants to >> view their work-in-progress, they have to place a function called >> view() on the last line in user.py. > > Don't you mean the code in user.py has to *call* the function app.view() > when they're all done with defining the components? That has nothing to > do with being the last line. Well... yes. The function is app.view() but it is not called automatically by the code in user.py. The following is an example of the contents of user.py ################### begin user.py ############################# from buildes import * site("Willow_Creek_Ct", 5) """Create a site with name and number of boundaries.""" level("level1", 3000) level("level2", 3000) """Create levels with name and height.""" setLevel("level1") """Set the current level to place objects""" space("Dining", 5) """Create a space with 5 sides (walls)""" linearSide("Dining-S1", 3683, 152, 0) """Initialize the first side of space called Dining""" offset("Dining-S1", (3000, 0, 0)) """Install the first side of Dining space called Dining-S1""" view(POV) """Exports objects to POV-Ray format""" ################### end user.py ############################# > >> This function currently exports > > You mean writes files into the file system? > Yes. >> the components into POV-Ray or OpenSCAD format. These are CAD programs >> that read script files to render or create images of the described >> artifacts. So this means that to view their work the user needs to run >> python on user.py to export the building and then run POV-Ray or >> OpenSCAD on the exported file to see the building. > > At that point, the user.py script has completed, and Python is done, > right? > Yes >> >> I want to make it possible for the user to preview the building >> components without having to use the external rendering programs. I >> can currently have the app object provide this preview but it means >> that the user will have to process user.py with python then exit the >> graphic window each time they need to see changes. > > What changes are those? You can't change a script while it's executing. > Could you clarify this so I can rethink the following paragraph? > Working on the user.py is an iterative process. The user adds new objects or changes the parameters of the objects already there and envokes "python user.py" each time to see the changes made. Just like using a program like LaTeX. You edit your text file and run LaTeX on the file to see the changes you made. The process continues until you finish the document. > > > So the solution I am looking for is to have a graphic window open that > watches user.py for changes. If there is a change the graphic window > updates the rendition of the created components without further > intervention by the user. However this means that the graphic must > somehow run python to parse user.py and then be able to access the > objects stored in doc so that the coordinates can be used to update > the view. This is where I am having difficulty. -- Kene :::::::::::::::::: KeMeniru at gmail.com From davea at davea.name Sat Mar 9 12:20:51 2013 From: davea at davea.name (Dave Angel) Date: Sat, 09 Mar 2013 12:20:51 -0500 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513B5F88.9060002@davea.name> Message-ID: <513B6F73.5010909@davea.name> On 03/09/2013 11:56 AM, Kene Meniru wrote: > Dave Angel wrote: > >> On 03/09/2013 10:34 AM, Kene Meniru wrote: > >>> To use my program the user needs a script file I will call user.py. >>> Functions from my program must be imported into this file with >>> something like "from myapp import *". >> >> And does the user run this script by doing >> python user.py >> > > Yes > >>> >>> myapp.py is a module in my program that has all the functions that the >>> user needs to describe building components. There is also a main >>> controller object that is imported into myapp.py module called app. >>> >>> When python parses user.py module, >> >> You presumably mean, "When Python runs the script user.py" >> > > When the user types and enters at the command line: "python user.py" > >>> the functions the user has provided >>> creates building components which are then saved in a dictionary >>> located in an object called doc that is part of my program. >> >> What program is that? Looks to me like you're writing a series of >> modules, a framework perhaps, that is invoked by the user script. >> > > Yes. I am writing many functions and classes in many modules that work > together. > >>> >>> The user is free to use the functions in myapp.py to describe building >>> components. When this process is complete or when the user wants to >>> view their work-in-progress, they have to place a function called >>> view() on the last line in user.py. >> >> Don't you mean the code in user.py has to *call* the function app.view() >> when they're all done with defining the components? That has nothing to >> do with being the last line. > > Well... yes. The function is app.view() but it is not called automatically > by the code in user.py. The following is an example of the contents of > user.py > > ################### begin user.py ############################# > from buildes import * > > site("Willow_Creek_Ct", 5) > """Create a site with name and number of boundaries.""" > level("level1", 3000) > level("level2", 3000) > """Create levels with name and height.""" > setLevel("level1") > """Set the current level to place objects""" > space("Dining", 5) > """Create a space with 5 sides (walls)""" > linearSide("Dining-S1", 3683, 152, 0) > """Initialize the first side of space called Dining""" > offset("Dining-S1", (3000, 0, 0)) > """Install the first side of Dining space called Dining-S1""" > view(POV) > """Exports objects to POV-Ray format""" > ################### end user.py ############################# > >> >>> This function currently exports >> >> You mean writes files into the file system? >> > > Yes. > >>> the components into POV-Ray or OpenSCAD format. These are CAD programs >>> that read script files to render or create images of the described >>> artifacts. So this means that to view their work the user needs to run >>> python on user.py to export the building and then run POV-Ray or >>> OpenSCAD on the exported file to see the building. >> >> At that point, the user.py script has completed, and Python is done, >> right? >> > > Yes > >>> >>> I want to make it possible for the user to preview the building >>> components without having to use the external rendering programs. I >>> can currently have the app object provide this preview but it means >>> that the user will have to process user.py with python then exit the >>> graphic window each time they need to see changes. >> >> What changes are those? You can't change a script while it's executing. >> Could you clarify this so I can rethink the following paragraph? >> > > Working on the user.py is an iterative process. The user adds new objects or > changes the parameters of the objects already there and envokes "python > user.py" each time to see the changes made. Just like using a program like > LaTeX. You edit your text file and run LaTeX on the file to see the changes > you made. The process continues until you finish the document. > >> >> >> So the solution I am looking for is to have a graphic window open that >> watches user.py for changes. It would then have to be a separate executable. Are you really saying you want this window to keep "running" after the script ends? And that somehow it notices that the user has rerun the user.py script? Or could it simply be a window created during the user.py run that stays running till it's closed, which ends the script as well? >> If there is a change the graphic window >> updates the rendition of the created components without further >> intervention by the user. Is running the script considered intervention? Or do you mean literally that somebody watches the script for changes (eg. by watching the timestamp)? >> However this means that the graphic must >> somehow run python to parse user.py and then be able to access the >> objects stored in doc so that the coordinates can be used to update >> the view. This is where I am having difficulty. > Either the "graphic" is in the same process, in which case the script can only be "parsed" once, or the "graphic" is in a second process, in which case you're talking some interesting interprocess communication (ipc). That's certainly do-able, but it's way beyond the scope of the kind of programming you've been talking about. But sometimes just using a regular file for transfer is adequate. If you really want two processes, then you should consider having the user run the the graphic app, with a commandline parameter of user.py, and have it create the user.py process. The user.py process runs till it has created all the data, then sends it via some ipc to the graphic app. Once sent, it terminates. The graphic app reads the ipc stuff, updates its graphics, then idles, watching for timestamp changes on the user.py file. If you choose to use external file(s) to communicate between the two processes, you might use pickle or shelve. -- DaveA From Kene.Meniru at illom.org Sat Mar 9 12:39:46 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 12:39:46 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513B5F88.9060002@davea.name> <513B6F73.5010909@davea.name> Message-ID: Dave Angel wrote: >>> >>> So the solution I am looking for is to have a graphic window open that >>> watches user.py for changes. > > It would then have to be a separate executable. This is my thinking too. > Are you really saying > you want this window to keep "running" after the script ends? And that > somehow it notices that the user has rerun the user.py script? Or > could it simply be a window created during the user.py run that stays > running till it's closed, which ends the script as well? Following the idea that it should be a separate executable, the user does not have to run the script by doing "python user.py" as they would normally do. The window takes this over. It sits there watching for changes to user.py such as change in file size and/or time or if the user hits the enter key while it has focus. My question really is how can the graphics window have access to the objects saved in the dictionary of the doc object after running "python user.py". It need to do this to be able to use their coordinates to redraw the view. > >>> If there is a change the graphic window >>> updates the rendition of the created components without further >>> intervention by the user. > > Is running the script considered intervention? Or do you mean literally > that somebody watches the script for changes (eg. by watching the > timestamp)? > I do not understand. What I mean is that this happens automatically. The user no longer needs to do "python user.py" the graphics window now should do this for the user when changes are detected in user.py by watching timestamp for example. >>> However this means that the graphic must >>> somehow run python to parse user.py and then be able to access the >>> objects stored in doc so that the coordinates can be used to update >>> the view. This is where I am having difficulty. >> > If you really want two processes, then you should consider having the > user run the the graphic app, with a commandline parameter of user.py, > and have it create the user.py process. The user.py process runs till > it has created all the data, then sends it via some ipc to the graphic > app. Once sent, it terminates. The graphic app reads the ipc stuff, > updates its graphics, then idles, watching for timestamp changes on the > user.py file. > This sounds interesting. What is ipc. Can you give me an example? > -- Kene :::::::::::::::::: KeMeniru at gmail.com From Kene.Meniru at illom.org Sat Mar 9 13:18:19 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 13:18:19 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513B5F88.9060002@davea.name> <513B6F73.5010909@davea.name> Message-ID: Kene Meniru wrote: > Dave Angel wrote: >> If you really want two processes, then you should consider having the >> user run the the graphic app, with a commandline parameter of user.py, >> and have it create the user.py process. The user.py process runs till >> it has created all the data, then sends it via some ipc to the graphic >> app. Once sent, it terminates. The graphic app reads the ipc stuff, >> updates its graphics, then idles, watching for timestamp changes on the >> user.py file. >> > > This sounds interesting. What is ipc. Can you give me an example? Actually there is a possible simple solution consistent with the way my program works already. I can just provide another exporter for OpenGL that pyglet.window.Window() subclass will be able to read. So I will provide another parameter for OGL so the user can use view(OGL). When the user.py script is run, all objects in doc are converted and exported to a file that the graphics window is watching. The contents will then be used to update the view. So this means that the user or the graphics window object can run "python user.py" it no longer matters how. Thanks for your comments. -- Kene :::::::::::::::::: KeMeniru at gmail.com From rantingrickjohnson at gmail.com Sat Mar 9 11:51:35 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Mar 2013 08:51:35 -0800 (PST) Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, March 9, 2013 9:34:53 AM UTC-6, Kene Meniru wrote: > OK. Sorry to have caused all the confusion. Let me try > this again. Sounds to me like you should solve this problem in two manners: ============================================================ Interactive Input ============================================================ Create an interactive environment where the user can enter commands directly into the namespace using your API in real time, then when he is ready to see the result of those commands, he can call "display command" or push a "display button" and the App will run the appropriate outside programs to show the visualization. ============================================================ Scripts loaded at runtime ============================================================ If you prefer the user to write "scripts", and then have your App read these scripts (and create visualizations from the commands within the scripts) then the only difference between step 1 and step 2 is *when* the commands are interpreted. In this case your app will *load* the scripts AFTER they are completely written (this could be done automatically by the app at runtime IF the path to these scripts is known, or could be accomplished by the user picking files in a dialog (Menu->RunScript). I think you are trying to create step 1 without the interactive environment. This is your mistake. Having users work with "raw files" and then *somehow* watching a "raw file" for certain "display commands" (in real time) is folly. Heck, when you edit a file in a text editor you are only seeing a representation of the file from the last time it was saved, and your app could never know when the "file data" and the "file view" where synchronized; without an asinine amount of foolish programming of course. If this is not what you want, then i suggest you create a simple representation of your code (or link to the actual code). From Kene.Meniru at illom.org Sat Mar 9 12:21:20 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Sat, 09 Mar 2013 12:21:20 -0500 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: Rick Johnson wrote: > On Saturday, March 9, 2013 9:34:53 AM UTC-6, Kene Meniru wrote: > ============================================================ > Interactive Input > ============================================================ > > Create an interactive environment where the user can enter commands > directly into the namespace using your API in real time, then when he is > ready to see the result of those commands, he can call "display command" > or push a "display button" and the App will run the appropriate outside > programs to show the visualization. > > ============================================================ > Scripts loaded at runtime > ============================================================ > > If you prefer the user to write "scripts", and then have your App read > these scripts (and create visualizations from the commands within the > scripts) then the only difference between step 1 and step 2 is *when* the > commands are interpreted. In this case your app will *load* the scripts > AFTER they are completely written (this could be done automatically by the > app at runtime IF the path to these scripts is known, or could be > accomplished by the user picking files in a dialog (Menu->RunScript). > Please see my last response to Dave Angel. I think it is possible for a program to watch a file. I am not interested in menus which is why I am going this route. I could easily use PyQt to make this but I am not interested in graphical user interfaces. Are you are familiar with LaTeX? That is the system I very much want to emulate. > I think you are trying to create step 1 without the interactive > environment. This is your mistake. Having users work with "raw files" and > then *somehow* watching a "raw file" for certain "display commands" (in > real time) is folly. > It is possible to watch files for changes without user intervention. If a change is detected (whether by file size or time) the file can be executed as all python modules can be using "python FILENAME.py". How is this folly? > Heck, when you edit a file in a text editor you are only seeing a > representation of the file from the last time it was saved, and your app > could never know when the "file data" and the "file view" where > synchronized; without an asinine amount of foolish programming of course. > > If this is not what you want, then i suggest you create a simple > representation of your code (or link to the actual code). My code is available at http://sourceforge.net/projects/buildes. The documentation is at http://buildes.sourceforge.net/. -- Kene :::::::::::::::::: KeMeniru at gmail.com From rantingrickjohnson at gmail.com Sat Mar 9 13:33:13 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Mar 2013 10:33:13 -0800 (PST) Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9e0dea4b-c936-4f28-b6d8-e2a0f166a17d@googlegroups.com> On Saturday, March 9, 2013 11:21:20 AM UTC-6, Kene Meniru wrote: > Please see my last response to Dave Angel. I think it is > possible for a program to watch a file. I am not > interested in menus which is why I am going this route. I > could easily use PyQt to make this but I am not interested > in graphical user interfaces. Yes, using a non-GUI interface is always much simpler to code than a GUI. I can see the merit in that approach. > It is possible to watch files for changes without user > intervention. If a change is detected (whether by file > size or time) Indeed, but the file data on disc and the file data in the text editor cannot be guaranteed to be exact representations of each other at any random sample of time. > the file can be executed as all python > modules can be using "python FILENAME.py". I understand that Python files can be executed (as we all do). > How is this folly? Well i don't have enough information *yet* to decide if your program design is "folly", but i can assure you that your explanations of how this program will function are. My problem with your workflow is that it ignores the need to constantly save the edited file data back to disc, because i "assume" you are using a text editor to edit the ".py" files. Sure, you could create a behavior of the editor to save the changes after every keystroke, or every newline, or whatever; but you failed to mentioned how any of this will work. > My code is available at > http://sourceforge.net/projects/buildes. The documentation > is at http://buildes.sourceforge.net/. Well GEE-GOLLY-GARSH, thanks for finally posting something we can draw coherency from. May i suggest that next time you post the links in the very first post? I mean, i like playing "guess the number" as much as the next guy, but geez! From Kene.Meniru at illom.org Mon Mar 11 19:57:28 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Mon, 11 Mar 2013 19:57:28 -0400 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: Here's the answer to this question. The summary of the question: how to run a module (called myapp.py) from another module (called myappwin.py) and be able to access the namespace of myapp.py from myappwin.py. ------------------------------------------ # contents of myapp.py import math class MyApp(object): def __init__(self): super(MyApp, self).__init__() self.name = "MyAppName" def testFunction(): boke = "Smilling" print math.sin(1), boke ----------------------------------------- # contents of myappwin def test(): dic = {} execfile("myapp.py", dic) testObj = dic["MyApp"]() # access MyApp class dic["testFunction"]() # execute testFunction print testObj.name # print string test() ----------------------------------------- # OUTPUT $ python myappwin.py 0.841470984808 Smilling MyAppName -- Kene :::::::::::::::::: KeMeniru at gmail.com From davea at davea.name Mon Mar 11 20:48:43 2013 From: davea at davea.name (Dave Angel) Date: Mon, 11 Mar 2013 20:48:43 -0400 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <513E7B6B.5070608@davea.name> On 03/11/2013 07:57 PM, Kene Meniru wrote: > Here's the answer to this question. > > The summary of the question: how to run a module (called myapp.py) from > another module (called myappwin.py) and be able to access the namespace of > myapp.py from myappwin.py. > > ------------------------------------------ > # contents of myapp.py > import math > > class MyApp(object): > def __init__(self): > super(MyApp, self).__init__() > self.name = "MyAppName" > > > def testFunction(): > boke = "Smilling" > print math.sin(1), boke > ----------------------------------------- > # contents of myappwin > def test(): > dic = {} > execfile("myapp.py", dic) > testObj = dic["MyApp"]() # access MyApp class > dic["testFunction"]() # execute testFunction > print testObj.name # print string > > > test() > ----------------------------------------- > # OUTPUT > $ python myappwin.py > 0.841470984808 Smilling > MyAppName > I hope you're just kidding. execfile() and exec() are two of the most dangerous mechanisms around. import or __import__() would be much better, as long as your user hasn't already run myapp.py as his script. -- DaveA From Kene.Meniru at illom.org Mon Mar 11 21:23:19 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Mon, 11 Mar 2013 21:23:19 -0400 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> Message-ID: Dave Angel wrote: > On 03/11/2013 07:57 PM, Kene Meniru wrote: > > I hope you're just kidding. execfile() and exec() are two of the most > dangerous mechanisms around. import or __import__() would be much > better, as long as your user hasn't already run myapp.py as his script. > It does what I want. Security is another issue and I understand but can't help it until I find another solution. import does not do what I want. How does __import__() work and what do you mean "as long as your user hasn't already run myapp.py as his script."? -- Kene :::::::::::::::::: KeMeniru at gmail.com From davea at davea.name Mon Mar 11 22:11:24 2013 From: davea at davea.name (Dave Angel) Date: Mon, 11 Mar 2013 22:11:24 -0400 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> Message-ID: <513E8ECC.20805@davea.name> On 03/11/2013 09:23 PM, Kene Meniru wrote: > Dave Angel wrote: > >> On 03/11/2013 07:57 PM, Kene Meniru wrote: > >> >> I hope you're just kidding. execfile() and exec() are two of the most >> dangerous mechanisms around. import or __import__() would be much >> better, as long as your user hasn't already run myapp.py as his script. >> > > It does what I want. Security is another issue and I understand but can't > help it until I find another solution. > > import does not do what I want. > > How does __import__() work and what do you mean "as long as your user hasn't > already run myapp.py as his script."? > The __import__() function is defined http://docs.python.org/2/library/functions.html#__import__ appname = "myapp" usermodule = __import__(appname, globals(), locals(), [], -1) And now you can use usermodule as though you had imported it in the usual way. As for my other caveat, I've said it before in this thread. Make sure you don't ever load a module by more than one name, or you'll end up with a mess. And that includes the original script, which is loaded by the name '__main__' You also should avoid any circular import, as it can be very tricky to deal with them. As I said earlier in the thread: >>>> >>>> For example the __import__() function can import a module that you >>>> don't know the name of ahead of time. It's not often the right >>>> answer, though, so I hesitate to suggest it. >>>> >>>> For another example, if you import a module by two different names, >>>> or if you import the "module" that is your starting script, then >>>> you can end up with two instances of such a module, with all sorts >>>> of negative implications about global data or class attributes >>>> stored in that module, or even more subtle problems. >>>> >>>> For a final example, having a circular import tree can cause >>>> problems if any of those imports have any global code (like class >>>> initialization, defining constants, etc.). It's generally much >>>> better to define a strict hierarchy of who imports whom. -- DaveA From kemeniru at gmail.com Tue Mar 12 09:28:45 2013 From: kemeniru at gmail.com (Kene Meniru) Date: Tue, 12 Mar 2013 13:28:45 +0000 (UTC) Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> <513E8ECC.20805@davea.name> Message-ID: Dave Angel davea.name> writes: > > The __import__() function is defined > http://docs.python.org/2/library/functions.html#__import__ > Thanks. The name of the imported file will change with each user and for each project so according to the this reference using this in my situation makes sense. > appname = "myapp" > usermodule = __import__(appname, globals(), locals(), [], -1) > > And now you can use usermodule as though you had imported it in the > usual way. > Thanks. This worked! I was using __import__ without the other arguments before. I guess did not think it will work :-) > As for my other caveat, I've said it before in this thread. Make sure > you don't ever load a module by more than one name, or you'll end up > with a mess. And that includes the original script, which is loaded by > the name '__main__' > > You also should avoid any circular import, as it can be very tricky to > deal with them. > The two programs are separate, there is no fear of a circular import. Also, I need only a function to get access to the objects in the other module so the import is inside the function... no fear of ending up in a mess. Thanks. I guess this makes more sense than execfile and it works. From Kene.Meniru at illom.org Mon Mar 11 21:58:07 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Mon, 11 Mar 2013 21:58:07 -0400 Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> Message-ID: Dave Angel wrote: > On 03/11/2013 07:57 PM, Kene Meniru wrote: > > I hope you're just kidding. execfile() and exec() are two of the most > dangerous mechanisms around. import or __import__() would be much > better, as long as your user hasn't already run myapp.py as his script. > Tried __import__ and it seems to execute the myapp.py just like execfile however it only provides access to objects defined in the module myapp.py only. Like I mentioned, my program has multiple packages and the objects myappwin needs access to are stored in an object in another module called doc.py. - myapp.py provides the functions used to describe 3D objects - app.py is imported into myapp.py and is called by the functions after they create the 3D objects. - app.py uses another module called doc.py which app.py imports to save the objects in a class with a dictionary. - myappwin needs to access the dictionary in the class inside the doc module. -- Kene :::::::::::::::::: KeMeniru at gmail.com From davea at davea.name Mon Mar 11 22:16:17 2013 From: davea at davea.name (Dave Angel) Date: Mon, 11 Mar 2013 22:16:17 -0400 Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> Message-ID: <513E8FF1.10100@davea.name> On 03/11/2013 09:58 PM, Kene Meniru wrote: > Dave Angel wrote: > >> On 03/11/2013 07:57 PM, Kene Meniru wrote: > >> >> I hope you're just kidding. execfile() and exec() are two of the most >> dangerous mechanisms around. import or __import__() would be much >> better, as long as your user hasn't already run myapp.py as his script. >> > > Tried __import__ and it seems to execute the myapp.py just like execfile > however it only provides access to objects defined in the module myapp.py > only. Like I mentioned, my program has multiple packages and the objects > myappwin needs access to are stored in an object in another module called > doc.py. > > - myapp.py provides the functions used to describe 3D objects > - app.py is imported into myapp.py and is called by the functions after they > create the 3D objects. > - app.py uses another module called doc.py which app.py imports to save the > objects in a class with a dictionary. > - myappwin needs to access the dictionary in the class inside the doc > module. > If you need access to modules in your own framework, then import them yourself. You don't need any strange indirection through the myapp.py module. It's because you said that name was arbitrary and would change from run to run that we had to special case it. Same as you do with sys module in the standard library. It may get imported from dozens of places, and as long as they all import it by simple import sys there's no special problem accessing its globals. -- DaveA From torriem at gmail.com Tue Mar 12 00:05:07 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Mar 2013 22:05:07 -0600 Subject: Running external module and accessing the created objects In-Reply-To: <513E7B6B.5070608@davea.name> References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> Message-ID: <513EA973.7000705@gmail.com> On 03/11/2013 06:48 PM, Dave Angel wrote: > I hope you're just kidding. execfile() and exec() are two of the most > dangerous mechanisms around. import or __import__() would be much > better, as long as your user hasn't already run myapp.py as his script. It's not possible to setuid a python script, so I don't see how execfile or exec is any more dangerous than the user creating a shell script that rm -rf * things, and then running it. Bash "exec's" scripts all the time that users create and provide. How is this different and what issues did you have in mind, exactly? From davea at davea.name Tue Mar 12 07:20:07 2013 From: davea at davea.name (Dave Angel) Date: Tue, 12 Mar 2013 07:20:07 -0400 Subject: Running external module and accessing the created objects In-Reply-To: <513EA973.7000705@gmail.com> References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> <513EA973.7000705@gmail.com> Message-ID: <513F0F67.6010108@davea.name> On 03/12/2013 12:05 AM, Michael Torrie wrote: > On 03/11/2013 06:48 PM, Dave Angel wrote: >> I hope you're just kidding. execfile() and exec() are two of the most >> dangerous mechanisms around. import or __import__() would be much >> better, as long as your user hasn't already run myapp.py as his script. > > It's not possible to setuid a python script, so I don't see how execfile > or exec is any more dangerous than the user creating a shell script that > rm -rf * things, and then running it. > > Bash "exec's" scripts all the time that users create and provide. How > is this different and what issues did you have in mind, exactly? > Mainly that exec and execfile are a slippery slope for a new programmer. Once as they get it in their minds that this is the way to do things, they'll soon fall into using one of them on raw_input() data, on network data, and on other untrusted sources. -- DaveA From kemeniru at gmail.com Tue Mar 12 09:38:59 2013 From: kemeniru at gmail.com (Kene Meniru) Date: Tue, 12 Mar 2013 13:38:59 +0000 (UTC) Subject: Running external module and accessing the created objects References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <513E7B6B.5070608@davea.name> <513EA973.7000705@gmail.com> Message-ID: Michael Torrie gmail.com> writes: > It's not possible to setuid a python script, so I don't see how execfile > or exec is any more dangerous than the user creating a shell script that > rm -rf * things, and then running it. > > Bash "exec's" scripts all the time that users create and provide. How > is this different and what issues did you have in mind, exactly? > This is close to my reasoning too, although I appreciate Dave's concern. From rantingrickjohnson at gmail.com Tue Mar 12 02:40:48 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Mar 2013 23:40:48 -0700 (PDT) Subject: Running external module and accessing the created objects In-Reply-To: References: <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, March 11, 2013 6:57:28 PM UTC-5, Kene Meniru wrote: > > ------------------------------------------ > # contents of myapp.py > import math > > class MyApp(object): > def __init__(self): > super(MyApp, self).__init__() > self.name = "MyAppName" > > > def testFunction(): > boke = "Smilling" > print math.sin(1), boke > ----------------------------------------- > # contents of myappwin > def test(): > dic = {} > execfile("myapp.py", dic) > testObj = dic["MyApp"]() # access MyApp class > dic["testFunction"]() # execute testFunction > print testObj.name # print string > > > test() > ----------------------------------------- > # OUTPUT > $ python myappwin.py > 0.841470984808 Smilling > MyAppName Hmm. I don't understand why you think a simple old import won't work. Here is code (with names slightly adjusted for sanity). ============================================================ Contents of "mymodule.py" ============================================================ import math class Foo(object): def __init__(self): super(Foo, self).__init__() self.name = "MyAppName" def foo(): boke = "Smilling" print math.sin(1), boke ============================================================ Contents of "myscript.py" ============================================================ # This next import statement requires that a script named # "myapp.py" exist on the Python search path. If you cannot # bring the script into the search path, you can bring the # search path to the script by editing "sys.path". # # import sys # sys.path.append('foderContainingMyModule') # del sys # # But i would suggest placing the module on search path. from mymodule import Foo, foo def test(): ## dic = {} ## execfile("myapp.py", dic) ## testObj = dic["MyApp"]() # access MyApp class instance = Foo() ## dic["testFunction"]() # execute testFunction foo() ## print testObj.name # print string print instance.name if __name__ == '__main__': test() ============================================================ Results of running "myscript" ============================================================ 0.841470984808 Smilling MyAppName From charles.xrandolph2 at gmail.com Sat Mar 9 10:26:15 2013 From: charles.xrandolph2 at gmail.com (Owatch) Date: Sat, 9 Mar 2013 07:26:15 -0800 (PST) Subject: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Message-ID: I made a better chat client following help from people: They told me that if I didn't want to be blocked on .recv when waiting for messages, I would need to use threads, classes, functions, and queues to do so. So I followed some help a specific person gave me where I created a thread from a class and then defined a function that was supposed to read incoming messages and print them. I also created a function that allows you to enter stuff to be sent off. Thing is, when I run the program. Nothing happens. Can somebody help point out what is wrong? (I've asked questions and researched for 3 days, without getting anywhere, so I did try) from socket import * import threading import json import select print("Client Version 3") HOST = input("Connect to: ") PORT = int(input("On port: ")) # Create Socket s = socket(AF_INET,SOCK_STREAM) s.connect((HOST,PORT)) print("Connected to: ",HOST,) #-------------------Need 2 threads for handling incoming and outgoing messages-- # 1: Create out_buffer: Buffer = [] rlist,wlist,xlist = select.select([s],Buffer,[]) class Incoming(threading.Thread): # made a function a thread def Incoming_messages(): while True: for i in rlist: data = i.recv(1024) if data: print(data.decode()) # Now for outgoing data. def Outgoing(): while True: user_input=("Your message: ") if user_input is True: Buffer += [user_input.encode()] for i in wlist: s.sendall(Buffer) Buffer = [] Thanks for taking a look, thanks also to Tony The Lion for suggesting this If the code isnt done right, here's a link to view it, and download: View: http://i1267.photobucket.com/albums/jj554/owatch/PPP_zps4beb891b.png Download: http://www.mediafire.com/?u51a9b5axfffoxl From bahamutzero8825 at gmail.com Sat Mar 9 11:35:49 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 09 Mar 2013 10:35:49 -0600 Subject: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads In-Reply-To: References: Message-ID: <513B64E5.1050202@gmail.com> On 2013.03.09 09:26, Owatch wrote: > Thing is, when I run the program. Nothing happens. > > Can somebody help point out what is wrong? (I've asked questions and researched for 3 days, without getting anywhere, so I did try) You defined a thread, but never created or started it. Also, why did you subclass threading.Thread? You also mentioned queues, but you didn't use them. Not tested, but shows the basics: import threading import queue import socket def process(): while alive: thing = things_to_process.get() # do stuff with the thing here things_to_process.task_done() alive = True host = 'localhost' port = 9999 things_to_process = queue.Queue() process_thread = threading.Thread(target=process) process_thread.start() sock = socket.socket() sock.connect((host, port)) while alive: try: data = sock.recv() except Exception: # should probably do different things for different errors in real code alive = False sock.close() process_thread.join() raise else: things_to_process.put(data) -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From charles.xrandolph2 at gmail.com Sat Mar 9 16:23:17 2013 From: charles.xrandolph2 at gmail.com (Owatch) Date: Sat, 9 Mar 2013 13:23:17 -0800 (PST) Subject: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads References: Message-ID: On Mar 9, 6:35?pm, Andrew Berg wrote: > On 2013.03.09 09:26, Owatch wrote:> Thing is, when I run the program. Nothing happens. > > > Can somebody help point out what is wrong? (I've asked questions and researched for 3 days, without getting anywhere, so I did try) > > You defined a thread, but never created or started it. Also, why did you > subclass threading.Thread? You also mentioned queues, but you didn't use > them. > > Not tested, but shows the basics: > > import threading > import queue > import socket > > def process(): > ? while alive: > ? ? thing = things_to_process.get() > ? ? # do stuff with the thing here > ? ? things_to_process.task_done() > > alive = True > host = 'localhost' > port = 9999 > things_to_process = queue.Queue() > process_thread = threading.Thread(target=process) > process_thread.start() > sock = socket.socket() > sock.connect((host, port)) > while alive: > ? try: > ? ? data = sock.recv() > ? except Exception: # should probably do different things for different > errors in real code > ? ? alive = False > ? ? sock.close() > ? ? process_thread.join() > ? ? raise > ? else: > ? ? things_to_process.put(data) > > -- > CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 Thanks. From redstone-cold at 163.com Sat Mar 9 10:36:08 2013 From: redstone-cold at 163.com (iMath) Date: Sat, 9 Mar 2013 07:36:08 -0800 (PST) Subject: read and write the same text file Message-ID: read and write the same text file Open a text file ,read the content ,then make some change on it ,then write it back to the file ,now the modified text should only has the modified content but not the initial content ,so can we implement this by only set the mode parameter with open() function ?if yes ,what the parameter should be ?if no ,can we implement this by only one with statement ? I implement this with 2 with statement as the following replace_pattern = re.compile(r"<.+?>",re.DOTALL) def text_process(file): with open(file,'r') as f: text = f.read() with open(file,'w') as f: f.write(replace_pattern.sub('',text)) From roy at panix.com Sat Mar 9 10:47:34 2013 From: roy at panix.com (Roy Smith) Date: Sat, 09 Mar 2013 10:47:34 -0500 Subject: read and write the same text file References: Message-ID: In article , iMath wrote: > read and write the same text file > Open a text file ,read the content ,then make some change on it ,then write > it back to the file ,now the modified text should only has the modified > content but not the initial content ,so can we implement this by only set the > mode parameter with open() function ?if yes ,what the parameter should be ?if > no ,can we implement this by only one with statement ? > I implement this with 2 with statement as the following > > replace_pattern = re.compile(r"<.+?>",re.DOTALL) > > def text_process(file): > > with open(file,'r') as f: > text = f.read() > > with open(file,'w') as f: > f.write(replace_pattern.sub('',text)) At a minimum, you need to close the file after you read it and before you re-open it for writing. There's a variety of ways you could achieve the same effect. You might open the file once, in read-write mode, read the contents, rewind to the beginning with seek(), then write the new contents. You might also write the modified data out to a new file, close it, and then rename it. But, open, read, close, open, write, close is the most straight-forward. From steve+comp.lang.python at pearwood.info Sat Mar 9 22:45:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 03:45:19 GMT Subject: read and write the same text file References: Message-ID: <513c01cf$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sat, 09 Mar 2013 10:47:34 -0500, Roy Smith wrote: > In article , > iMath wrote: >> def text_process(file): >> with open(file,'r') as f: >> text = f.read() >> with open(file,'w') as f: >> f.write(replace_pattern.sub('',text)) > > At a minimum, you need to close the file after you read it and before > you re-open it for writing. The "with" statement automatically does that. When the indented block -- in this case, a single line "text = f.read()" -- completes, f.close() is automatically called. Technically, this is a property of file objects, not the with statement. The with statement merely calls the magic __exit__ method, which for file objects closes the file. > There's a variety of ways you could achieve the same effect. You might > open the file once, in read-write mode, read the contents, rewind to the > beginning with seek(), then write the new contents. You might also > write the modified data out to a new file, close it, and then rename it. > But, open, read, close, open, write, close is the most straight-forward. All of those techniques are acceptable for quick and dirty scripts. But for professional applications, you want something which is resistant to data loss. The problems happens when you do this: 1. Read file. 2. Modify data. 3. Open file for writing. # This deletes contents of the file! 4. Write data. 5. Flush data to the hard drive. Notice that there is a brief time frame where the old data is destroyed, but the new data hasn't been saved to the hard drive yet. This is where you can get data loss if, say, the power goes off. So a professional-quality application should do something like this: 1. Read file. 2. Modify data. 3. Open a new file for writing. 4. Write data to this new file. 5. Flush data to the hard drive. 6. Atomically replace the original file with the new file. Since sensible operating systems promise to be able to replace as a single atomic step, guaranteed to either fully succeed or not occur at all, this reduces the risk of data corruption or data loss significantly. Even if you're using an OS that doesn't guarantee atomic replacement *cough* Windows *cough* it still decreases the risk of data loss, just not as much as we would like. But having said all that, for "normal" use, a simple read-write cycle is still pretty safe, and it's *much* simpler to get right. -- Steven From james.harris.1 at gmail.com Sat Mar 9 11:21:06 2013 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 9 Mar 2013 11:21:06 EST Subject: RFD: comp.sys.raspberry-pi Message-ID: REQUEST FOR DISCUSSION (RFD) unmoderated group comp.sys.raspberry-pi This is a formal Request for Discussion (RFD) for the creation of the unmoderated newsgroup comp.sys.raspberry-pi. NEWSGROUPS LINE: comp.sys.raspberry-pi Raspberry Pi computers & related hardware and software. RATIONALE: * Discussions on this topic have so far been widely and thinly spread on Usenet - e.g. google site:groups.google.com/group/comp "raspberry pi" * Device has been on sale for over a year (since 29 Feb 2012) * Circa 1 million units sold so far - http://www.wired.com/design/2013/01/raspberry-pi-million-boards/ * The maker's web forum, while it is a web site and not Usenet, currently reports over 299,000 posts and 33,000 threads giving an indication of the levels of interest in discussion - http://www.raspberrypi.org/phpBB3/ * The Raspberry Pi is complex and used by communities having technical issues to discuss * Various third-party add-ons are available * The device has some distinctive features, e.g., * Low cost - base retail prices US$25/35 depending on model * Header for interfacing with external electronics * Can generate 1080p30 High Definition video * For further specs see http://en.wikipedia.org/wiki/Raspberry_Pi * People have been using the device for a variety of unusual purposes - http://www.raspberrypi.org/phpBB3/viewforum.php?f=15 All-in-all there seems to be many reasons why a Usenet group would be well used but to allow the Big 8 Management Board to make an informed decision if you would read and/or post to the proposed newsgroup please indicate your interest by replying on this thread. Followups are set to news.groups.proposals where discussions about the proposal can be carried out. CHARTER: Newsgroup comp.sys.raspberry-pi is for discussion of issues connected with Raspberry Pi computer systems including set up, programming, software, operating systems, interfacing, related hardware and projects. Posters are expected to abide by normal Usenet standards of decorum, and to ignore articles intended to disrupt the group. The usual suspects are prohibited (spam, binaries, direct advertising, etc.) PROCEDURE: For more information on the newsgroup creation process, please see: http://www.big-8.org/dokuwiki/doku.php?id=policies:creation Those who wish to influence the development of this RFD and its final resolution should subscribe to news.groups.proposals and participate in the relevant threads in that newsgroup. This is both a courtesy to groups in which discussion of creating a new group is off-topic as well as the best method of making sure that one's comments or criticisms are heard. All discussion of active proposals should be posted to news.groups.proposals To this end, the followup header of this RFD has been set to news.groups.proposals. If desired by the readership of closely affected groups, the discussion may be crossposted to those groups, but care must be taken to ensure that all discussion appears in news.groups.proposals as well. We urge those who would like to read or post in the proposed newsgroup to make a comment to that effect in this thread; we ask proponents to keep a list of such positive posts with the relevant message ID: Barney Fife, <4jgdnb60fsmzha7znz2dnuvz_rwdnz2d at sysmatrix.net>) Such lists of positive feedback for the proposal may constitute good evidence that the group will be well-used if it is created. DISTRIBUTION: This document has been posted to the following newsgroups: news.announce.newgroups news.groups.proposals comp.lang.forth comp.lang.python comp.os.linux.misc PROPONENT: James Harris james.harris.1Agmail.com (replace A with @ - but please discuss the proposal on Usenet!) CHANGE HISTORY: 2013-03-09 Initial RFD From board at big-8.org Sat Mar 16 03:02:06 2013 From: board at big-8.org (Big 8 Management Board) Date: Sat, 16 Mar 2013 03:02:06 EDT Subject: 2nd RFD: comp.sys.raspberry-pi - LAST CALL FOR COMMENTS References: Message-ID: SECOND REQUEST FOR DISCUSSION (RFD) unmoderated group comp.sys.raspberry-pi LAST CALL FOR COMMENTS This is a formal Request for Discussion (RFD) for the creation of the unmoderated newsgroup comp.sys.raspberry-pi. NEWSGROUPS LINE: comp.sys.raspberry-pi Raspberry Pi computers & related hardware and software RATIONALE: * Discussions on this topic have so far been widely and thinly spread on Usenet - e.g. google site:groups.google.com/group/comp "raspberry pi" * The RFD (published 9 March 2013) was well supported with positive responses CHARTER: Newsgroup comp.sys.raspberry-pi is for discussion of issues connected with Raspberry Pi computer systems including set up, programming, software, operating systems, interfacing, related hardware and projects. Posters are expected to abide by normal Usenet standards of decorum, and to ignore articles intended to disrupt the group. The usual suspects are prohibited (spam, binaries, direct advertising, etc.) PROCEDURE: Please refer to the newsgroup creation policies listed here: http://www.big-8.org/wiki/How_to_Create_a_New_Big-8_Newsgroup All discussion of active proposals should be posted to news.groups.proposals. To this end, the followup header of this RFD has been set to news.groups.proposals. The final comment period lasts for five (5) days from the time that this RFD is posted. DISTRIBUTION: This document has been posted to the following newsgroups: news.announce.newgroups news.groups.proposals comp.lang.forth comp.lang.python comp.os.linux.misc Pointers will also be posted to: comp.arch.embedded uk.comp.homebuilt uk.comp.os.linux comp.sys.apple2 PROPONENT: James Harris james.harris.1Agmail.com (replace A with @) CHANGE HISTORY: 2013-03-09 Initial RFD 2013-03-16 This LCC From board at big-8.org Sat Mar 30 03:46:39 2013 From: board at big-8.org (Big 8 Management Board) Date: Sat, 30 Mar 2013 03:46:39 EDT Subject: RESULT: comp.sys.raspberry-pi will be created References: Message-ID: RESULT unmoderated group comp.sys.raspberry-pi The Last Call for Comments (LCC) on 2013-03-16 initiated a five-day period for final comments. Following this comment period, the Big-8 Management Board has decided by consensus to create unmoderated newsgroup comp.sys.raspberry-pi. NEWSGROUPS LINE: comp.sys.raspberry-pi Raspberry Pi computers & related hardware and software CHARTER: Newsgroup comp.sys.raspberry-pi is for discussion of issues connected with Raspberry Pi computer systems including set up, programming, software, operating systems, interfacing, related hardware and projects. Posters are expected to abide by normal Usenet standards of decorum, and to ignore articles intended to disrupt the group. The usual suspects are prohibited (spam, binaries, direct advertising, etc.) DISTRIBUTION: This document has been posted to the following newsgroups: news.announce.newgroups news.groups.proposals comp.lang.forth comp.lang.python comp.os.linux.misc PROPONENT: James Harris james.harris.1Agmail.com (replace A with @) CHANGE HISTORY: 2013-03-09 Initial RFD 2013-03-16 2nd RFD/LCC 2013-03-30 RESULT From gosinn at gmail.com Sat Mar 9 13:49:22 2013 From: gosinn at gmail.com (gosinn at gmail.com) Date: Sat, 9 Mar 2013 10:49:22 -0800 (PST) Subject: Calling J from Python In-Reply-To: <1170686928.985128.16720@h3g2000cwc.googlegroups.com> References: <1170686928.985128.16720@h3g2000cwc.googlegroups.com> Message-ID: <61386d55-4497-4ea2-9070-b60f0c8509fe@googlegroups.com> Den m?ndagen den 5:e februari 2007 kl. 14:48:49 UTC skrev Gosi: > It is quite easy to call J from Python > > http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e http://www.jsoftware.com/jwiki/Scripts/qjide From breamoreboy at yahoo.co.uk Sat Mar 9 14:34:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 09 Mar 2013 19:34:09 +0000 Subject: Calling J from Python In-Reply-To: <61386d55-4497-4ea2-9070-b60f0c8509fe@googlegroups.com> References: <1170686928.985128.16720@h3g2000cwc.googlegroups.com> <61386d55-4497-4ea2-9070-b60f0c8509fe@googlegroups.com> Message-ID: On 09/03/2013 18:49, gosinn at gmail.com wrote: > Den m?ndagen den 5:e februari 2007 kl. 14:48:49 UTC skrev Gosi: >> It is quite easy to call J from Python >> >> http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e > > http://www.jsoftware.com/jwiki/Scripts/qjide > Got a right slagging six years ago when first posted, what's changed to make it worth evaluating? -- Cheers. Mark Lawrence From gosinn at gmail.com Sun Mar 10 04:30:26 2013 From: gosinn at gmail.com (gosinn at gmail.com) Date: Sun, 10 Mar 2013 00:30:26 -0800 (PST) Subject: Calling J from Python In-Reply-To: References: <1170686928.985128.16720@h3g2000cwc.googlegroups.com> <61386d55-4497-4ea2-9070-b60f0c8509fe@googlegroups.com> Message-ID: Den l?rdagen den 9:e mars 2013 kl. 19:34:09 UTC skrev Mark Lawrence: > On 09/03/2013 18:49, gosinn at gmail.com wrote: > > > Den m?ndagen den 5:e februari 2007 kl. 14:48:49 UTC skrev Gosi: > > >> It is quite easy to call J from Python > > >> > > >> http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e > > > > > > http://www.jsoftware.com/jwiki/Scripts/qjide > > > > > > > Got a right slagging six years ago when first posted, what's changed to > > make it worth evaluating? > > > > -- > > Cheers. > > > > Mark Lawrence A lot has changed these last six years. By the way Python 2.5 and Python 3.3 will not work with the example. Python 2.7 does not work in Vista unchanged (neither does Python 3.3) but after change will run the demo and some examples. J is now open source and has more platforms and guis. From gosinn at gmail.com Sun Mar 10 04:30:26 2013 From: gosinn at gmail.com (gosinn at gmail.com) Date: Sun, 10 Mar 2013 00:30:26 -0800 (PST) Subject: Calling J from Python In-Reply-To: References: <1170686928.985128.16720@h3g2000cwc.googlegroups.com> <61386d55-4497-4ea2-9070-b60f0c8509fe@googlegroups.com> Message-ID: Den l?rdagen den 9:e mars 2013 kl. 19:34:09 UTC skrev Mark Lawrence: > On 09/03/2013 18:49, gosinn at gmail.com wrote: > > > Den m?ndagen den 5:e februari 2007 kl. 14:48:49 UTC skrev Gosi: > > >> It is quite easy to call J from Python > > >> > > >> http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e > > > > > > http://www.jsoftware.com/jwiki/Scripts/qjide > > > > > > > Got a right slagging six years ago when first posted, what's changed to > > make it worth evaluating? > > > > -- > > Cheers. > > > > Mark Lawrence A lot has changed these last six years. By the way Python 2.5 and Python 3.3 will not work with the example. Python 2.7 does not work in Vista unchanged (neither does Python 3.3) but after change will run the demo and some examples. J is now open source and has more platforms and guis. From olsr.kamal at gmail.com Sat Mar 9 14:47:43 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Sat, 9 Mar 2013 11:47:43 -0800 (PST) Subject: =?ISO-8859-1?Q?how_to_d=E9place_a_circle_in_canvas_python=3F?= Message-ID: <8989c2cd-0a17-44f2-9744-dbce2265dac3@googlegroups.com> how to diplace a circle in canvas tkinter python from position to an auther position by a mouse click 'press' 'relase' or by delete the d?plicated objects in canvas?? From rantingrickjohnson at gmail.com Sat Mar 9 15:54:47 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Mar 2013 12:54:47 -0800 (PST) Subject: =?ISO-8859-1?Q?Re=3A_how_to_d=E9place_a_circle_in_canvas_python=3F?= In-Reply-To: <8989c2cd-0a17-44f2-9744-dbce2265dac3@googlegroups.com> References: <8989c2cd-0a17-44f2-9744-dbce2265dac3@googlegroups.com> Message-ID: <4c61a0a4-83ae-48d9-8851-ad14499a61a6@googlegroups.com> On Saturday, March 9, 2013 1:47:43 PM UTC-6, olsr.... at gmail.com wrote: > how to [translate] a circle in canvas tkinter python from > [one] position to an [another] position Well "translation" is by definition: "changing an objects position" > by a mouse click 'press' ['release'] or by delete the [duplicated] objects > in canvas?? Here's an idea: how about you learn how to translate a Tkinter canvas object via code BEFORE you try to do it via user input? This is called "code evolution along an intelligent linear path", not some "random shots in the dark". How do you do this you ask, well i'll give you a hint, follow this yellow brick road for enlightenment. ============================================================ STEP 1 ============================================================ Take a look at the following methods available to the Tkinter canvas widget here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/canvas-methods.html Can you find a method that will "translate" or "displace" or (insert another synonym here), a canvas object by passing two (x,y) Cartesian coordinates? Once you can accomplish step 1, we can move on to step 2. ============================================================ STEP 2 ============================================================ Solving "Step 1" is compulsory! From nikos.gr33k at gmail.com Sat Mar 9 16:25:33 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 13:25:33 -0800 (PST) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: mail = form.getvalue('mail') id what the user types in an html form and click submits. this can be a non valid email of course i just check if there is a '@' in the mail address. But will the mail, gets delivered even if mail's value is invalid? From rosuav at gmail.com Sat Mar 9 17:15:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Mar 2013 09:15:33 +1100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: On Sun, Mar 10, 2013 at 8:25 AM, ????? ???33? wrote: > mail = form.getvalue('mail') > > id what the user types in an html form and click submits. this can be a non valid email of course i just check if there is a '@' in the mail address. > > But will the mail, gets delivered even if mail's value is invalid? I asked the postman to deliver a letter to Dreaded Batter Pudding Hurler, Bexhill-on-Sea, England 142857. Will that letter get delivered even if that address is invalid? Is email in any way magical and able to deliver mail to invalid values, whatever it is you mean by "value"? ChrisA From nikos.gr33k at gmail.com Sat Mar 9 23:42:03 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 20:42:03 -0800 (PST) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> Any ideas why the mail never gets delivered? From steve+comp.lang.python at pearwood.info Sun Mar 10 00:56:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 05:56:45 GMT Subject: This mail never gets delivered. Any ideas why? References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> Message-ID: <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sat, 09 Mar 2013 20:42:03 -0800, ????? ???33? wrote: > Any ideas why the mail never gets delivered? What do the mail logs say? Can you send email using this mail server from Thunderbird, or does it fail there too? My wild guess is that the mail server is properly rejecting mail because you are trying to send to it without an account. -- Steven From nikos.gr33k at gmail.com Sun Mar 10 01:00:39 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 22:00:39 -0800 (PST) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> ?? ???????, 10 ??????? 2013 7:56:45 ?.?. UTC+2, ? ??????? Steven D'Aprano ??????: > My wild guess is that the mail server is properly rejecting mail because > you are trying to send to it without an account. Account 'support(-at-)hostgator.com' exists. It's the recipient mail address which is my personal address fot my web hosting business. In TB yes i can read email via SSL witohut any problem. From nikos.gr33k at gmail.com Sun Mar 10 06:19:25 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 10 Mar 2013 03:19:25 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> Message-ID: Anyone else migth ahve an idea please so that i can successfully send mail via python? From steve+comp.lang.python at pearwood.info Sun Mar 10 06:37:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 10:37:00 GMT Subject: This mail never gets delivered. Any ideas why? References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> Message-ID: <513c624c$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sat, 09 Mar 2013 22:00:39 -0800, ????? ???33? wrote: > ?? ???????, 10 ??????? 2013 7:56:45 ?.?. UTC+2, ? ??????? Steven > D'Aprano ??????: > >> My wild guess is that the mail server is properly rejecting mail >> because you are trying to send to it without an account. > > Account 'support(-at-)hostgator.com' exists. It's the recipient mail > address which is my personal address fot my web hosting business. > > In TB yes i can read email via SSL witohut any problem. I didn't ask if you can READ email using Thunderbird, I asked if you can SEND email using Thunderbird, *specifically* sending using the same mail server as your script is trying to do. There is no point checking that Thunderbird can send email as "nikos.gr33k at gmail.com" using the gmail server. You have to check whether it can send email as "mail" (notice that it is just a local name, not a full email address), using /usr/sbin/sendmail on whatever machine you happen to be using. A second question... what happens if you try to send email using sendmail directly from the command line? If this is a hosted server, are you sure that they have enabled sendmail on the hosted server? What happens if you try to send email using the email library, as seen here: http://docs.python.org/3/library/email-examples.html instead of using popen to talk directly to sendmail? -- Steven From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 11 18:34:50 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Mar 2013 23:34:50 +0100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <08433d4e-6ffb-4929-a708-f8ba1d670449@googlegroups.com> References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> <513c624c$0$6512$c3e8da3$5496439d@news.astraweb.com> <08433d4e-6ffb-4929-a708-f8ba1d670449@googlegroups.com> Message-ID: Am 10.03.2013 19:39 schrieb ????? ???33?: > Hey man this worked via Python! [...] > if( os.system( 'echo "%s" | mail -s "%s" support at superhost.gr' % (MESSAGE, FROM) ) ): [...] > Thank you! I beleive this is the simplest way of sending an email! Until you get a MESSAGE which has a " sign in it, or a FROM. (Sorry, didn't see this message before.) In order to prevent trouble with this, it might be better to use subprocess and to do sp = subprocess.Popen(['mail', '-f', FROM, '-s', SUBJECT, 'support at superhost.gr], stdin=subprocess.PIPE) sp.communicate(MESSAGE) res = sp.wait() if res: ... else: ... If you do so, you can have FROMs, SUBJECTs and MESSAGEs conaining every character you want, including " and ', an no shell will complain about it or be confused. (Note that I changed the arguments for mail a little bit, because -s prevedes the subject and -f the from.) Thomas From nikos.gr33k at gmail.com Tue Mar 26 04:49:22 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 26 Mar 2013 01:49:22 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> <513c624c$0$6512$c3e8da3$5496439d@news.astraweb.com> <08433d4e-6ffb-4929-a708-f8ba1d670449@googlegroups.com> Message-ID: ?? ?????, 12 ??????? 2013 12:34:50 ?.?. UTC+2, ? ??????? Thomas Rachel ??????: > Am 10.03.2013 19:39 schrieb ??????????????? ?????????33???: > > > Hey man this worked via Python! > > > > [...] > > > > > if( os.system( 'echo "%s" | mail -s "%s" support at superhost.gr' % (MESSAGE, FROM) ) ): > > > > [...] > > > > > Thank you! I beleive this is the simplest way of sending an email! > > > > Until you get a MESSAGE which has a " sign in it, or a FROM. > > > > (Sorry, didn't see this message before.) > > > > In order to prevent trouble with this, it might be better to use > > subprocess and to do > > > > sp = subprocess.Popen(['mail', '-f', FROM, '-s', SUBJECT, > > 'support at superhost.gr], stdin=subprocess.PIPE) > > sp.communicate(MESSAGE) > > res = sp.wait() > > if res: > > ... > > else: > > ... > > > > > > If you do so, you can have FROMs, SUBJECTs and MESSAGEs conaining every > > character you want, including " and ', an no shell will complain about > > it or be confused. > > > > (Note that I changed the arguments for mail a little bit, because -s > > prevedes the subject and -f the from.) > > > > > > Thomas Hello and sorry for beign so much late to respond. Yout solution is clearly betetr than the simple mail solution i found to be working but i think subprocess requires that i use Python3 interpeter which of course my web host supports, but it would fail running my MYSQLdbd module. So is there still a way to use your solution? From nikos.gr33k at gmail.com Tue Mar 26 06:26:15 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 26 Mar 2013 03:26:15 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: <10f30df1-e0f8-4834-ae5f-b6e0d0aac079@googlegroups.com> <513c209d$0$6512$c3e8da3$5496439d@news.astraweb.com> <3daebceb-88e2-4d0b-bc32-802e6cece93e@googlegroups.com> <513c624c$0$6512$c3e8da3$5496439d@news.astraweb.com> <08433d4e-6ffb-4929-a708-f8ba1d670449@googlegroups.com> Message-ID: <37ba3304-a18e-4a5a-86f5-033b449eb76f@googlegroups.com> Because Python 3 doesnt support MySQLdb moudle yet i decided to use mypysql-0.5.5.tar.gz which i found in google. problem is that i dont know how to run this file in my webost account so it cant be utilized and so i can pass to Python 3 at last. i ahve uplaoded the file viua cPnael in webhost but then what? How doi "embed" this in python so to make use of it? From torriem at gmail.com Sun Mar 10 00:07:25 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 09 Mar 2013 22:07:25 -0700 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: <513C150D.1040105@gmail.com> On 03/09/2013 02:25 PM, ????? ???33? wrote: > mail = form.getvalue('mail') > > id what the user types in an html form and click submits. this can be > a non valid email of course i just check if there is a '@' in the > mail address. > > But will the mail, gets delivered even if mail's value is invalid? Who knows. You haven't specified how you are sending e-mail. Likely, if an e-mail address is invalid, python still happily hands it off to your designated mail server or local MTA (mail transfer agent--could be sendmail). What happens there depends entirely on the policies of the mail server or MTA you are using. If python is trying to use sendmail, then probably the process would just fail and return some sort of error code. But you will need to check on the documentation of whatever e-mail library you are using in Python. From nikos.gr33k at gmail.com Sun Mar 10 00:10:36 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 21:10:36 -0800 (PST) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> ?? ???????, 10 ??????? 2013 7:07:25 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 03/09/2013 02:25 PM, ????? ???33? wrote: > > > mail = form.getvalue('mail') > > > > > > id what the user types in an html form and click submits. this can be > > > a non valid email of course i just check if there is a '@' in the > > > mail address. > > > > > > But will the mail, gets delivered even if mail's value is invalid? > > > > Who knows. You haven't specified how you are sending e-mail. Likely, if > > an e-mail address is invalid, python still happily hands it off to your > > designated mail server or local MTA (mail transfer agent--could be > > sendmail). What happens there depends entirely on the policies of the > > mail server or MTA you are using. > > > > If python is trying to use sendmail, then probably the process would > > just fail and return some sort of error code. But you will need to > > check on the documentation of whatever e-mail library you are using in > > Python. I'am using smtplib and i ahve contacted the hostgator administrators and they say that Sendmail is ebaled for my reseller account. From nikos.gr33k at gmail.com Sun Mar 10 00:10:36 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sat, 9 Mar 2013 21:10:36 -0800 (PST) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> ?? ???????, 10 ??????? 2013 7:07:25 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > On 03/09/2013 02:25 PM, ????? ???33? wrote: > > > mail = form.getvalue('mail') > > > > > > id what the user types in an html form and click submits. this can be > > > a non valid email of course i just check if there is a '@' in the > > > mail address. > > > > > > But will the mail, gets delivered even if mail's value is invalid? > > > > Who knows. You haven't specified how you are sending e-mail. Likely, if > > an e-mail address is invalid, python still happily hands it off to your > > designated mail server or local MTA (mail transfer agent--could be > > sendmail). What happens there depends entirely on the policies of the > > mail server or MTA you are using. > > > > If python is trying to use sendmail, then probably the process would > > just fail and return some sort of error code. But you will need to > > check on the documentation of whatever e-mail library you are using in > > Python. I'am using smtplib and i ahve contacted the hostgator administrators and they say that Sendmail is ebaled for my reseller account. From torriem at gmail.com Sun Mar 10 12:09:53 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Mar 2013 10:09:53 -0600 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> References: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> Message-ID: <513CB051.3000106@gmail.com> On 03/09/2013 10:10 PM, ????? ???33? wrote: > I'am using smtplib and i ahve contacted the hostgator administrators > and they say that Sendmail is ebaled for my reseller account. You need to post the code snippet that's failing (possibly changing private details like smtp server ip address for security reasons), and any exception trace that you are getting! Other wise, sorry we've done all we can. From nikos.gr33k at gmail.com Sun Mar 10 13:53:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 10 Mar 2013 10:53:57 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> Message-ID: <3de79596-4578-4265-afce-af04751805ef@googlegroups.com> ?? ???????, 10 ??????? 2013 6:09:53 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > You need to post the code snippet that's failing (possibly changing > private details like smtp server ip address for security reasons), and > any exception trace that you are getting! Other wise, sorry we've done > all we can. Michael may i send you an email with my reseller account password so you can try things for yourself because i'am not sure what exactly i must do in the remote jailed unix prompt ? From nikos.gr33k at gmail.com Sun Mar 10 13:53:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 10 Mar 2013 10:53:57 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> Message-ID: <3de79596-4578-4265-afce-af04751805ef@googlegroups.com> ?? ???????, 10 ??????? 2013 6:09:53 ?.?. UTC+2, ? ??????? Michael Torrie ??????: > You need to post the code snippet that's failing (possibly changing > private details like smtp server ip address for security reasons), and > any exception trace that you are getting! Other wise, sorry we've done > all we can. Michael may i send you an email with my reseller account password so you can try things for yourself because i'am not sure what exactly i must do in the remote jailed unix prompt ? From torriem at gmail.com Sun Mar 10 22:20:35 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Mar 2013 20:20:35 -0600 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <3de79596-4578-4265-afce-af04751805ef@googlegroups.com> References: <475a8e9c-5645-475f-8107-013027884e63@googlegroups.com> <3de79596-4578-4265-afce-af04751805ef@googlegroups.com> Message-ID: <513D3F73.6010407@gmail.com> On 03/10/2013 11:53 AM, ????? ???33? wrote: > Michael may i send you an email with my reseller account password so > you can try things for yourself because i'am not sure what exactly i > must do in the remote jailed unix prompt ? It's never a good idea to share that kind of information with folks on the internet. Your subject line reads: "this mail never gets delivered." What e-mail? What code did you use to send this e-mail? What happened? What exceptions, if any were given. I know there's a language barrier here, but you definitely make a habit of not providing us with sufficient details to help you get your code working. From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 11 01:25:56 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Mar 2013 06:25:56 +0100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: Am 09.03.2013 22:20 schrieb ????? ???33?: > SENDMAIL = '/usr/sbin/sendmail' > > FROM = mail > TO = ['support at superhost.gr'] > SUBJECT = "??????????? ??????? ??????!" > TEXT = comment > > message = """\ > From: %s > To: %s > Subject: %s > > %s > """ % (FROM, ", ".join(TO), SUBJECT, TEXT) > > p = os.popen("%s -t -i" % SENDMAIL, "w") > p.write(message) > status = p.close() > if status != 256: > print( "

    ????????? ???? ??? ?? ??????????! ?? ???????????? ???? ??? ????? :-)

    " ) > else: > print( "

    ???????? ??? ??????? ?? ????????? ?? e-mail :-(" ) > > =============== > > Do you see somehtign wrong in the above code? > I see some things here: 1. Your subject is not properly encoded. All characters outside the ASCII area must be encoded in an appropriate way if you send an email. It MIGHT be the case that sendmail handles this for you, but probably not every version. But that should not prevent sending the mail at all; probably some garbage would result. 2. You failed to tell us what "never gets delivered" means: do you get an error message? 3. You failed to give us a SSCCE : in order to test the code, I had to add several variable definitions and imports. 4., an I thik this is the point: you are indenting your message string. If you put a print(message) somewhere into the code, you'll see that the email header lines don't start with the header names, but with spaces. That is something which sendmail cannot and won't handle. Likewise, the header-body-separator is probably broken as well. Just write, even if your code is indented in some way: message = """\ From: %s To: %s Subject: %s %s""" % (FROM, ", ".join(TO), SUBJECT, TEXT) or maybe, just to be sure, message = "From: %s\nTo: %s\nSubject: %s\n\n%s" % \ (FROM, ", ".join(TO), SUBJECT, TEXT) in order to get a useful result. And, as you are working on it, don't use os.popen - it is deprecated. Better use subprocess: replace p = os.popen("%s -t -i" % SENDMAIL, "w") p.write(message) status = p.close() with import subprocess sp = subprocess.Popen([SENDMAIL, '-t', '-i'], stdin=subprocess.PIPE) sp.communicate(message) status = sp.wait() giving more flexibility. HTH, Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 11 01:47:44 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Mar 2013 06:47:44 +0100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: Am 11.03.2013 06:25 schrieb Thomas Rachel: > 1. Your subject is not properly encoded. > > All characters outside the ASCII area must be encoded in an appropriate > way if you send an email. It MIGHT be the case that sendmail handles > this for you, but probably not every version. Mine not, at least. So you should do this: import email message = email.message_from_string('') message.add_header('From', FROM) message.add_header('To', ", ".join(TO)) # and then # either message.add_header('Subject', email.quoprimime.header_encode(SUBJECT)) # or message.add_header('Subject', email.base64mime.header_encode(SUBJECT)) # Here you should decide upon readability: for Greek text, base64 is # probably better, while for languages with Latin characters, quopri # is better because bost characters remain readable. # # The difference is # # Subject: =?iso-8859-1?q?=CE=95=CF=80=CE=B9=CE=BA=CE=BF=CE=B9=CE=BD=CF=89=CE=BD=CE?= # =?iso-8859-1?q?=AF=CE=B1_=CF=80=CE=B9=CE=B8=CE=B1=CE=BD=CE=BF=CF=8D_=CF?= # =?iso-8859-1?q?=80=CE=B5=CE=BB=CE=AC=CF=84=CE=B7!?= # # vs. # # Subject: =?iso-8859-1?b?zpXPgM65zrrOv865zr3Pic69zq/OsSDPgM65zrjOsc69zr/PjSDPgM61zrs=?= # =?iso-8859-1?b?zqzPhM63IQ==?= # # # If your sender or your recipients have names outside the ASCII area, # you should quote them as well. # These are for the text. message.add_header('MIME-Version', '1.0') message.add_header('Content-Type', 'text/plain; charset=utf8') message.add_header('Content-Transfer-Encoding', '8bit') message.set_payload(TEXT) # now transform the object into a string: message = message.as_string() print message This message string now can be used for sending. HTH, Thomas From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 11 01:59:52 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Mar 2013 06:59:52 +0100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: Am 11.03.2013 06:47 schrieb Thomas Rachel: > # either > message.add_header('Subject', email.quoprimime.header_encode(SUBJECT)) > > # or > message.add_header('Subject', email.base64mime.header_encode(SUBJECT)) Sorry! These were completely wrong. # either message.add_header('Subject', email.quoprimime.header_encode(SUBJECT, charset='utf8')) # or message.add_header('Subject', email.base64mime.header_encode(SUBJECT, charset='utf8')) should be correct, however. But be aware that both seem to potentially break the UTF8 surrogates apart, which in turn confuses at least Thunderbird, so it might not be the ideal solution. Maybe you transcode the subject into iso-8859-7 and declare it as such, if you only have greek characters. Let's try: [...] # and then # either enc = email.base64mime.header_encode # or enc = email.quoprimime.header_encode message.add_header('Subject', enc( SUBJECT.decode('utf8').encode('iso-8859-7'), charset='iso-8859-7')) I tried both values for enc(), and both seem to work with the subject string you provided. HTH, Thomas From nagia.retsina at gmail.com Mon Mar 11 05:15:29 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Mon, 11 Mar 2013 02:15:29 -0700 (PDT) Subject: This mail never gets delivered. Any ideas why? In-Reply-To: References: Message-ID: <41f45d68-4669-4c51-ae60-d2f22ddf244b@googlegroups.com> Thank you Thomas but that simple line as i have it now its capable of sending mail successfully wven with greek letters two in subject or in message variables. Now need to dad additional extra code for it to work. From benjamin at schollnick.net Mon Mar 11 06:44:03 2013 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Mon, 11 Mar 2013 06:44:03 -0400 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <41f45d68-4669-4c51-ae60-d2f22ddf244b@googlegroups.com> References: <41f45d68-4669-4c51-ae60-d2f22ddf244b@googlegroups.com> Message-ID: <3651E2AF-C5EE-42D0-9C5B-273A32251367@schollnick.net> Nagia, > Thank you Thomas but that simple line as i have it now its capable of sending mail successfully wven with greek letters two in subject or in message variables. > > Now need to dad additional extra code for it to work. Your code as it is, isn't working. They just sent you several suggestions on why it might not be working, and your not even testing to see if it might work better, or assist in tracking down the problem? Even if these suggestions were completely unfounded, are they more readable then your existing code? Or more standards compliant? If you wish to receive help, please at least try to work with the people that are trying to help you. Otherwise, you'll end up with someone helping you that won't have your best interests in mind. - Benjamin -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 11 12:24:04 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 11 Mar 2013 17:24:04 +0100 Subject: This mail never gets delivered. Any ideas why? In-Reply-To: <41f45d68-4669-4c51-ae60-d2f22ddf244b@googlegroups.com> References: <41f45d68-4669-4c51-ae60-d2f22ddf244b@googlegroups.com> Message-ID: Am 11.03.2013 10:15 schrieb nagia.retsina at gmail.com: > Thank you Thomas but that simple line as i have it now its capable of > sending mail successfully Obviously not, otherwise you wouldn't ask, would you? Thomas From mpc8250 at gmail.com Sat Mar 9 17:00:39 2013 From: mpc8250 at gmail.com (Z W) Date: Sat, 9 Mar 2013 14:00:39 -0800 Subject: pexpect on windows - child process of another child process - quick question Message-ID: Hi All We have a windows application to install on console mode typing on cygwin shell "app.exe -i console" On Windows process window, we could see this kicks a process named ia which in turn kicks off ia_launcher to kick off another java.exe process. ie app.exe -- kick off --> ia --> kicks off --> ia_launcher --kicks off --> java.exe We like to use pexpect to interact with the ia_launcher process, which seems to control the stdin/stdout of its own shell window to allow user to enter responses. So far, our research shows most examples are related to use of direct child process, in this case, app.exe process interacting with pexpect. How do we go about using pexpect to talk to app.exe's grandchild's shell window ? We set Don L's expect example where he could "set id $spawn_id" between direct child processes but it's still to us how we can accomplish our goal. Thanks for your kind help Sincerely From olsr.kamal at gmail.com Sat Mar 9 17:46:40 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Sat, 9 Mar 2013 14:46:40 -0800 (PST) Subject: =?ISO-8859-1?Q?how_to_get_id_of_a_line_from_his_coordon=E9e_in_tkint?= =?ISO-8859-1?Q?er_python=3F?= Message-ID: how to get id of a line from his coordon?e in tkinter python? From rantingrickjohnson at gmail.com Sat Mar 9 18:40:45 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Mar 2013 15:40:45 -0800 (PST) Subject: =?ISO-8859-1?Q?Re=3A_how_to_get_id_of_a_line_from_his_coordon=E9e_in_t?= =?ISO-8859-1?Q?kinter_python=3F?= In-Reply-To: References: Message-ID: <85f0602a-9626-4aea-a690-6b2e22193340@googlegroups.com> On Saturday, March 9, 2013 4:46:40 PM UTC-6, olsr.... at gmail.com wrote: > how to get id of a line from his coordon?e in tkinter python? Each time you create a "canvas item", be it a rectangle, line, circle, or whatever..., the id of that object is returned as an integer. All you have to do is save the id into a variable. rectID = canvas.create_rectangle(...) Now you can pass that unique id into many of the methods that exist for "canvas items". canvas.delete(rectID) canvas.coords(rectID) canvas.bbox(rectID) *Sarcastic Sam quipped*: """Rick, not everybody can be as smart as you! What if we forgot to save the return value into a variable? Besides, you cannot expect us to create a variable to hold *every single* id of *every single* canvas object; that would be ridiculous!""" Indeed it would Sam. Besides, integer tags are not easy to remember, and they are created by the canvas object (which is out of your control). But before you throw the computer out the window, be aware that the canvas allows you to tag each "canvas item" by passing one or more strings, using the "tags=..." argument, into the "canvas.create_X(args)" methods. py> canvas.create_rectangle(0,0,10,10, fill='red', tags='red_rect') py> canvas.coords('red_rect') (0,0,10,10) PS: Hopefully you solved that other issue. From tjreedy at udel.edu Sat Mar 9 19:41:08 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Mar 2013 19:41:08 -0500 Subject: Building importable _tkinter on Windows Message-ID: If you have tried to build _tkinter on Windows from the cpython repository, and have 'import tkinter' work, please share your experience, successful or not. I and another person have both failed. Following the directions in the devguide (and for one step, PCBuild/readme), I did essentially the following. * download and install TortoiseHG and an svn client (for external.bat) * download and install c++ 2010 express * in directory X, clone the python.org hg repository as cpython * in X/cpython, run Tools/buildbot/external.bat to fetch and compile tcl/tk and other external dependencies. * run visual studio with X/cpython/PCBuild/pcbuild.sln (I just double click on the .sln file. Choose c++ 2010 if other compilers are listed. * build debug version of 3.4 (F7), stored as .../PCBuild/python_d.exe. This also builds in the same directory things like _bz2_d.pyd and _lzma_d.pyd (whose dependencies are also fetched by external.bat) and _tkinter_d.pyd, apparently without error. The last is 43 kb. That is smaller than the others, but reasonable considering that it just forwards calls to tk. My installed 3.3 _tkinter.pyd is 41 kb. * run python_d.exe. sys.path is ['', 'F:\\Python\\dev\\cpython\\PCbuild\\python34_d.zip', 'F:\\Python\\dev\\cpython\\DLLs', 'F:\\Python\\dev\\cpython\\lib', 'F:\\Python\\dev\\cpython\\PCbuild', # where _tkinter, etc are 'F:\\Python\\dev\\cpython', 'F:\\Python\\dev\\cpython\\lib\\site-packages'] >>> import bz2, lzma # these import _bz2 and _lzma >>> import tkinter Traceback (most recent call last): File "", line 1, in File "F:\Python\dev\cpython\lib\tkinter\__init__.py", line 36, in from tkinter import _fix File "F:\Python\dev\cpython\lib\tkinter\_fix.py", line 65, in import _tkinter ImportError: DLL load failed: The specified module could not be found. [83479 refs, 32096 blocks] My two hypotheses: 1. There is something wrong with _tkinter_d.pyd in particular such that it is not recognized as a dll file. To test this, I renamed my installed _tkinter, copied and renamed _tkinter_d, ran installed python 3.3, and got a similar error ImportError: DLL load failed: %1 is not a valid Win32 application. Perhaps this verifies the hypothesis, perhaps it is due to a mismatch between normal builds and debug builds. 2. CPython somehow special-cases the _tkinter import so that it fails in the fresh build environment. This seems dubious, but who knows? Since the Windows buildbots build and test cpython more or less the same way, test/test_tkinter should pick up the same problem -- *if* it is actually run, but because of some problems with the test suite, I am not sure it is, rather than being skipped. Or maybe there is some significant small different in the buildbot process. Does anyone have any idea what else I might do? I expect to eventually post on pydev or the tracker, but I wanted to first try to collect more information here (which I wish more people would do). -- Terry Jan Reedy From tjreedy at udel.edu Sun Mar 10 19:04:43 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Mar 2013 19:04:43 -0400 Subject: Building importable _tkinter on Windows (solved) In-Reply-To: References: Message-ID: On 3/9/2013 7:41 PM, Terry Reedy wrote: > If you have tried to build _tkinter on Windows from the cpython > repository, and have 'import tkinter' work, please share your > experience, successful or not. I and another person have both failed. > [snip] Solution from Merlijn van Deen on core-mentorship list: Let x be the directory containing both the repository directories, such as 'cpython' and the external dependency directories created by external.bat. Copy x/tcl-8.5.11.0/win/Debug_VC10/tcl85g.dll x/tk-8.5.11.0/win/Debug_VC10/tk85g.dll to x/cpython/PCbuild Now, 'import tkinter', and hence idle, seem to work. -- Terry Jan Reedy From jawerty210 at gmail.com Sat Mar 9 20:14:56 2013 From: jawerty210 at gmail.com (Jared Wright) Date: Sat, 9 Mar 2013 17:14:56 -0800 (PST) Subject: gmreader - a terminal app for listening to your emails Message-ID: <3e97e0e9-b089-46b4-b8af-b0d1b7d8089f@googlegroups.com> Gmail message test-to-speech reader I used imaplib along with BeautifulSoup to make this run. It uses system calls to run the tts functions. It's all a work in progress, and if you see a bug, you are welcome to to make a pull request or open an issue. https://github.com/jawerty/gmreader From pitsakis at gmail.com Sat Mar 9 21:03:35 2013 From: pitsakis at gmail.com (pitsakis at gmail.com) Date: Sat, 9 Mar 2013 18:03:35 -0800 (PST) Subject: pyqt4 & qt license Message-ID: <2c2db42a-1c7f-4400-a34a-c18a9a2652ff@googlegroups.com> i want to develop a GUI application that will be sold. i want to use pyqt4. can i download and use the GML version during the development and then buy the commercial verion beofore i distribute the application ? commercial version means LGPL? i think i am comfused so please someone clarify on versions and licences. somewhere i also noticed that there is a qt license ? will i need this also ? Thank you in advance From pitsakis at gmail.com Sat Mar 9 21:08:13 2013 From: pitsakis at gmail.com (pitsakis at gmail.com) Date: Sat, 9 Mar 2013 18:08:13 -0800 (PST) Subject: pyqt4 & qt license Message-ID: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> hello, i want to develop a GUI application that will be sold. i want to use pyqt4. can i download and use the GPL version during the development and then buy the commercial verion beofore i distribute the application ? commercial version means LGPL? i think i am comfused so please someone clarify on versions and licences. somewhere i also noticed that there is a qt license ? will i need this also ? Thank you in advance From lists at e-noesis.com Sat Mar 9 21:38:15 2013 From: lists at e-noesis.com (Ioakeim Tellidis) Date: Sat, 9 Mar 2013 21:38:15 -0500 Subject: pyqt4 & qt license In-Reply-To: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> Message-ID: On Sat, Mar 9, 2013 at 9:08 PM, wrote: > hello, > > i want to develop a GUI application that will be sold. > i want to use pyqt4. > can i download and use the GPL version during the development and then buy > the commercial verion beofore i distribute the application ? > > commercial version means LGPL? i think i am comfused so please someone > clarify on versions and licences. > > somewhere i also noticed that there is a qt license ? will i need this > also ? > > Thank you in advance > -- > http://mail.python.org/mailman/listinfo/python-list > I am not sure if this is the right place for clarifying Licences issues. But I am sure that you are "touching" a very sensitive issue about how to mix licenses for commercial products. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmpython at gmail.com Sat Mar 9 22:31:21 2013 From: cmpython at gmail.com (CM) Date: Sat, 9 Mar 2013 19:31:21 -0800 (PST) Subject: pyqt4 & qt license References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> Message-ID: <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> On Mar 9, 9:08?pm, pitsa... at gmail.com wrote: > hello, > > i want to develop a GUI application that will be sold. > i want to use pyqt4. > can i download and use the GPL version during the development and then buy the commercial verion beofore i distribute the application ? Arguably, yes. From pyqt4's website: "Yes, you can re-license your application under a commercial license so long as you have purchased appropriate commercial PyQt licenses before you start to sell it." and also: "The availability of the LGPL version of Qt means that it is possible to evaluate using that and the GPL version of PyQt while still being able to re-license any code written during an evaluation in a future closed source application." > commercial version means LGPL? i think i am comfused so please someone clarify on versions and licences. There is currently no version of PyQT licensed with LGPL. They refer to their commercial license as their "commercial license". > somewhere i also noticed that there is a qt license ? will i need this also ? Yes. PyQT is a wrapper for Python around QT, so you would need both. QT has, according to the site, both a GPL and LGPL version of their license. You can read up on GPL and LGPL by Googling about it, but in a nutshell, for commercial applications, of the two, LGPL is what you want. Do you know about PySide? It's another wrapper for QT that is licensed as LGPL and is free software. I don't know it's current state of development, though. Last Twitter update was about a year ago. From gouzounakis at hotmail.com Sat Mar 9 23:09:41 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Sat, 9 Mar 2013 20:09:41 -0800 (PST) Subject: pyqt4 & qt license In-Reply-To: <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> Message-ID: <7041ce65-5551-4cdc-a312-b473b7e0c04a@googlegroups.com> Please correct me if im wrong.. PySide is LGPL and is free and by using that someone can develop commercial (and non commercial) software, while being able at the same to choose between both close and open Source. PyQT4 Commercial Licence costs more than 300 Euro and by using that someone can develop commercial software while being again able to choose between both close and open Soruce. PyQT4 GPL Licence is free and by using that someone can develop only non-commercial software. What about the source here? Could that be both open and close? Can someone develop a closed source but NON-commercial software, by using PyQT4 GPL license? ?? ???????, 10 ??????? 2013 5:31:21 ?.?. UTC+2, ? ??????? CM ??????: > Yes. PyQT is a wrapper for Python around QT, so you would need both. > > QT has, according to the site, > > both a GPL and LGPL version of their license. If someone used PySide, he should again use in addition one of those 2 above QT licences? Last question: Could someone just buy the PyQT4 commercial licence and use the LGPL licence of QT in his CLOSED source commercial software? (Which i believe is free :S) Or does LGPL mean that the source should be open? Or i should better ask, Does any of those 2 Licenses cost any money? Or they are free? Forgive me for all these questions im very interested in this topic too. THX 4 your time!! Tellidis your Greek? :) From vito.detullio at gmail.com Sat Mar 9 23:45:56 2013 From: vito.detullio at gmail.com (Vito De Tullio) Date: Sun, 10 Mar 2013 05:45:56 +0100 Subject: pyqt4 & qt license References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> <7041ce65-5551-4cdc-a312-b473b7e0c04a@googlegroups.com> Message-ID: D. Xenakis wrote: > Can someone develop a closed source but NON-commercial software, by using > PyQT4 GPL license? no, by definition of GPL: if you are using a GPL library, you must distribute your software as GPL. (the GPL does not care about commercial / non commercial) http://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL -- ZeD From torriem at gmail.com Sun Mar 10 00:03:23 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 09 Mar 2013 22:03:23 -0700 Subject: pyqt4 & qt license In-Reply-To: References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> <7041ce65-5551-4cdc-a312-b473b7e0c04a@googlegroups.com> Message-ID: <513C141B.1070902@gmail.com> On 03/09/2013 09:45 PM, Vito De Tullio wrote: > D. Xenakis wrote: > >> Can someone develop a closed source but NON-commercial software, by using >> PyQT4 GPL license? > > no, by definition of GPL: if you are using a GPL library, you must > distribute your software as GPL. > > (the GPL does not care about commercial / non commercial) > > http://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL Just to be clear here, the GPL isn't a magical license. It doesn't arbitrarily infect your code and force you to use the GPL on your own code. And no matter what license you use, you can re-license your code later under any terms you wish, since you own the copyright on the code. Here's the vital part: The moment you distribute your code, if you use a GPL library, then unless you also release your code under the GPL also, you are now in a copyright violation situation. You have three options: 1. License your code in a compatible way so that you're following the terms of the open source license the library you are using asks of you. IE release your source code under the terms of the GPL. 2. Remove the GPL'd library and either implement the lost functionality yourself (also know as "write your own dang code"), or replace the GPL'd library with an equivalent library under a different, compatible license. In the case of PyQt, this could be PySide, or maybe you decide to use a completely different GUI toolkit. 3. Negotiate a proprietary license with the copyright holder (IE buy the proprietary, royalty-free license from PyQt's authors. If you are in a position where you have violated copyright, failure to remedy it in a timely manner can cause you to be financially liable to the copyright holders of the code you are mis-using. Now, if you develop a program using PyQt and distribute it under the terms of the GPL, that does not mean you have to keep your code under the GPL. You can close your source at any time and use, say, PySide instead. But any code you already distributed under the GPL remains in the wild (supposing someone has a copy) under the GPL terms, even if newer versions of your software adopt a new license. From newspost2012 at gmx.de Sun Mar 10 05:45:13 2013 From: newspost2012 at gmx.de (newspost2012 at gmx.de) Date: Sun, 10 Mar 2013 01:45:13 -0800 (PST) Subject: pyqt4 & qt license In-Reply-To: <7041ce65-5551-4cdc-a312-b473b7e0c04a@googlegroups.com> References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> <6137bdf6-4944-4fe3-8286-20cfba30dcef@5g2000yqz.googlegroups.com> <7041ce65-5551-4cdc-a312-b473b7e0c04a@googlegroups.com> Message-ID: <500b289f-c591-41d7-96c6-8a5a0fef89ff@googlegroups.com> Am Sonntag, 10. M?rz 2013 05:09:41 UTC+1 schrieb D. Xenakis: > Please correct me if im wrong.. > ... > PyQT4 GPL Licence is free and by using that someone can develop only > non-commercial software. Wrong. GPL does not prevent you from developing commercial softwarre. You just have to release your source under GPL. GPL is free as in freedom. It doesn't have to be free as in "free beer". There are customers paying for software relesed under GPL. They just needed it and didn't care if others used it too. > What about the source here? Could that be both open and close? As already said, if you use parts of GPL code in your (non private) project, the whole project has to be GPL. > Can someone develop a closed source but NON-commercial software, > by using PyQT4 GPL license? GPL does not cover commercial vs. non-commertial. Just freedom vs. proprietary. > ... hth, Martin From torriem at gmail.com Sat Mar 9 22:50:44 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 09 Mar 2013 20:50:44 -0700 Subject: pyqt4 & qt license In-Reply-To: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> References: <8bb998ea-858c-4aff-b8e6-36f1acfdc621@googlegroups.com> Message-ID: <513C0314.6080207@gmail.com> On 03/09/2013 07:08 PM, pitsakis at gmail.com wrote: > hello, > > i want to develop a GUI application that will be sold. i want to use > pyqt4. can i download and use the GPL version during the development > and then buy the commercial verion beofore i distribute the > application ? > > commercial version means LGPL? i think i am comfused so please > someone clarify on versions and licences. Nope. Commerical means you buy a royalty-free license to use their product in a proprietary project. In other words you buy the right to use their code in a way that's compatible with your own code's distribution scheme. > > somewhere i also noticed that there is a qt license ? will i need > this also ? You must be aware of the licenses of each individual part of the stack and honor their terms! This is true of *any* library you use, and code from *any* source. Open source does not mean public domain and you don't automatically have a right to use it in your own project. If you are using open source components in a proprietary project, you might need to consult a lawyer if you are unsure of the use terms you are dealing with or your obligations under those terms under copyright law. You have to follow the appropriate license for Qt (LGPL, so no biggy for you if you don't modify Qt itself), PyQt (GPL only or proprietary royalty-free), Python itself (not a problem since you aren't modifying it and you can redistribute it), and any and all Python libraries you might use. From what I can tell things in the standard library are fine, but watch out for third-party libraries. The licenses are not always compatible with proprietary code. As for PyQt, unless you pay for the proprietary, royalty-free license for PyQT (before or after development), then you have to use the GPL for your project, since those are the terms the free version of PyQt is released under. This is a deliberate choice by the company that makes it to secure a revenue stream. There is an alternative to PyQt, PySide, which is under the LGPL and compatible with a closed-source project. From jiangwen365 at gmail.com Sun Mar 10 06:17:57 2013 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Sun, 10 Mar 2013 18:17:57 +0800 Subject: PyPyODBC 1.0.5 released. (DBI 2.0 ODBC module compatible with PyPy, IronPython and SQLAlchemy) Message-ID: Changes in Ver 1.0.5 (and 1.0.4, 1.0.3, 1.0.2, 1.0.1) - *Fix several bugs under Python 3.x* - *Add Mac / iODBC platform support* - *Improved ODBC ANSI / unicode mode support* Features - *One pure Python script, runs on CPython / IronPython / PyPy , Python 3.3 / 2.4 / 2.5 / 2.6 / 2.7 , Win / Linux / Mac , 32 / 64 bit* - *Almost totally same usage as pyodbc * ( can be seen as a re-implementation of pyodbc in pure Python ) - *Simple - the whole module is implemented in a single python script with less than 3000 lines * - *Built-in functions to create and compress Access MDB files on Windows* Simply try pypyodbc: import pypyodbc pypyodbc.win_create_mdb('D:\\database.mdb') connection_string = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\database.mdb' connection = pypyodbc.connect(connection_string) SQL = 'CREATE TABLE saleout (id COUNTER PRIMARY KEY,product_name VARCHAR(25));' connection.cursor().execute(SQL).commit() ... Samples*A HelloWorld sample of python database programming **Create & Compact Access MDB database *Install *Download the latest package * , unzip to a folder, *double click the setup.py file*, or run setup.py install Or if you have pip available: pip install pypyodbc Or get the latest pypyodbc.py script from *GitHub * (Main Development site) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tampucciolina at libero.it Sun Mar 10 07:04:16 2013 From: tampucciolina at libero.it (leonardo) Date: Sun, 10 Mar 2013 12:04:16 +0100 Subject: idle doesn't work Message-ID: <513C68B0.7050204@libero.it> hi guys i have a mac os x 10.8, i had already python 2.7, i downloaded python 3.3 and active tcl 8.5, but idle and the new version don't work, the answer is:"idle's subprocess didn't make connection or personal firewall is blocking". do you know what can i do ? or can i use other easy editors to program in python? thanks! best regards From mail at lukaszposadowski.pl Sun Mar 10 09:43:32 2013 From: mail at lukaszposadowski.pl (=?UTF-8?Q?=C5=81ukasz?= Posadowski) Date: Sun, 10 Mar 2013 14:43:32 +0100 Subject: idle doesn't work In-Reply-To: <513C68B0.7050204@libero.it> References: <513C68B0.7050204@libero.it> Message-ID: <1362923012.2658.7.camel@localhost> Dnia 2013-03-10, nie o godzinie 12:04 +0100, leonardo pisze: > hi guys > > i have a mac os x 10.8, i had already python 2.7, i downloaded python > 3.3 and active tcl 8.5, but idle and the new version don't work, the > answer is:"idle's subprocess didn't make connection or personal firewall > is blocking". do you know what can i do ? Try "python idle.py -n". You're on Mac and don't have Textmate? :) -- ?ukasz Posadowski From tampucciolina at libero.it Sun Mar 10 15:05:45 2013 From: tampucciolina at libero.it (leonardo) Date: Sun, 10 Mar 2013 20:05:45 +0100 Subject: idle doesn't work References: <1362923012.2658.7.camel@localhost> Message-ID: <973ADD49-327F-4847-AC7B-D63F41FF77B5@libero.it> >> hi guys >> >> i have a mac os x 10.8, i had already python 2.7, i downloaded python >> 3.3 and active tcl 8.5, but idle and the new version don't work, the >> answer is:"idle's subprocess didn't make connection or personal firewall >> is blocking". do you know what can i do ? thanks and regards > > From tampucciolina at libero.it Sun Mar 10 18:01:25 2013 From: tampucciolina at libero.it (leonardo) Date: Sun, 10 Mar 2013 23:01:25 +0100 Subject: =?windows-1252?Q?_idle_=28GUI=29doesn=27t_work=85?= References: <973ADD49-327F-4847-AC7B-D63F41FF77B5@libero.it> Message-ID: >>> hi guys >>> i need help: >>> i have a mac os x 10.8, i had already python 2.7, i downloaded python >>> 3.3 and active tcl 8.5, but idle and the new version don't work, the >>> answer is:"idle's subprocess didn't make connection or personal firewall >>> is blocking" plus in the terminal i still have python 2.7. do you know what can i do ? > > thanks and regards >> >> > From tampucciolina at libero.it Mon Mar 11 10:42:59 2013 From: tampucciolina at libero.it (leonardo) Date: Mon, 11 Mar 2013 15:42:59 +0100 Subject: Fwd: Re: [Python-Help] idle doesn't work In-Reply-To: <513D6CDD.6060506@libero.it> References: <513D6CDD.6060506@libero.it> Message-ID: <513DED73.6020802@libero.it> -------- sorry for that, that answer didn't help me.. regards Il 10/03/2013 23.59, Matthew Dixon Cowles ha scritto: > Dear Leonardo, > Sending the same message three times isn't likely to produce faster > or better help. > > Is the reply that you got on the main Python list satisfactory? > > Regards, > Matt > > From tampucciolina at libero.it Tue Mar 12 11:57:52 2013 From: tampucciolina at libero.it (leonardo) Date: Tue, 12 Mar 2013 16:57:52 +0100 Subject: [Python-Help] idle doesn't work In-Reply-To: <1363043817.03.53316@mint-julep.mondoinfo.com> References: <513C68B0.7050204@libero.it> <513C8650.2010802@libero.it> <1362956078.93.46251@mint-julep.mondoinfo.com> <513D6CDD.6060506@libero.it> <1363043817.03.53316@mint-julep.mondoinfo.com> Message-ID: <513F5080.6030808@libero.it> first of all thanks for trying to help me. the text of my email was the following: i have a mac os x 10.8, i had already python 2.7, i downloaded python 3.3 and active tcl 8.5, but idle and the new version don't work, the answer is:"idle's subprocess didn't make connection or personal firewall is blocking". do you know what can i do ? or can i use other easy editors to program in python? i am frustated cause i can use only the old python 2.7 in the terminal window. python 3.3 has not taken place and idle gives the above mentioned error.. thanks for any help! Il 12/03/2013 0.20, Matthew Dixon Cowles ha scritto: > Dear Leonardo, > I only got two copies of that message. We're going in the right > direction. > >> that answer didn't help me.. > Did it not work to run IDLE in a terminal window with the "-n" > argument? Or are you having difficulty doing that? > > IDLE doesn't have any unique abilities. Many people (including me) > use Python under OS X with just a couple of terminal windows and a > text editor. Have you tried that? Have you run into difficulties with > it? > > Regards, > Matt > > From nad at acm.org Tue Mar 12 12:52:12 2013 From: nad at acm.org (Ned Deily) Date: Tue, 12 Mar 2013 09:52:12 -0700 Subject: [Python-Help] idle doesn't work References: <513C68B0.7050204@libero.it> <513C8650.2010802@libero.it> <1362956078.93.46251@mint-julep.mondoinfo.com> <513D6CDD.6060506@libero.it> <1363043817.03.53316@mint-julep.mondoinfo.com> <513F5080.6030808@libero.it> Message-ID: In article <513F5080.6030808 at libero.it>, leonardo wrote: > first of all thanks for trying to help me. the text of my email was the > following: > i have a mac os x 10.8, i had already python 2.7, i downloaded python > 3.3 and active tcl 8.5, but idle and the new version don't work, the > answer is:"idle's subprocess didn't make connection or personal firewall > is blocking". do you know what can i do ? > or can i use other easy editors to program in python? > > i am frustated cause i can use only the old python 2.7 in the terminal > window. python 3.3 has not taken place and idle gives the above > mentioned error.. Try typing the following in a terminal window: idle3.3 or, possibly /usr/local/bin/idle3.3 and see if there is a more useful error message. If that doesn't work, try adding -n: idle3.3 -n -- Ned Deily, nad at acm.org From tampucciolina at libero.it Tue Mar 12 15:25:21 2013 From: tampucciolina at libero.it (leonardo) Date: Tue, 12 Mar 2013 20:25:21 +0100 Subject: [Python-Help] idle doesn't work In-Reply-To: References: <513C68B0.7050204@libero.it> <513C8650.2010802@libero.it> <1362956078.93.46251@mint-julep.mondoinfo.com> <513D6CDD.6060506@libero.it> <1363043817.03.53316@mint-julep.mondoinfo.com> <513F5080.6030808@libero.it> Message-ID: <513F8121.5070805@libero.it> thanks now python shell works Il 12/03/2013 17.52, Ned Deily ha scritto: > In article <513F5080.6030808 at libero.it>, > leonardo wrote: >> first of all thanks for trying to help me. the text of my email was the >> following: >> i have a mac os x 10.8, i had already python 2.7, i downloaded python >> 3.3 and active tcl 8.5, but idle and the new version don't work, the >> answer is:"idle's subprocess didn't make connection or personal firewall >> is blocking". do you know what can i do ? >> or can i use other easy editors to program in python? >> >> i am frustated cause i can use only the old python 2.7 in the terminal >> window. python 3.3 has not taken place and idle gives the above >> mentioned error.. > Try typing the following in a terminal window: > > idle3.3 > > or, possibly > > /usr/local/bin/idle3.3 > > and see if there is a more useful error message. > > If that doesn't work, try adding -n: > > idle3.3 -n > From tampucciolina at libero.it Tue Mar 12 15:29:06 2013 From: tampucciolina at libero.it (leonardo) Date: Tue, 12 Mar 2013 20:29:06 +0100 Subject: programming course References: Message-ID: <4D031E61-0398-439A-A249-2AA8DA16C885@libero.it> sorry for bothering you, i found www.code.org, do you think is that useful? i am a beginner and i would really like to learn, but i need a step by step website or books, any recommendations? thanks! Inizio messaggio inoltrato: > Da: Ned Deily > Oggetto: Re: [Python-Help] idle doesn't work > Data: 12 marzo 2013 17:52:12 CET > A: python-list at python.org > > In article <513F5080.6030808 at libero.it>, > leonardo wrote: >> first of all thanks for trying to help me. the text of my email was the >> following: >> i have a mac os x 10.8, i had already python 2.7, i downloaded python >> 3.3 and active tcl 8.5, but idle and the new version don't work, the >> answer is:"idle's subprocess didn't make connection or personal firewall >> is blocking". do you know what can i do ? >> or can i use other easy editors to program in python? >> >> i am frustated cause i can use only the old python 2.7 in the terminal >> window. python 3.3 has not taken place and idle gives the above >> mentioned error.. > > Try typing the following in a terminal window: > > idle3.3 > > or, possibly > > /usr/local/bin/idle3.3 > > and see if there is a more useful error message. > > If that doesn't work, try adding -n: > > idle3.3 -n > > -- > Ned Deily, > nad at acm.org > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From jsf80238 at gmail.com Tue Mar 12 20:06:20 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 12 Mar 2013 18:06:20 -0600 Subject: programming course In-Reply-To: <4D031E61-0398-439A-A249-2AA8DA16C885@libero.it> References: <4D031E61-0398-439A-A249-2AA8DA16C885@libero.it> Message-ID: > sorry for bothering you, i found www.code.org, do you think is that useful? > i am a beginner and i would really like to learn, but i need a step by step > website or books, any recommendations? Try https://www.udacity.com/course/cs101. From jcasale at activenetwerx.com Sun Mar 10 10:16:27 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 10 Mar 2013 14:16:27 +0000 Subject: Switch statement Message-ID: I have a switch statement composed using a dict: switch = { ? ? 'a': func_a, ? ? 'b':?func_b, ? ? 'c':?func_c } switch.get(var, default)() As a result of multiple functions per choice, it migrated to: switch = { ? ? 'a': (func_a1, func_a2), ? ? 'b': (func_b1,?func_b2), ? ? 'c': (func_c, ) } for f in?switch.get(var, (default, )): ? ? f() As a result of only some of the functions now?requiring unique arguments, I presume this needs to be migrated to a if/else statement? Is there a way to maintain the switch style with the ability in this scenario to cleanly pass args only to some functions? Thanks, jlc From steve+comp.lang.python at pearwood.info Sun Mar 10 11:18:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 15:18:08 GMT Subject: Switch statement References: Message-ID: <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Mar 2013 14:16:27 +0000, Joseph L. Casale wrote: > I have a switch statement composed using a dict: > > > switch = { > ? ? 'a': func_a, > ? ? 'b':?func_b, > ? ? 'c':?func_c > } > switch.get(var, default)() > > > As a result of multiple functions per choice, it migrated to: > > > > switch = { > ? ? 'a': (func_a1, func_a2), > ? ? 'b': (func_b1,?func_b2), > ? ? 'c': (func_c, ) > } > > > > for f in?switch.get(var, (default, )): > ? ? f() > > > As a result of only some of the functions now?requiring unique > arguments, I presume this needs to be migrated to a if/else statement? > Is there a way to maintain the switch style with the ability in this > scenario to cleanly pass args only to some functions? The dict-as-switch-statement pattern only works when the functions all take the same argument(s). Otherwise, you need to check which function you are calling, and provide the right arguments. So either use the if...elif...else pattern, or you need to modify those functions to take the same arguments. For example, suppose I have three functions taking different arguments: spam(a) ham(b) eggs(c) Instead of storing spam, ham and eggs in my switch-dict, I store three wrapper functions: switch = { 'A': lambda a, b, c: spam(a), 'B': lambda a, b, c: ham(b), 'C': lambda a, b, c: eggs(c), } and then unconditionally call the function with all three arguments: switch[letter](a, b, c) The wrappers take care of ignoring the arguments that should be ignored, and calling the correct function with the right argument. Here's another similar case. Suppose the functions are called like this: spam(a, b) ham(b, c) eggs(b) and furthermore, the arguments a and c are known ahead of time, with only b varying. I can make one-argument versions of the spam and ham functions using either the functools module or a lambda with a default value: switch = { 'A': functools.partial(spam, a), 'B': lambda b, c=c: ham(b, c), 'C': eggs, } switch[letter](b) I stress that this version only applies if the extra arguments are known ahead of time. If they aren't known until you look-up the switch, you can't use this tactic. functools.partial isn't always applicable, but when it is, you should prefer it over lambda since it will be very slightly more efficient. -- Steven From jcasale at activenetwerx.com Sun Mar 10 13:51:58 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 10 Mar 2013 17:51:58 +0000 Subject: Switch statement In-Reply-To: <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> References: , <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: > switch = {? >???? 'A': functools.partial(spam, a), >???? 'B': lambda b, c=c: ham(b, c), >???? 'C': eggs, >???? } >? >?switch[letter](b) That's cool, never even thought to use lambdas. > functools.partial isn't always applicable, but when it is, you should >?prefer it over lambda since it will be very slightly more efficient. Ok, haven't used this before but I?will?give it a read! Much appreciated Steven! jlc From tjreedy at udel.edu Sun Mar 10 18:02:25 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Mar 2013 18:02:25 -0400 Subject: Switch statement In-Reply-To: <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <513ca430$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/10/2013 11:18 AM, Steven D'Aprano wrote: > On Sun, 10 Mar 2013 14:16:27 +0000, Joseph L. Casale wrote: > >> I have a switch statement composed using a dict: >> >> >> switch = { >> 'a': func_a, >> 'b': func_b, >> 'c': func_c >> } >> switch.get(var, default)() >> >> >> As a result of multiple functions per choice, it migrated to: >> >> >> >> switch = { >> 'a': (func_a1, func_a2), >> 'b': (func_b1, func_b2), >> 'c': (func_c, ) >> } >> >> >> >> for f in switch.get(var, (default, )): >> f() >> >> >> As a result of only some of the functions now requiring unique >> arguments, I presume this needs to be migrated to a if/else statement? >> Is there a way to maintain the switch style with the ability in this >> scenario to cleanly pass args only to some functions? > > > The dict-as-switch-statement pattern only works when the functions all > take the same argument(s). Otherwise, you need to check which function > you are calling, and provide the right arguments. If, for instance, the functions take either 0 or 1 arg and the 1 arg is always the same, an alternative to the other suggestions is to look at the signature in an if statement. In 3.3 this is relatively ease, as inspect.signature(func) returns a signature object. There are more complicated paths in earlier versions. -- Terry Jan Reedy From msirenef at lightbird.net Sun Mar 10 16:42:24 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 10 Mar 2013 16:42:24 -0400 Subject: Switch statement In-Reply-To: References: Message-ID: <513CF030.9030808@lightbird.net> On 03/10/2013 10:16 AM, Joseph L. Casale wrote: > I have a switch statement composed using a dict: > > > switch = { > 'a': func_a, > 'b': func_b, > 'c': func_c > } > switch.get(var, default)() > > > As a result of multiple functions per choice, it migrated to: > > > > switch = { > 'a': (func_a1, func_a2), > 'b': (func_b1, func_b2), > 'c': (func_c, ) > } > > > > for f in switch.get(var, (default, )): > f() > > > As a result of only some of the functions now requiring unique arguments, I presume this > needs to be migrated to a if/else statement? Is there a way to maintain the switch style with > the ability in this scenario to cleanly pass args only to some functions? > > > Thanks, > jlc You can have two dictionaries; you can also add a flag: 'a': (WITHARG, funca1, funca2) -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The cure for boredom is curiosity. There is no cure for curiosity. Dorothy Parker From nicholas.cole at gmail.com Sun Mar 10 17:50:19 2013 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Sun, 10 Mar 2013 21:50:19 +0000 Subject: Switch statement In-Reply-To: <513CF030.9030808@lightbird.net> References: <513CF030.9030808@lightbird.net> Message-ID: On Sun, Mar 10, 2013 at 8:42 PM, Mitya Sirenef wrote: > On 03/10/2013 10:16 AM, Joseph L. Casale wrote: > >> I have a switch statement composed using a dict: >> > > > > > > switch = { > > 'a': func_a, > > 'b': func_b, > > 'c': func_c > > } > > switch.get(var, default)() > > > > > > As a result of multiple functions per choice, it migrated to: > > > > > > > > switch = { > > 'a': (func_a1, func_a2), > > 'b': (func_b1, func_b2), > > 'c': (func_c, ) > > } > > > > > > > > for f in switch.get(var, (default, )): > > f() > > > > > > As a result of only some of the functions now requiring unique > arguments, I presume this > > needs to be migrated to a if/else statement? Is there a way to maintain > the switch style with > > the ability in this scenario to cleanly pass args only to some functions? > Or could you do something like: arguments_to_pass = [list of some sort] switch.get(var, default)(*arguments_to_pass) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcasale at activenetwerx.com Sun Mar 10 18:18:37 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 10 Mar 2013 22:18:37 +0000 Subject: Switch statement In-Reply-To: References: <513CF030.9030808@lightbird.net>, Message-ID: > Or could you do something like: > > arguments_to_pass = [list of some sort] > switch.get(var, default)(*arguments_to_pass) Stevens lambda suggestion was most appropriate. Within the switch, there are functions called with none, or some variation of arguments. It was not easy to pass them in after the fact, especially since the same function may have different args depending on which case. The lamda worked well. Thanks guys! jlc -------------- next part -------------- An HTML attachment was scrubbed... URL: From mbg1708 at planetmail.com Sun Mar 10 11:38:43 2013 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Sun, 10 Mar 2013 08:38:43 -0700 (PDT) Subject: BPLUSPY-1.0 Installation issue Message-ID: The Bpluspy-1.0 package from Pypi is excellent. The usual setup loads the software into site-packages. Unfortunately, once installed, Python import statements don't find the software. The fix is to add a "pth" file in the site-packages directory. The file can be called .pth and needs to contain a single line of text BplusPy Python import statements now work fine. This fix applies to Python 2.7 in Fedora 18 and Windows XP. Mary From steve+comp.lang.python at pearwood.info Sun Mar 10 12:22:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2013 16:22:37 GMT Subject: BPLUSPY-1.0 Installation issue References: Message-ID: <513cb34d$0$6512$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Mar 2013 08:38:43 -0700, mbg1708 wrote: > The Bpluspy-1.0 package from Pypi is excellent. The usual setup loads > the software into site-packages. Unfortunately, once installed, Python > import statements don't find the software. > > The fix is to add a "pth" file in the site-packages directory. The file > can be called .pth and needs to contain a single line > of text > > BplusPy > > Python import statements now work fine. > > This fix applies to Python 2.7 in Fedora 18 and Windows XP. > > Mary Thanks for posting this! Have you considered notifying the package's author? Perhaps the installer script could add the pth file automatically, or fix the package structure so it becomes unnecessary. -- Steven From mbg1708 at planetmail.com Mon Mar 11 18:32:00 2013 From: mbg1708 at planetmail.com (mbg1708 at planetmail.com) Date: Mon, 11 Mar 2013 15:32:00 -0700 (PDT) Subject: BPLUSPY-1.0 Installation issue In-Reply-To: <513cb34d$0$6512$c3e8da3$5496439d@news.astraweb.com> References: <513cb34d$0$6512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0591d613-2f8c-44f0-9a66-9fa22ae6ff3a@googlegroups.com> On Sunday, March 10, 2013 11:22:37 AM UTC-5, Steven D'Aprano wrote: > On Sun, 10 Mar 2013 08:38:43 -0700, mbg1708 wrote: > > > > > The Bpluspy-1.0 package from Pypi is excellent. The usual setup loads > > > the software into site-packages. Unfortunately, once installed, Python > > > import statements don't find the software. > > > > > > The fix is to add a "pth" file in the site-packages directory. The file > > > can be called .pth and needs to contain a single line > > > of text > > > > > > BplusPy > > > > > > Python import statements now work fine. > > > > > > This fix applies to Python 2.7 in Fedora 18 and Windows XP. > > > > > > Mary > > > > > > Thanks for posting this! > > > > Have you considered notifying the package's author? Perhaps the installer > > script could add the pth file automatically, or fix the package structure > > so it becomes unnecessary. > > > > > > -- > > Steven Yup. Tried that. There's no bug reporting link in Pypi (that I could find). And Aaron Watters email address at Sourceforge is invalid....the email bounced back. So.....I tried.....and ended up here...it was the best I could do. Mary. From mukeshtiwari.iiitm at gmail.com Sun Mar 10 13:42:29 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 10 Mar 2013 10:42:29 -0700 (PDT) Subject: Regular expression problem Message-ID: Hello all I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please tell me how to make this code run faster. import re if __name__ == "__main__": n = int ( raw_input() ) c = 1 while c <= n : email = filter ( lambda x : x != None , [ re.search ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-9]*' , x ) for x in raw_input().split(' ') ] ) t = len ( email ) print 'Case #' + str ( c ) + ': ' + str ( t ) for i in xrange ( t ): print email[i].group() c += 1 Also rather than breaking the string at space, I tried to use findall but I am not getting correct result. >>> re.findall ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-9]*[ ]+','mukeshtiwari.iiitmmmm at gmail.com mukeshtiwari.iiitmmmmm at gmail.com') ['com'] I am suppose to get [ mukeshtiwari.iiitmmm at gmail.com , mukeshtiwari.iiitmmm at gmail.com] ? Regards Mukesh Tiwari [1] http://www.spoj.com/problems/MAIN12C/ From rosuav at gmail.com Sun Mar 10 13:59:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Mar 2013 04:59:59 +1100 Subject: Regular expression problem In-Reply-To: References: Message-ID: On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari wrote: > I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please tell me how to make this code run faster. What is the time limit? I just tried it (Python 2.6 under Windows) and it finished in a humanly-immeasurable amount of time. Are you sure that STDIN (eg raw_input()) is where your test data is coming from? ChrisA From rosuav at gmail.com Sun Mar 10 14:08:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Mar 2013 05:08:44 +1100 Subject: Regular expression problem In-Reply-To: References: Message-ID: On Mon, Mar 11, 2013 at 4:59 AM, Chris Angelico wrote: > On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari > wrote: >> I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please tell me how to make this code run faster. > > What is the time limit? I just tried it (Python 2.6 under Windows) and > it finished in a humanly-immeasurable amount of time. Are you sure > that STDIN (eg raw_input()) is where your test data is coming from? Oops, reading comprehension fail. Time limit is 3s on a Pentium III. I've no idea how long your code will take on that hardware, but I doubt that it's taking three seconds. So my query regarding source of test data still stands. Can you put together an uber-simple test program that just echoes the lines of input, to make sure it really is coming off stdin? The problem description certainly does seem to imply stdin, but I can't see why your code would take three seconds unless it's stalling for some reason. Though perhaps on a P3 with the maximum 100 tests, maybe that could take a while... Something to try: Since you're using re.search(), see if you can drop the complemented sets at the beginning [^~!@#$%^&*()<>?,.]* and end [^~!@#$%^&*()<>?,.a-zA-Z0-9]* - they're going to be slow to process. Also, you can simplify this: [a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]* to this: [a-zA-Z0-9][a-zA-Z0-9._]{4,} The brace notation means "at least 4, at most infinity". Try those out and see if you still get the results you want. ChrisA From mukeshtiwari.iiitm at gmail.com Sun Mar 10 14:48:16 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 10 Mar 2013 11:48:16 -0700 (PDT) Subject: Regular expression problem In-Reply-To: References: Message-ID: Hi Chris Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! import re if __name__ == "__main__": n = int ( raw_input() ) c = 1 while c <= n : email = filter ( lambda x : x != None , [ re.search ( '[a-zA-Z0-9][a-zA-Z0-9._]{4,}@[a-zA-Z0-9]+.(com|edu|org|co.in)' , x ) for x in raw_input().split(' ') ] ) t = len ( email ) print 'Case #' + str ( c ) + ': ' + str ( t ) for i in xrange ( t ) : print email[i].group() c += 1 Regards Mukesh Tiwari From mukeshtiwari.iiitm at gmail.com Sun Mar 10 14:48:16 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 10 Mar 2013 11:48:16 -0700 (PDT) Subject: Regular expression problem In-Reply-To: References: Message-ID: Hi Chris Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! import re if __name__ == "__main__": n = int ( raw_input() ) c = 1 while c <= n : email = filter ( lambda x : x != None , [ re.search ( '[a-zA-Z0-9][a-zA-Z0-9._]{4,}@[a-zA-Z0-9]+.(com|edu|org|co.in)' , x ) for x in raw_input().split(' ') ] ) t = len ( email ) print 'Case #' + str ( c ) + ': ' + str ( t ) for i in xrange ( t ) : print email[i].group() c += 1 Regards Mukesh Tiwari From rosuav at gmail.com Sun Mar 10 14:57:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Mar 2013 05:57:14 +1100 Subject: Regular expression problem In-Reply-To: References: Message-ID: On Mon, Mar 11, 2013 at 5:48 AM, mukesh tiwari wrote: > Hi Chris > Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! Excellent! Have fun. Incidentally, regular expressions aren't the only way to solve this sort of problem. If you get stuck with one method, it may be worth trying another one, to see if you can get around the issue. As they say, now you have two problems... ChrisA From mukeshtiwari.iiitm at gmail.com Sun Mar 10 14:05:56 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 10 Mar 2013 11:05:56 -0700 (PDT) Subject: Regular expression problem In-Reply-To: References: Message-ID: Hi Chris On the problem page, it is 3 second. > What is the time limit? I just tried it (Python 2.6 under Windows) and > > it finished in a humanly-immeasurable amount of time. Are you sure > > that STDIN (eg raw_input()) is where your test data is coming from? Yes, on SPOJ we read data from STDIN. Regards Mukesh Tiwari > > > > ChrisA From mukeshtiwari.iiitm at gmail.com Sun Mar 10 14:05:56 2013 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 10 Mar 2013 11:05:56 -0700 (PDT) Subject: Regular expression problem In-Reply-To: References: Message-ID: Hi Chris On the problem page, it is 3 second. > What is the time limit? I just tried it (Python 2.6 under Windows) and > > it finished in a humanly-immeasurable amount of time. Are you sure > > that STDIN (eg raw_input()) is where your test data is coming from? Yes, on SPOJ we read data from STDIN. Regards Mukesh Tiwari > > > > ChrisA From tjreedy at udel.edu Sun Mar 10 22:06:12 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Mar 2013 22:06:12 -0400 Subject: Regular expression problem In-Reply-To: References: Message-ID: On 3/10/2013 1:42 PM, mukesh tiwari wrote: > Hello all > I am trying to solve this problem[1] > [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all languages. Thus, a 'slow' python program may work correctly but the site will not let you know. A test that refuses to answer is no test at all. In the meanwhile, an algorithmically equivalent C program will be run and judged correct, so the programmer can try to speed up while not losing correctness. By teaching 'speed before correctness", this site promotes bad programming habits and thinking (and the use of low-level but faster languages). I quote your later response: "Now I am getting wrong answer so at least program is faster then previous one". If the previous one was correct and the revision wrong, you should toss the revision and go back to the correct program. I recommend that you work on problems where you have tests that you can actually run even before you code. -- Terry Jan Reedy From storchaka at gmail.com Mon Mar 11 14:30:36 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 11 Mar 2013 20:30:36 +0200 Subject: Regular expression problem In-Reply-To: References: Message-ID: On 11.03.13 04:06, Terry Reedy wrote: > On 3/10/2013 1:42 PM, mukesh tiwari wrote: >> Hello all >> I am trying to solve this problem[1] >> [1] http://www.spoj.com/problems/MAIN12C/ > > As I remember, and as it still appears, this site severely penalizes > Python solvers by using the same time limit for all languages. Thus, a > 'slow' python program may work correctly but the site will not let you > know. I'm sure the time limits are enough to solve most (if not all) of problems. Actually all submitted solutions on Python for this problem run from 0.47 to 0.61 seconds (http://www.spoj.com/ranks/MAIN12C/). From tjreedy at udel.edu Mon Mar 11 16:23:21 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Mar 2013 16:23:21 -0400 Subject: Regular expression problem In-Reply-To: References: Message-ID: On 3/11/2013 2:30 PM, Serhiy Storchaka wrote: > On 11.03.13 04:06, Terry Reedy wrote: >> On 3/10/2013 1:42 PM, mukesh tiwari wrote: >>> Hello all >>> I am trying to solve this problem[1] >>> [1] http://www.spoj.com/problems/MAIN12C/ >> >> As I remember, and as it still appears, this site severely penalizes >> Python solvers by using the same time limit for all languages. Thus, a >> 'slow' python program may work correctly but the site will not let you >> know. > > I'm sure the time limits are enough to solve most (if not all) of > problems. Actually all submitted solutions on Python for this problem > run from 0.47 to 0.61 seconds (http://www.spoj.com/ranks/MAIN12C/). You do not see the solutions that timed out. I suppose you are pointing to the fact that for this problem there are solutions close to but under the time limit. However, algorithm running times are not evenly distributed. Suppose, for instance) there is a correct O(n**2) solution and a correct O(n) solution and that the ones listed are the O(n) solutions. Then the Python O(n**2) solutions could easily take 10x longer to run and time out, while equivalent C solutions do not. Mukesh is not the first to post here a reasonable looking solution for that site that he could not judge because the test quite and refused to answer. I point out again that he was 'happy' to have a faster but incorrect program, even though it might have been a regression from his original. -- Terry Jan Reedy From wxjmfauth at gmail.com Mon Mar 11 05:28:14 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 11 Mar 2013 02:28:14 -0700 (PDT) Subject: Regular expression problem References: Message-ID: On 11 mar, 03:06, Terry Reedy wrote: > > ... > By teaching 'speed before correctness", this site promotes bad > programming habits and thinking (and the use of low-level but faster > languages). > ... This is exactly what "your" flexible string representation does! And away from technical aspects, you even succeeded to somehow lose unicode compliance. jmf From breamoreboy at yahoo.co.uk Mon Mar 11 06:19:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Mar 2013 10:19:51 +0000 Subject: Regular expression problem In-Reply-To: References: Message-ID: On 11/03/2013 09:28, jmfauth wrote: > On 11 mar, 03:06, Terry Reedy wrote: > >> >> ... >> By teaching 'speed before correctness", this site promotes bad >> programming habits and thinking (and the use of low-level but faster >> languages). >> ... > > > This is exactly what "your" flexible string representation > does! > > And away from technical aspects, you even succeeded to > somehow lose unicode compliance. > > jmf > Please stick to something you know about such as sexual self abuse. -- Cheers. Mark Lawrence From nad at acm.org Mon Mar 11 14:13:16 2013 From: nad at acm.org (Ned Deily) Date: Mon, 11 Mar 2013 11:13:16 -0700 Subject: On topic, please [Was:Re: Regular expression problem] References: Message-ID: A friendly reminder that this forum is for general discussion and questions about Python. "Pretty much anything Python-related is fair game for discussion, and the group is even fairly tolerant of off-topic digressions; there have been entertaining discussions of topics such as floating point, good software design, and other programming languages such as Lisp and Forth." But ... "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." http://www.python.org/community/lists/ It's up to all of us to help keep this group/list a place where people enjoy participating, without fear of gratuitous personal sniping. Thanks! -- Ned Deily, nad at acm.org From rustompmody at gmail.com Mon Mar 11 09:18:56 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 11 Mar 2013 06:18:56 -0700 (PDT) Subject: Regular expression problem References: Message-ID: <160bcdfd-2400-4d51-8431-93f47d962149@vh9g2000pbb.googlegroups.com> On Mar 11, 2:28?pm, jmfauth wrote: > On 11 mar, 03:06, Terry Reedy wrote: > > > > > ... > > By teaching 'speed before correctness", this site promotes bad > > programming habits and thinking (and the use of low-level but faster > > languages). > > ... > > This is exactly what "your" flexible string representation > does! This is an old complaint of your with no new data for supporting it > > And away from technical aspects, you even succeeded to > somehow lose unicode compliance. This is a new complaint. Just to make it clear: 1. All your recent complaints about unicode were in the realm of performance So your complaint that python has lost unicode compliance can mean one of: 2a. The unicode standard mandates performance criteria or 2b. There are problems with python's implementation (of strings?) that have functional problems apart from your old performance complaints or 2c. You need to look up what 'compliance' means My own choice is to have a mid-point between Very early binding: Narrow vs wide builds Very late binding: String reps can change with the characters as they are seen This mid point would be perhaps a commandline switch to choose string- engine attributes. However to make this choice even worth a second look we need to have hard data about performance that you have been unable to provide. [See the recent thread of RoR vs Django to see the problems of excessive spurious choice] From zuhaib.chohan88 at gmail.com Sun Mar 10 15:23:16 2013 From: zuhaib.chohan88 at gmail.com (zuhaib.chohan88 at gmail.com) Date: Sun, 10 Mar 2013 12:23:16 -0700 (PDT) Subject: how to make a tree with randomly selected html tags from an array in python? Message-ID: <673463f5-78e1-43a2-b5f9-59aa23a3bf20@googlegroups.com> I am new to python. I have xml file as an input to my python script "html.xml". I made an array which contains html tags: from xml.etree import ElementTree tree = ElementTree.parse("html.xml") olp = tree.findall("//tag_Name") mylist = [t.text for t in olp] print mylist The output is: [' !--...-- ', ' !DOCTYPE ', ' a ', ' abbr ', ' acronym ', ' address ', ' applet ', ' area ', ' article ', ' aside ', ' audio ', ' b ', ' base ', ' basefont ', ' bdi ', ' bdo ', ' big ', ' blockquote ', ' body ', ' br ', ' button ', ' canva s ', ' caption ', ' center ', ' cite ', ' code ', ' col ', ' colgroup ', ' comma nd ', ' datalist ', ' dd ', ' del ', ' details ', ' dfn ', ' dialog ', ' dir ', ' div ', ' dl ', ' dt ', ' em ', ' embed ', ' fieldset ', ' figcaption ', ' figu re ', ' font ', ' footer ', ' form ', ' frame ', ' frameset ', ' h1 to h6 ', ' h ead ', ' header ', ' hgroup ', ' hr ', ' html ', ' i ', ' iframe ', ' img ', ' i nput ', ' ins ', ' kbd ', ' keygen ', ' label ', ' legend ', ' li ', ' link ', ' map ', ' mark ', ' menu ', ' meta ', ' meter ', ' nav ', ' noframes ', ' noscri pt ', ' object ', ' ol ', ' optgroup ', ' option ', ' output ', ' p ', ' param ' , ' pre ', ' progress ', ' q ', ' rp ', ' rt ', ' ruby ', ' s ', ' samp ', ' scr ipt ', ' section ', ' select ', ' small ', ' source ', ' span ', ' strike ', ' s trong ', ' style ', ' sub ', ' summary ', ' sup ', ' table ', ' tbody ', ' td ', ' textarea ', ' tfoot ', ' th ', ' thead ', ' time ', ' title ', ' tr ', ' trac k ', ' tt ', ' u ', ' ul ', ' var ', ' video ', ' wbr '] >From the above array, I want to randomly select some tags and want to make a tree like: (As an example) Root node 'abbr' with child nodes 'a' and 'option' 'a' with child nodes 'video' and 'title' 'option' with child nodes 'output' and 'source' ...... Can anyone tell me how I can do that? what should be the code in python? From amkulkar at uci.edu Mon Mar 11 01:57:49 2013 From: amkulkar at uci.edu (Abhinav M Kulkarni) Date: Sun, 10 Mar 2013 22:57:49 -0700 Subject: Advice regarding multiprocessing module In-Reply-To: <513D6FEB.9040706@uci.edu> References: <513D6FEB.9040706@uci.edu> Message-ID: <513D725D.307@uci.edu> Dear all, I need some advice regarding use of the multiprocessing module. Following is the scenario: * I am running gradient descent to estimate parameters of a pairwise grid CRF (or a grid based graphical model). There are 106 data points. Each data point can be analyzed in parallel. * To calculate gradient for each data point, I need to perform approximate inference since this is a loopy model. I am using Gibbs sampling. * My grid is 9x9 so there are 81 variables that I am sampling in one sweep of Gibbs sampling. I perform 1000 iterations of Gibbs sampling. * My laptop has quad-core Intel i5 processor, so I thought using multiprocessing module I can parallelize my code (basically calculate gradient in parallel on multiple cores simultaneously). * I did not use the multi-threading library because of GIL issues, GIL does not allow multiple threads to run at a time. * As a result I end up creating a process for each data point (instead of a thread that I would ideally like to do, so as to avoid process creation overhead). * I am using basic NumPy array functionalities. Previously I was running this code in MATLAB. It runs quite faster, one iteration of gradient descent takes around 14 sec in MATLAB using parfor loop (parallel loop - data points is analyzed within parallel loop). However same program takes almost 215 sec in Python. I am quite amazed at the slowness of multiprocessing module. Is this because of process creation overhead for each data point? Please keep my email in the replies as I am not a member of this mailing list. Thanks, Abhinav -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 11 07:14:23 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 11 Mar 2013 12:14:23 +0100 (CET) Subject: Advice regarding multiprocessing module In-Reply-To: <513D725D.307@uci.edu> Message-ID: <1522066129.3339778.1363000462968.JavaMail.root@sequans.com> ----- Original Message ----- > Dear all, > I need some advice regarding use of the multiprocessing module. > Following is the scenario: > * I am running gradient descent to estimate parameters of a pairwise > grid CRF (or a grid based graphical model). There are 106 data > points. Each data point can be analyzed in parallel. > * To calculate gradient for each data point, I need to perform > approximate inference since this is a loopy model. I am using Gibbs > sampling. > * My grid is 9x9 so there are 81 variables that I am sampling in one > sweep of Gibbs sampling. I perform 1000 iterations of Gibbs > sampling. > * My laptop has quad-core Intel i5 processor, so I thought using > multiprocessing module I can parallelize my code (basically > calculate gradient in parallel on multiple cores simultaneously). > * I did not use the multi-threading library because of GIL issues, > GIL does not allow multiple threads to run at a time. > * As a result I end up creating a process for each data point > (instead of a thread that I would ideally like to do, so as to avoid > process creation overhead). > * I am using basic NumPy array functionalities. > Previously I was running this code in MATLAB. It runs quite faster, > one iteration of gradient descent takes around 14 sec in MATLAB > using parfor loop (parallel loop - data points is analyzed within > parallel loop). However same program takes almost 215 sec in Python. > I am quite amazed at the slowness of multiprocessing module. Is this > because of process creation overhead for each data point? > Please keep my email in the replies as I am not a member of this > mailing list. > Thanks, > Abhinav Hi, Can you post some code, especially the part where you're create/running the processes ? If it's not too big, the process function as well. Either multiprocess is slow like you stated, or you did something wrong. Alternatively, if posting code is an issue, you can profile your python code, it's very easy and effective at finding which the code is slowing down everyone. http://docs.python.org/2/library/profile.html Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From amkulkar at uci.edu Mon Mar 11 10:57:00 2013 From: amkulkar at uci.edu (Abhinav M Kulkarni) Date: Mon, 11 Mar 2013 07:57:00 -0700 Subject: Advice regarding multiprocessing module In-Reply-To: <1522066129.3339778.1363000462968.JavaMail.root@sequans.com> References: <1522066129.3339778.1363000462968.JavaMail.root@sequans.com> Message-ID: <513DF0BC.1000902@uci.edu> Hi Jean, Below is the code where I am creating multiple processes: if __name__ == '__main__': # List all files in the games directory files = list_sgf_files() # Read board configurations (intermediateBoards, finalizedBoards) = read_boards(files) # Initialize parameters param = Param() # Run maxItr iterations of gradient descent for itr in range(maxItr): # Each process analyzes one single data point # They dump their gradient calculations in queue q # Queue in Python is process safe start_time = time.time() q = Queue() jobs = [] # Create a process for each game board for i in range(len(files)): p = Process(target=TrainGoCRFIsingGibbs, args=(intermediateBoards[i], finalizedBoards[i], param, q)) p.start() jobs.append(p) # Blocking wait for each process to finish for p in jobs: p.join() elapsed_time = time.time() - start_time print 'Iteration: ', itr, '\tElapsed time: ', elapsed_time As you recommended, I'll use the profiler to see which part of the code is slow. Thanks, Abhinav On 03/11/2013 04:14 AM, Jean-Michel Pichavant wrote: > ----- Original Message ----- > >> Dear all, >> I need some advice regarding use of the multiprocessing module. >> Following is the scenario: >> * I am running gradient descent to estimate parameters of a pairwise >> grid CRF (or a grid based graphical model). There are 106 data >> points. Each data point can be analyzed in parallel. >> * To calculate gradient for each data point, I need to perform >> approximate inference since this is a loopy model. I am using Gibbs >> sampling. >> * My grid is 9x9 so there are 81 variables that I am sampling in one >> sweep of Gibbs sampling. I perform 1000 iterations of Gibbs >> sampling. >> * My laptop has quad-core Intel i5 processor, so I thought using >> multiprocessing module I can parallelize my code (basically >> calculate gradient in parallel on multiple cores simultaneously). >> * I did not use the multi-threading library because of GIL issues, >> GIL does not allow multiple threads to run at a time. >> * As a result I end up creating a process for each data point >> (instead of a thread that I would ideally like to do, so as to avoid >> process creation overhead). >> * I am using basic NumPy array functionalities. >> Previously I was running this code in MATLAB. It runs quite faster, >> one iteration of gradient descent takes around 14 sec in MATLAB >> using parfor loop (parallel loop - data points is analyzed within >> parallel loop). However same program takes almost 215 sec in Python. >> I am quite amazed at the slowness of multiprocessing module. Is this >> because of process creation overhead for each data point? >> Please keep my email in the replies as I am not a member of this >> mailing list. >> Thanks, >> Abhinav > Hi, > > Can you post some code, especially the part where you're create/running the processes ? If it's not too big, the process function as well. > > Either multiprocess is slow like you stated, or you did something wrong. > > Alternatively, if posting code is an issue, you can profile your python code, it's very easy and effective at finding which the code is slowing down everyone. > http://docs.python.org/2/library/profile.html > > Cheers, > > JM > > > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Mon Mar 11 11:58:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 11 Mar 2013 15:58:54 +0000 Subject: Advice regarding multiprocessing module In-Reply-To: <513DF0BC.1000902@uci.edu> References: <1522066129.3339778.1363000462968.JavaMail.root@sequans.com> <513DF0BC.1000902@uci.edu> Message-ID: On 11 March 2013 14:57, Abhinav M Kulkarni wrote: > Hi Jean, > > Below is the code where I am creating multiple processes: > > if __name__ == '__main__': > # List all files in the games directory > files = list_sgf_files() > > # Read board configurations > (intermediateBoards, finalizedBoards) = read_boards(files) > > # Initialize parameters > param = Param() > > # Run maxItr iterations of gradient descent > for itr in range(maxItr): > # Each process analyzes one single data point > # They dump their gradient calculations in queue q > # Queue in Python is process safe > start_time = time.time() > q = Queue() > jobs = [] > # Create a process for each game board > for i in range(len(files)): > p = Process(target=TrainGoCRFIsingGibbs, args=(intermediateBoards[i], finalizedBoards[i], param, q)) Use a multiprocessing.Pool for this, rather than creating one process for each job. e.g.: p = Pool(4) # 1 process for each core results = [] for ib, fb in zip(intermediateBoards, finalizedBoards): results.append(p.apply_async(TrainGoCRFIsingGibbs, args=(ib, fb, param, q))) p.close() p.join() # To retrieve the return values for r in results: print(r.get()) This will distribute your jobs over a fixed number of processes. You avoid the overhead of creating and killing processes and the process switching that occurs when you have more processes than cores. > p.start() > jobs.append(p) > # Blocking wait for each process to finish > for p in jobs: > p.join() > elapsed_time = time.time() - start_time > print 'Iteration: ', itr, '\tElapsed time: ', elapsed_time > > As you recommended, I'll use the profiler to see which part of the code is > slow. Do this without using multiprocessing first. Loosely you can hope that multiprocessing would give you a factor of 4 speedup but no more. You haven't reported a comparison of times with/without multiprocessing so it's not clear that that is the issue. Oscar From davea at davea.name Mon Mar 11 07:27:28 2013 From: davea at davea.name (Dave Angel) Date: Mon, 11 Mar 2013 07:27:28 -0400 Subject: Advice regarding multiprocessing module In-Reply-To: <513D725D.307@uci.edu> References: <513D6FEB.9040706@uci.edu> <513D725D.307@uci.edu> Message-ID: <513DBFA0.6010001@davea.name> On 03/11/2013 01:57 AM, Abhinav M Kulkarni wrote: > > > > * My laptop has quad-core Intel i5 processor, so I thought using > multiprocessing module I can parallelize my code (basically > calculate gradient in parallel on multiple cores simultaneously). > * As a result I end up creating a process for each data point (instead > of a thread that I would ideally like to do, so as to avoid process > creation overhead). Seems you only need 4 processes, as you have 4 cores. Instead of creating a new one each time, reuse the same 4 processes, letting each do a quarter of the data. It's not the process creation that's particularly slow, but all the initialization of starting another instance of Python. If you're on Linux, you might be able to speed that up by using fork, but I don't specifically know. -- DaveA From i at introo.me Mon Mar 11 10:42:38 2013 From: i at introo.me (Shiyao Ma) Date: Mon, 11 Mar 2013 22:42:38 +0800 Subject: How to quickly set up a multithreaded server that can handle http file post. Message-ID: Today I come across a problem. Basically, my need is that I want to launch a http server that can not only support get but also support post (including post file). My first idea is to use -m http.sever. However, it only supports get. Later I find some one extended basehttpserver and made it support post. However it is not multithreaded. Is it easy to write a RELIABLE (I mean under normal cases) multithreaded server that suits my need. Also, are there any already invented wheel I can use? Thx -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsgroups at afrosoft.ca Mon Mar 11 13:02:28 2013 From: newsgroups at afrosoft.ca (Xavier L.) Date: Mon, 11 Mar 2013 13:02:28 -0400 Subject: How to quickly set up a multithreaded server that can handle http file post. In-Reply-To: References: Message-ID: On 13-03-11 10:42 AM, Shiyao Ma wrote: > Today I come across a problem. > Basically, my need is that I want to launch a http server that can not > only support get but also support post (including post file). > My first idea is to use -m http.sever. However, it only supports get. > Later I find some one extended basehttpserver and made it support post. > However it is not multithreaded. > > Is it easy to write a RELIABLE (I mean under normal cases) multithreaded > server that suits my need. > Also, are there any already invented wheel I can use? > > Thx > > > -- > My gpg pubring is available via: gpg --keyserver subkeys.pgp.net > --recv-keys 307CF736 > > More on: http://about.me/introom > The best would be to use an existing webserver, such as Apache, Nginx, Lighttpd, etc. with python running as a fcgi or cgi script. Those webservers have been tested for longer and there is no need to reinvent the wheel. X From i at introo.me Mon Mar 11 20:16:55 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 12 Mar 2013 08:16:55 +0800 Subject: How to quickly set up a multithreaded server that can handle http file post. In-Reply-To: References: Message-ID: Yes, sounds good. I should give it a try. On Tue, Mar 12, 2013 at 1:02 AM, Xavier L. wrote: > On 13-03-11 10:42 AM, Shiyao Ma wrote: > >> Today I come across a problem. >> Basically, my need is that I want to launch a http server that can not >> only support get but also support post (including post file). >> My first idea is to use -m http.sever. However, it only supports get. >> Later I find some one extended basehttpserver and made it support post. >> However it is not multithreaded. >> >> Is it easy to write a RELIABLE (I mean under normal cases) multithreaded >> server that suits my need. >> Also, are there any already invented wheel I can use? >> >> Thx >> >> >> -- >> My gpg pubring is available via: gpg --keyserver subkeys.pgp.net >> --recv-keys 307CF736 >> >> More on: http://about.me/introom >> >> The best would be to use an existing webserver, such as Apache, Nginx, > Lighttpd, etc. with python running as a fcgi or cgi script. > > Those webservers have been tested for longer and there is no need to > reinvent the wheel. > > X > -- > http://mail.python.org/**mailman/listinfo/python-list > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From thinksoft.ithub at gmail.com Mon Mar 11 11:19:04 2013 From: thinksoft.ithub at gmail.com (thinksoft.ithub at gmail.com) Date: Mon, 11 Mar 2013 08:19:04 -0700 (PDT) Subject: Very Urgent Requirement, Interview within 3 hours-immediate start Message-ID: Please review the Requirements? which are quit urgent with our client it?s immediate hire, Please forward the Resumes with expected rate and skills matrix, Please send as the resume of your own W2 consultants Send your Resumes to stay at thinksofttech.com or reach me on 302-343-7478 Requirement 1 Title: Informatica Developer Duration: 6 months to start Interview: Phone and/or Skype Location: Jacksonville, FL 2-3 years of Informatica 5-10 years of PL/SQL 5-10 years of SQL 3-5 years of UNIX Must- Have Skills/ Qualifications: ? Bachelor's degree in computer science, information systems, or equivalent ? 3+ years of application development experience ? Experience in the software delivery lifecycle ? Skilled in Oracle, PL/SQL, and stored procedure development ? Skilled in Unix (AIX) and shell scripting ? Two to three years of interface development with Informatica ? Experience with Callidus/TrueComp or similar application preferred ? Experience working with MS Office products(i.e. Visio, MS Access) ? Strong verbal and written communication skills Nice-To-Have Skills/ Qualifications: ? Experience and/ or training in the Rational Suite of products ? Experience in the Health Insurance Industry Requirement 2: Sr. Systems Engineer - EPIC 12 month (Only US Citizen) Clear Lake, TX Skills required: ? Cache database administration ? Epic system administration ? Solaris ? SAN knowledge ? preferably Netapp ? Excellent scripting skills ? Excellent communication, team work, and customer service skills. Facility Job Description: Seeking Position for: Senior Systems Engineer - Epic This position is for an Epic Cache Systems Manager. Primary high-level responsibilities include Cache support, and Epic core systems support. The person selected will be a certified Cache Database Administrator and will have a broad and deep understanding of supporting mission-critical Epic systems on a Sun Solaris platform using Veritas Foundations Suite and Netapp SANs. This position will provide direct support to Clinical IT Application teams and be focused on maintaining 100% uptime for UTMB?s electronic health system (EPIC). Demonstrated experience should include installation, configuration, and management of multiple Epic and Cache environments on a Solaris platform. The candidate should have expertise in Cache configuration, Cache monitoring, Cache backup and recovery, Cache performance monitoring and tuning, Cache shadowing, Cache journaling, and Cache security. In depth experience of ancillary systems is also required. This would include products like Red Alert, System Pulse, Data Courier, Interconnect, Environment Copy Utility, and others. Responsibilities to include: ? Installing, configuring, and maintaining multiple Cache instances and Epic environments ? Establishing system performance analysis and tuning methodologies. ? Managing Epic utilities like Red Alert, System Pulse, Data Courier, and ECU ? Ensuring fault tolerance and high availability by implementing appropriate software and hardware solutions. ? Implementing automated backup, recovery, and fail-over routines. ? Participating in application upgrades ? Participating in application migration to alternate data centers ? Working closely with application teams Please send the resumes to stacy at thinksofttech.com and reach me on 302-343-7478 From insideshoes at gmail.com Mon Mar 11 11:23:05 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 11 Mar 2013 16:23:05 +0100 Subject: working with dict : incrementing dict dynamically Message-ID: I am trying to create a dictionary with a key and its values seraching from a data set. But something is going wrong. This is the first time I am working with dicts. My code is : import cv def Computesegclass(segimage): num_pixel = 0 for y in xrange(0, segimage.height): for x in xrange(0, segimage.width): if segimage[y,x] == (0.0, 0.0, 0.0): continue else: color = segimage[y,x] blue = color[0] green = color[1] red = color[2] region_num = blue + 256 * green + 65536 * red print region_num segments = dict({region_num : num_pixel}) if region_num == region_num: num_pixel = +1 print segments if __name__== "__main__": segimage = cv.LoadImageM("Z:/Segmentation/segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED) print segimage Computesegclass(segimage) here I am traversing through an image which is 3000 x 3000. for each pixel I calculate a region number. What I am trying to do is increase the num_pixel by 1 if that pixel falls in the same region which is identified by region_num. How can I do it in dict created ? Thanx in Advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Mon Mar 11 11:37:14 2013 From: gordon at panix.com (John Gordon) Date: Mon, 11 Mar 2013 15:37:14 +0000 (UTC) Subject: working with dict : incrementing dict dynamically References: Message-ID: In inshu chauhan writes: > --14dae93408ffe4594104d7a7bf0c > Content-Type: text/plain; charset=ISO-8859-1 > I am trying to create a dictionary with a key and its values seraching from > a data set. But something is going wrong. This is the first time I am > working with dicts. > My code is : > import cv > def Computesegclass(segimage): > num_pixel = 0 > for y in xrange(0, segimage.height): > for x in xrange(0, segimage.width): > if segimage[y,x] == (0.0, 0.0, 0.0): > continue > else: > color = segimage[y,x] > blue = color[0] > green = color[1] > red = color[2] > region_num = blue + 256 * green + 65536 * red > print region_num > segments = dict({region_num : num_pixel}) You're creating a new segments dictionary for each pixel, overwriting the previous one. Instead, you probably want to create an empty dictionary at the top of your function. > if region_num == region_num: This if statement will always evaluate true, because you're comparing region_num to itself. > num_pixel = +1 This doesn't store the value of num_pixel in the dictionary. You probably want to do this instead: segments[region_num] += 1 -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From svenito at gmail.com Mon Mar 11 11:53:39 2013 From: svenito at gmail.com (Sven) Date: Mon, 11 Mar 2013 15:53:39 +0000 Subject: working with dict : incrementing dict dynamically In-Reply-To: References: Message-ID: On 11 March 2013 15:23, inshu chauhan wrote: > I am trying to create a dictionary with a key and its values seraching > from a data set. But something is going wrong. This is the first time I am > working with dicts. > > My code is : > > import cv > def Computesegclass(segimage): > num_pixel = 0 > for y in xrange(0, segimage.height): > for x in xrange(0, segimage.width): > > if segimage[y,x] == (0.0, 0.0, 0.0): > continue > else: > color = segimage[y,x] > blue = color[0] > green = color[1] > red = color[2] > region_num = blue + 256 * green + 65536 * red > print region_num > segments = dict({region_num : num_pixel}) > if region_num == region_num: > num_pixel = +1 > print segments > > if __name__== "__main__": > segimage = > cv.LoadImageM("Z:/Segmentation/segmentation_numbers_00000.tif", > cv.CV_LOAD_IMAGE_UNCHANGED) > print segimage > Computesegclass(segimage) > > > here I am traversing through an image which is 3000 x 3000. for each pixel > I calculate a region number. What I am trying to do is increase the > num_pixel by 1 if that pixel falls in the same region which is identified > by region_num. How can I do it in dict created ? > > Thanx in Advance > > If I am understanding you correctly you want to accumulate a pixel count for each region. I would suggest a default dict, and that you do something like from collections import defaultdict def ComputeSegClass(seqimage): segments = defaultdict(int) if region_num == region_num: segments[region_num] += 1 But as John mentioned, your comparison here will always be true, so you will need to fix this to test for your case. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From Robert.Flintham at uhb.nhs.uk Mon Mar 11 11:32:48 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Mon, 11 Mar 2013 15:32:48 +0000 Subject: Reversing bits in a byte Message-ID: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> Hi, I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per pixel). I can't work out how I would go about displaying this image. Does anyone have any thoughts? All the best, Rob Robert Flintham Trainee Clinical Scientist - MRI Tel: +44 (0)121 371 7000 Email: Robert.Flintham at uhb.nhs.uk Web: http://www.uhb.nhs.uk We're bringing the world's most advanced cancer treatments to Birmingham. Find out more at www.qecancerappeal.org or text QEHB01 ?5 to 70070 to donate ?5 to our appeal. RRPPS Medical Physics - University Hospitals Birmingham NHS Foundation Trust 63 Melchett Road, Kings Norton, Birmingham, B30 3HP [cid:image001.gif at 01CE1E6D.AF57F9D0] DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.gif Type: image/gif Size: 1941 bytes Desc: image001.gif URL: From davea at davea.name Tue Mar 12 08:46:39 2013 From: davea at davea.name (Dave Angel) Date: Tue, 12 Mar 2013 08:46:39 -0400 Subject: Reversing bits in a byte In-Reply-To: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> Message-ID: <513F23AF.8070907@davea.name> On 03/11/2013 11:32 AM, Robert Flintham wrote: > Hi, > > I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per pixel). I can't work out how I would go about displaying this image. Does anyone have any thoughts? > > All the best, > Rob > > How does your subject line relate to your question? But more importantly, what version of Python, what OS, and which GUI library (wxpython, qt, etc.) are you used to? Specify those, and somebody familiar with that particular library will probably pop up with an answer. -- DaveA From Robert.Flintham at uhb.nhs.uk Tue Mar 12 09:28:28 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Tue, 12 Mar 2013 13:28:28 +0000 Subject: Reversing bits in a byte In-Reply-To: <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> Message-ID: <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> Sorry, the subject line was for a related question that I decided not to ask, I forgot to change it when I changed my email. I've changed it now! I'm using Python 3.3 on Windows with the pydicom module (http://code.google.com/p/pydicom/). Using pydicom, I've ended up with a "bytes" object of length (512*512/8 = 32768) containing a 512x512 1-bit bitmap (i.e. each byte represents 8 pixels of either 1 or 0). When I print this to screen I get: 'b\x00\x00\x00.....' I can unpack this to a tuple of the integer representations of binary data, but that doesn't really help as presume I need the binary (8 digit) representation to be able to translate that into an image. I wasn't sure which GUI library to use, so haven't specified one. As it's Python 3, Tkinter is available. I also have matplotlib and numpy installed, and PIL. Ideally, I'd like to be able to access the pixel data in the form of a numpy array so that I can perform image-processing tasks on the data. So now that I've explained myself slightly more fully, does anyone have any thoughts on how to do this? All the best, Rob Robert Flintham Trainee Clinical Scientist - MRI Tel: +44 (0)121 371 7000 Email: Robert.Flintham at uhb.nhs.uk Web: http://www.uhb.nhs.uk We're bringing the world's most advanced cancer treatments to Birmingham. Find out more at www.qecancerappeal.org or text QEHB01 ?5 to 70070 to donate ?5 to our appeal. RRPPS Medical Physics - University Hospitals Birmingham NHS Foundation Trust 63 Melchett Road, Kings Norton, Birmingham, B30 3HP ? Delivering the best in care -----Original Message----- From: Python-list [mailto:python-list-bounces+robert.flintham=uhb.nhs.uk at python.org] On Behalf Of Dave Angel Sent: 12 March 2013 12:47 To: python-list at python.org Subject: Re: Reversing bits in a byte On 03/11/2013 11:32 AM, Robert Flintham wrote: > Hi, > > I have a 'bytes' object which contains a simple bitmap image (i.e. 1 bit per pixel). I can't work out how I would go about displaying this image. Does anyone have any thoughts? > > All the best, > Rob > > How does your subject line relate to your question? But more importantly, what version of Python, what OS, and which GUI library (wxpython, qt, etc.) are you used to? Specify those, and somebody familiar with that particular library will probably pop up with an answer. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. From oscar.j.benjamin at gmail.com Tue Mar 12 10:59:09 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 12 Mar 2013 14:59:09 +0000 Subject: Reversing bits in a byte In-Reply-To: <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> Message-ID: On 12 March 2013 13:28, Robert Flintham wrote: > Sorry, the subject line was for a related question that I decided not to ask, I forgot to change it when I changed my email. I've changed it now! > > I'm using Python 3.3 on Windows with the pydicom module (http://code.google.com/p/pydicom/). Using pydicom, I've ended up with a "bytes" object of length (512*512/8 = 32768) containing a 512x512 1-bit bitmap (i.e. each byte represents 8 pixels of either 1 or 0). When I print this to screen I get: > 'b\x00\x00\x00.....' > > I can unpack this to a tuple of the integer representations of binary data, but that doesn't really help as presume I need the binary (8 digit) representation to be able to translate that into an image. > > I wasn't sure which GUI library to use, so haven't specified one. As it's Python 3, Tkinter is available. I also have matplotlib and numpy installed, and PIL. > > Ideally, I'd like to be able to access the pixel data in the form of a numpy array so that I can perform image-processing tasks on the data. > > So now that I've explained myself slightly more fully, does anyone have any thoughts on how to do this? Numpy and matplotlib will do what you want: import numpy as np import matplotlib.pyplot as plt def bits_to_ndarray(bits, shape): abytes = np.frombuffer(bits, dtype=np.uint8) abits = np.zeros(8 * len(abytes), np.uint8) for n in range(8): abits[n::8] = (abytes % (2 ** (n+1))) != 0 return abits.reshape(shape) # 8x8 image = 64 bits bytes object bits = b'\x00\xff' * 4 img = bits_to_ndarray(bits, shape=(8, 8)) plt.imshow(img) plt.show() Oscar From oscar.j.benjamin at gmail.com Tue Mar 12 11:44:50 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 12 Mar 2013 15:44:50 +0000 Subject: Reversing bits in a byte In-Reply-To: References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> Message-ID: On 12 March 2013 14:59, Oscar Benjamin wrote: > Numpy and matplotlib will do what you want: > > import numpy as np > import matplotlib.pyplot as plt > > def bits_to_ndarray(bits, shape): > abytes = np.frombuffer(bits, dtype=np.uint8) > abits = np.zeros(8 * len(abytes), np.uint8) > for n in range(8): > abits[n::8] = (abytes % (2 ** (n+1))) != 0 Whoops! The line above should be abits[n::8] = (abytes & (2 ** n)) != 0 > return abits.reshape(shape) > > # 8x8 image = 64 bits bytes object > bits = b'\x00\xff' * 4 > > img = bits_to_ndarray(bits, shape=(8, 8)) > plt.imshow(img) > plt.show() > > > Oscar From dihedral88888 at googlemail.com Tue Mar 12 12:00:51 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 12 Mar 2013 09:00:51 -0700 (PDT) Subject: Reversing bits in a byte In-Reply-To: References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> Message-ID: <8f1fc478-54ee-4cdc-9074-81e9c01a4b17@googlegroups.com> Oscar Benjamin? 2013?3?12????UTC+8??11?44?50???? > On 12 March 2013 14:59, Oscar Benjamin wrote: > > > Numpy and matplotlib will do what you want: > > > > > > import numpy as np > > > import matplotlib.pyplot as plt > > > > > > def bits_to_ndarray(bits, shape): > > > abytes = np.frombuffer(bits, dtype=np.uint8) > > > abits = np.zeros(8 * len(abytes), np.uint8) > > > for n in range(8): > > > abits[n::8] = (abytes % (2 ** (n+1))) != 0 > > > > Whoops! The line above should be > > abits[n::8] = (abytes & (2 ** n)) != 0 > > > > > return abits.reshape(shape) > > > > > > # 8x8 image = 64 bits bytes object > > > bits = b'\x00\xff' * 4 > > > > > > img = bits_to_ndarray(bits, shape=(8, 8)) > > > plt.imshow(img) > > > plt.show() > > > > > > > > > Oscar Now the dram is so cheap in the street. Please type in a tuple of all 8 bit inversions from the index to the result then just take a look up by the index to solve the problem. # there are ways to exchange the top 4 bits and the low 4bits, then swap inside the nibbles then swap the 4 2bit pairs in the old way. From dihedral88888 at googlemail.com Tue Mar 12 12:00:51 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 12 Mar 2013 09:00:51 -0700 (PDT) Subject: Reversing bits in a byte In-Reply-To: References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312124931.C08D44482E5@nhs-pd1e-esg001.ad1.nhs.net> <20130312132840.B5A8D44863A@nhs-pd1e-esg102.ad1.nhs.net> Message-ID: <8f1fc478-54ee-4cdc-9074-81e9c01a4b17@googlegroups.com> Oscar Benjamin? 2013?3?12????UTC+8??11?44?50???? > On 12 March 2013 14:59, Oscar Benjamin wrote: > > > Numpy and matplotlib will do what you want: > > > > > > import numpy as np > > > import matplotlib.pyplot as plt > > > > > > def bits_to_ndarray(bits, shape): > > > abytes = np.frombuffer(bits, dtype=np.uint8) > > > abits = np.zeros(8 * len(abytes), np.uint8) > > > for n in range(8): > > > abits[n::8] = (abytes % (2 ** (n+1))) != 0 > > > > Whoops! The line above should be > > abits[n::8] = (abytes & (2 ** n)) != 0 > > > > > return abits.reshape(shape) > > > > > > # 8x8 image = 64 bits bytes object > > > bits = b'\x00\xff' * 4 > > > > > > img = bits_to_ndarray(bits, shape=(8, 8)) > > > plt.imshow(img) > > > plt.show() > > > > > > > > > Oscar Now the dram is so cheap in the street. Please type in a tuple of all 8 bit inversions from the index to the result then just take a look up by the index to solve the problem. # there are ways to exchange the top 4 bits and the low 4bits, then swap inside the nibbles then swap the 4 2bit pairs in the old way. From Robert.Flintham at uhb.nhs.uk Tue Mar 12 09:31:28 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Tue, 12 Mar 2013 13:31:28 +0000 Subject: Reversing bits in a byte In-Reply-To: <20130312131906.C4FC444A193@nhs-pd1e-esg002.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> <20130312131906.C4FC444A193@nhs-pd1e-esg002.ad1.nhs.net> Message-ID: <20130312133136.ABAE244888A@nhs-pd1e-esg102.ad1.nhs.net> Further to my earlier reply to Dave: I'd like to either display the image in a GUI, or save it in a format that can be opened easily in Windows (like a PNG or a 24-bit BMP). I know the dimensions as it's coming from the header of a DICOM file. I'm trying to analyse DICOM images where an 'overlay' image is stored as a bitmap in the header information. So the bitmap data is one DICOM tag (6000,3000) and the height and width of the overlay are in two other tags (6000,0010) and (6000,0011). All the best, Rob Robert Flintham Trainee Clinical Scientist - MRI Tel: +44 (0)121 371 7000 Email: Robert.Flintham at uhb.nhs.uk Web: http://www.uhb.nhs.uk We're bringing the world's most advanced cancer treatments to Birmingham. Find out more at www.qecancerappeal.org or text QEHB01 ?5 to 70070 to donate ?5 to our appeal. RRPPS Medical Physics - University Hospitals Birmingham NHS Foundation Trust 63 Melchett Road, Kings Norton, Birmingham, B30 3HP ? Delivering the best in care -----Original Message----- From: Tim Chase [mailto:python.list at tim.thechases.com] Sent: 12 March 2013 13:21 To: Robert Flintham Cc: 'python-list at python.org' Subject: Re: Reversing bits in a byte On 2013-03-11 15:32, Robert Flintham wrote: > I have a 'bytes' object which contains a simple bitmap image (i.e. > 1 bit per pixel). I can't work out how I would go about displaying > this image. Does anyone have any thoughts? You'd need to detail - how you want to display it (console, GUI, web page) - how you know what the dimensions are - the bit order It could be something as simple as HEIGHT = 40 some_bytes = file('data.bin').read() WIDTH = len(some_bytes) // HEIGHT for i, byte in enumerate(some_bytes): if i and i % WIDTH == 0: print # a new line for bit in range(8): if byte & (1 << bit): print '*', else: print ' ', -tkc > DISCLAIMER: [trim a paragraph of useless junk] Please remove these disclaimers if at all possible. You're posting to a public forum, which pretty much waives all credibility to the disclaimer (not that they've held much legal standing in any argument I've heard). DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. From python.list at tim.thechases.com Tue Mar 12 09:20:54 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 12 Mar 2013 08:20:54 -0500 Subject: Reversing bits in a byte In-Reply-To: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> References: <20130311153254.078484489A7@nhs-pd1e-esg101.ad1.nhs.net> Message-ID: <20130312082054.6f258aaa@bigbox.christie.dr> On 2013-03-11 15:32, Robert Flintham wrote: > I have a 'bytes' object which contains a simple bitmap image (i.e. > 1 bit per pixel). I can't work out how I would go about displaying > this image. Does anyone have any thoughts? You'd need to detail - how you want to display it (console, GUI, web page) - how you know what the dimensions are - the bit order It could be something as simple as HEIGHT = 40 some_bytes = file('data.bin').read() WIDTH = len(some_bytes) // HEIGHT for i, byte in enumerate(some_bytes): if i and i % WIDTH == 0: print # a new line for bit in range(8): if byte & (1 << bit): print '*', else: print ' ', -tkc > DISCLAIMER: [trim a paragraph of useless junk] Please remove these disclaimers if at all possible. You're posting to a public forum, which pretty much waives all credibility to the disclaimer (not that they've held much legal standing in any argument I've heard). From proteus.cronus at gmail.com Mon Mar 11 14:14:16 2013 From: proteus.cronus at gmail.com (proteus.cronus at gmail.com) Date: Mon, 11 Mar 2013 11:14:16 -0700 (PDT) Subject: Arcade Game Programming with Python Message-ID: If you know someone that wants to learn to program their own arcade games, check out: http://ProgramArcadeGames.com * 84 free tutorial videos * Start creating graphics by Chapter 5 * Full text of the book on-line. * Cookbook of 47 example programs * On-line multiple choice quizzes track your progress * Short-answer questions test your knowledge in more depth. * Labs ? see if you understand by creating your own games. * Sample tests ? Test your knowledge. * Program in Python * Track, grade, and mentor students' progress through the course I've put this book together and refined it from year-to-year based on student feedback during their first semester of programming at Simpson College. This is a first-semester course and assumes no prior knowledge of programming. I've successfully run hundreds of students through this course and had them create their own arcade games. Each time I refine the course and use their questions to make the book that much better. Plus, there are Russian and Turkish translations thanks to some volunteers! From tinnews at isbd.co.uk Mon Mar 11 14:21:16 2013 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Mon, 11 Mar 2013 18:21:16 +0000 Subject: Can't get any output from python-sqlkit, how to diagnose? Message-ID: I am trying to use python-sqlkit (https://pypi.python.org/pypi/sqlkit/0.9.5.1) but I'm not really getting over the first hurdle. If I run sqledit (the ready made executable that needs no programming) on my data then it works fine and displays my table data. However if I enter the minimal example given in the documentation (changing the database and table names to mine of course) I get no output, no errors either, just nothing (apart from two warning messages which are also output by the sqledit standalone). My code is as follows:- #!/usr/bin/python from sqlkit.widgets import SqlTable, SqlMask from sqlkit import DbProxy db = DbProxy(engine='sqlite:////home/chris/.sqledit/money.db') t = SqlMask('jessica', dbproxy=db) t.reload() ... this is the example given at http://sqlkit.argolinux.org/sqlkit/sqlwidget.html I'm not convinced that this is a complete example though (obviously not as it doesn't work). Can someone point me at a minimal python program for getting the GUI off the ground using sqlkit please. Or alternatively tell me what I have to add to the above. -- Chris Green From jstuardo at desytec.com Mon Mar 11 14:55:34 2013 From: jstuardo at desytec.com (Jaime Stuardo) Date: Mon, 11 Mar 2013 15:55:34 -0300 Subject: Problem installing Pyparsing Message-ID: <009f01ce1e8a$03e89f60$0bb9de20$@com> Hello I have downloaded pyparsing-2.0.0 files. When I run ?python setup.py install? I get this error: Traceback (most recent call last): File "setup.py", line 9, in from pyparsing import __version__ as pyparsing_version File "/tmp/openerp-7.0-20130311-002114/pyparsing-2.0.0/pyparsing.py", line 629 nonlocal limit,foundArity ^ SyntaxError: invalid syntax How can I solve it? Thanks Jaime Esta comunicaci?n (incluidos sus anexos) es Informaci?n Confidencial, dirigida exclusivamente a su destinatario, quien deber? resguardar la confidencialidad. Queda prohibido la divulgaci?n, modificaci?n, reproducci?n o uso de la informaci?n aqu? contenida por cualquier otra persona que no sea su destinatario. Si Ud. ha recibido este mail por error, le agradeceremos nos lo informe a la brevedad respondiendo a este e-mail a la direcci?n del remitente, destruya las copias y por favor, borre de su sistema el mensaje recibido. This message (including any attachments) constitutes Confidential Information, and is intended for the exclusive use of the named addressee, who shall preserve its confidentiality. Readers of this message other than the intended recipient are forbidden to disseminate, modify, distribute or reproduce this message. If you have received this email in error please notify us immediately by replying to the sender of this message, discard any copies, and delete this message from your system. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Mar 11 16:15:17 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Mar 2013 14:15:17 -0600 Subject: Problem installing Pyparsing In-Reply-To: <009f01ce1e8a$03e89f60$0bb9de20$@com> References: <009f01ce1e8a$03e89f60$0bb9de20$@com> Message-ID: On Mon, Mar 11, 2013 at 12:55 PM, Jaime Stuardo wrote: > Hello? > > I have downloaded pyparsing-2.0.0 files. When I run ?python setup.py > install? I get this error: > > Traceback (most recent call last): > File "setup.py", line 9, in > from pyparsing import __version__ as pyparsing_version > File "/tmp/openerp-7.0-20130311-002114/pyparsing-2.0.0/pyparsing.py", line > 629 > nonlocal limit,foundArity > ^ > SyntaxError: invalid syntax > > > How can I solve it? nonlocal is a Python 3 keyword. The error suggests that you are probably running this with Python 2. Either upgrade your Python version to 3.x or find another version of pyparsing that supports Python 2. From hossamalagmy at gmail.com Mon Mar 11 17:44:52 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Mon, 11 Mar 2013 14:44:52 -0700 (PDT) Subject: =?windows-1256?B?1ebRIOHHyOTlIMfhx9rhx+PsIMjH0+Mg7ebT3Q==?= Message-ID: ??? ????? ???????? ???? ???? https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fnatigtas7ab.blogspot.com%2F2013%2F03%2Fblog-post_5505.html%23.UT5PNJwVeBF.facebook From yushang at outlook.com Mon Mar 11 18:22:24 2013 From: yushang at outlook.com (shangyu) Date: Tue, 12 Mar 2013 06:22:24 +0800 Subject: metatype Message-ID: -----????----- ???: "shangyu" ????: ?2013/?3/?12 0:20 ???: "core-mentorship at python.org" ??: [Core-mentorship] metatype Hi dear all, I have following Python code class mydict(dict): def __init__(self): pass I wonder how this new type get created . What is the type of metatype in the following line ? type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots); (line 2296 of typeobject.c Python2.7.3 source code) It seems PyDict_Type . If so , how do I expect the tp_alloc will return a PyTypeObject object ? Maybe I've missed something ? Many thanks!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From yushang at outlook.com Mon Mar 11 21:27:36 2013 From: yushang at outlook.com (shangyu) Date: Tue, 12 Mar 2013 09:27:36 +0800 Subject: metatype In-Reply-To: References: Message-ID: I think I've found it out . For new-style class it's PyType_Type and for old-style class it's PyClass_Type . Thanks anyway. To: python-list at python.org From: yushang at outlook.com Subject: metatype Date: Tue, 12 Mar 2013 06:22:24 +0800 ???: shangyu ????: ?2013/?3/?12 0:20 ???: core-mentorship at python.org ??: [Core-mentorship] metatype Hi dear all, I have following Python code class mydict(dict): def __init__(self): pass I wonder how this new type get created . What is the type of metatype in the following line ? type = (PyTypeObject *)metatype->tp_alloc(metatype, nslots); (line 2296 of typeobject.c Python2.7.3 source code) It seems PyDict_Type . If so , how do I expect the tp_alloc will return a PyTypeObject object ? Maybe I've missed something ? Many thanks!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Mar 12 02:50:21 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Mar 2013 07:50:21 +0100 Subject: metatype References: Message-ID: shangyu wrote: > Hi dear all, > I have following Python code > class mydict(dict): > def __init__(self): > pass > I wonder how this new type get created . What is the type of metatype in > the following line ? type = (PyTypeObject *)metatype->tp_alloc(metatype, > nslots); (line 2296 of typeobject.c Python2.7.3 source code) > It seems PyDict_Type . If so , how do I expect the tp_alloc will return a > PyTypeObject object ? Maybe I've missed something ? Many thanks!!! > I think I've found it out . For new-style class it's PyType_Type and for > old-style class it's PyClass_Type . Thanks anyway. Yes. You can find that out without resorting to the C API: >>> class A(dict): pass ... >>> type(A) A fancy example: >>> import abc >>> class B: ... __metaclass__ = abc.ABCMeta ... >>> type(B) From vinay_sajip at yahoo.co.uk Mon Mar 11 20:14:48 2013 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 11 Mar 2013 17:14:48 -0700 (PDT) Subject: ANN: A new version (0.3.3) of the Python module which wraps GnuPG has been released. Message-ID: <11bbf737-b40c-46cc-b8e2-e0259e6945a4@googlegroups.com> A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor enhancement and bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Improved support for status messages from GnuPG. Fixed list_keys to handle control characters. Enabled fast random for tests. The current version passes all tests on Windows (CPython 2.4, 2.5, 2.6, 3.1, 2.7 and Jython 2.5.1) and Ubuntu (CPython 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2). On Windows, GnuPG 1.4.11 has been used for the tests. What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. From thebalancepro at gmail.com Tue Mar 12 01:35:43 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Mon, 11 Mar 2013 22:35:43 -0700 (PDT) Subject: del not working for (exhausted) dict iterable value (Python 3.3) Message-ID: <2879f537-1666-46f7-abbf-38204d8184c2@googlegroups.com> Hi all, event['Items'] is an exhausted (all used up) iterable. Now I do the following (lines 142-4): event.update({'Attributes': filtered_attributes}) del event['Items'] yield event and get a KeyError on the del statement. 'Items' is a key in the event dictionary at this point. The full file is here: https://gist.github.com/nickmellor/5140516 I can get round it by copying all but the 'Items' member to a new dictionary, but obviously I don't want to. Is there some deep design in Python here, that it won't delete a dict value that's an (exhausted) iterator, or have I found a bug? Thanks for any help, Nick From wuwei23 at gmail.com Tue Mar 12 01:52:15 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 11 Mar 2013 22:52:15 -0700 (PDT) Subject: del not working for (exhausted) dict iterable value (Python 3.3) References: <2879f537-1666-46f7-abbf-38204d8184c2@googlegroups.com> Message-ID: <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> On Mar 12, 3:35?pm, Nick Mellor wrote: > event['Items'] is an exhausted (all used up) iterable. > > Now I do the following (lines 142-4): > > ? ? ? ? ? ? event.update({'Attributes': filtered_attributes}) > ? ? ? ? ? ? del event['Items'] > ? ? ? ? ? ? yield event > > and get a KeyError on the del statement. > > Is there some deep design in Python here, that it won't delete a > dict value that's an (exhausted) iterator, or have I found a bug? You're effectively doing this: >>> event = dict(Items=[1,2,3]) >>> for e in event['Items']: ... del event['Items'] ... Traceback (most recent call last): File "", line 2, in KeyError: 'Items' You want to move your del statement up an indentation level so it happens after the iterator is actually exhausted, and not after the first iteration. From thebalancepro at gmail.com Tue Mar 12 18:40:13 2013 From: thebalancepro at gmail.com (Nick Mellor) Date: Tue, 12 Mar 2013 15:40:13 -0700 (PDT) Subject: del not working for (exhausted) dict iterable value (Python 3.3) In-Reply-To: <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> References: <2879f537-1666-46f7-abbf-38204d8184c2@googlegroups.com> <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> Message-ID: <9781042e-786c-4e5f-8a2e-b77d6fabc593@googlegroups.com> Thanks Alex! Nick From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Mar 13 00:02:42 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 13 Mar 2013 05:02:42 +0100 Subject: del not working for (exhausted) dict iterable value (Python 3.3) In-Reply-To: <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> References: <2879f537-1666-46f7-abbf-38204d8184c2@googlegroups.com> <0809a262-494f-46d6-910a-909a06e2aa92@m9g2000pby.googlegroups.com> Message-ID: Am 12.03.2013 06:52 schrieb alex23: > You're effectively doing this: > >>>> event = dict(Items=[1,2,3]) >>>> for e in event['Items']: > ... del event['Items'] > ... > Traceback (most recent call last): > File "", line 2, in > KeyError: 'Items' > > You want to move your del statement up an indentation level so it > happens after the iterator is actually exhausted, and not after the > first iteration. Just to be clear: Exhausting the iterator is not the problem, as I thought as well at the first glance. The problem is the fact that the loop body tuns multiple times - and so does the del statement. A event = dict(Items=[1,2,3]) for e in event['Items']: if 'Items' in event: del event['Items'] runs perfectly, as the iterable is transformed to an iterator at the very start of the loop. Thomas From magguru.bangarayya at gmail.com Tue Mar 12 06:08:10 2013 From: magguru.bangarayya at gmail.com (magguru.bangarayya at gmail.com) Date: Tue, 12 Mar 2013 03:08:10 -0700 (PDT) Subject: make 4000 dollars a month Message-ID: <5dcde8ff-00b9-4d75-bf8a-43871c7e4245@googlegroups.com> make 4000 dollars a month click here to read terms and conditions.... http://63541hsb18iflglycbqhxprqbc.hop.clickbank.net/ From kevin.khan27 at gmail.com Tue Mar 12 10:06:20 2013 From: kevin.khan27 at gmail.com (kevin.khan27 at gmail.com) Date: Tue, 12 Mar 2013 07:06:20 -0700 (PDT) Subject: Matplotlib Slider Widget and changing colorbar threshold Message-ID: <6e531e68-8f57-437e-9ce9-71cfe5e4e73f@googlegroups.com> I am currently trying to work on a program that will allow the user to display their dataset in the form of a colormap and through the use of sliders, it will also allow the user to adjust the threshold of the colormap and thus update the colormap accordingly. The best to describe this would be through the use of a picture: ![enter image description here][1] [1]: http://i.stack.imgur.com/1T9Qp.png This image shows how the colorbar should look before (the image on the left) and after (the image on the right) the adjustment. As the threshold values of the colrobar are changed, the colormap would be updated accordingly. Now I am mainly using matplotlib and I found that matplotlib does support some widgets, such as a slider. However the area I need help in is devising a piece of code which will update the colorbar and colormap (like the way shown in the picture above) when the slider is adjusted. I was wondering if anyone has done this before and might have a piece of code they would be willing to share and might have pointers as to how this can be achieved. From matt.newville at gmail.com Wed Mar 13 06:46:43 2013 From: matt.newville at gmail.com (matt.newville at gmail.com) Date: Wed, 13 Mar 2013 03:46:43 -0700 (PDT) Subject: Matplotlib Slider Widget and changing colorbar threshold In-Reply-To: <6e531e68-8f57-437e-9ce9-71cfe5e4e73f@googlegroups.com> References: <6e531e68-8f57-437e-9ce9-71cfe5e4e73f@googlegroups.com> Message-ID: <4cf12c84-63af-483b-83c0-568d62522989@googlegroups.com> On Tuesday, March 12, 2013 9:06:20 AM UTC-5, kevin.... at gmail.com wrote: > I am currently trying to work on a program that will allow the user to display their dataset in the form of a colormap and through the use of sliders, it will also allow the user to adjust the threshold of the colormap and thus update the colormap accordingly. The best to describe this would be through the use of a picture: ![enter image description here][1] > > > > > > [1]: http://i.stack.imgur.com/1T9Qp.png > > > > > > This image shows how the colorbar should look before (the image on the left) and after (the image on the right) the adjustment. As the threshold values of the colrobar are changed, the colormap would be updated accordingly. > > > > Now I am mainly using matplotlib and I found that matplotlib does support some widgets, such as a slider. However the area I need help in is devising a piece of code which will update the colorbar and colormap (like the way shown in the picture above) when the slider is adjusted. I was wondering if anyone has done this before and might have a piece of code they would be willing to share and might have pointers as to how this can be achieved. An example using wxPython and matplotlib: http://newville.github.com/wxmplot/imagepanel.html#examples-and-screenshots might be close to what you're looking for. This does allow the user to re-scale the intensity of the colorbar and the corresponding map, as well as change colormaps, smoothing, and explicitly set intensity ranges. This image display frame might cover most of what you need -- if not, I'd be interested to hear what else might be useful. The specific code building the control is at https://github.com/newville/wxmplot/blob/master/lib/imageframe.py Hope that helps, --Matt Newville From daffra.claudio at gmail.com Tue Mar 12 11:25:40 2013 From: daffra.claudio at gmail.com (cld) Date: Tue, 12 Mar 2013 08:25:40 -0700 (PDT) Subject: beowulf Basic extension python Message-ID: hi all, my friend i like python ! and i have code in c http://sourceforge.net/projects/beowulfpython/?source=directory an extension of this wonderfull language Beowulf Beginner Extended Object Language (with ultra language functionality) in the future ! it's like a Basic that translate code in full python i have added : powerfull struct, switch. redim, retype, enum, const, property and many other features my extensions will be never beatuy like python but i need your help to improve it ! best regards claudio From noone at nowhere.org Tue Mar 12 11:28:27 2013 From: noone at nowhere.org (BlindAnagram) Date: Tue, 12 Mar 2013 15:28:27 +0000 Subject: Snowed In? Message-ID: Hi Geoff Are you snowed in? Its OK here. Brian From Octothorpe at invalid.com Tue Mar 12 12:05:17 2013 From: Octothorpe at invalid.com (Octothorpe) Date: Tue, 12 Mar 2013 12:05:17 -0400 Subject: Snowed In? References: Message-ID: On Tue, 12 Mar 2013 15:28:27 +0000, BlindAnagram wrote: > Hi Geoff > > Are you snowed in? > > Its OK here. > > Brian Why Yes, matter if fact I am listening to snow blind From heguner at gmail.com Tue Mar 12 11:58:55 2013 From: heguner at gmail.com (Huseyin Emre Guner) Date: Tue, 12 Mar 2013 08:58:55 -0700 (PDT) Subject: 2-D drawing/map with python Message-ID: <58576851-f30e-4e19-9d0c-797c075b7b82@googlegroups.com> Hello, I am newbie in Python. I would like to make a project using python. The main ideo of this project is that a user enters the x,y values to the Gui(PyQt or Gtk) and then a 2-D map is plotted due to the x,y values. First, I use Pygame commands "(pygame.draw.line(window, (255, 255, 255), (10, 10), (200, 400))" However I could not establish a gui with pygame. Now I would like to use the PyQt. Could you please give me advice for this project? From jsf80238 at gmail.com Thu Mar 14 00:37:29 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 13 Mar 2013 22:37:29 -0600 Subject: 2-D drawing/map with python In-Reply-To: <58576851-f30e-4e19-9d0c-797c075b7b82@googlegroups.com> References: <58576851-f30e-4e19-9d0c-797c075b7b82@googlegroups.com> Message-ID: > Hello, > I am newbie in Python. I would like to make a project using python. > The main ideo of this project is that a user enters the x,y values to the Gui(PyQt or Gtk) and then a 2-D map is plotted due to the x,y values. First, I use Pygame commands "(pygame.draw.line(window, (255, 255, 255), (10, 10), (200, 400))" However I could not establish a gui with pygame. Now I would like to use the PyQt. Could you please give me advice for this project? Is your goal just to learn Python, or also to learn how to create GUIs? Your answer might help others on this list give better advice. Either way, though, this free course might be helpful: https://www.coursera.org/course/interactivepython. From matteo.boscolo at boscolini.eu Thu Mar 14 18:20:38 2013 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Thu, 14 Mar 2013 23:20:38 +0100 Subject: 2-D drawing/map with python In-Reply-To: <58576851-f30e-4e19-9d0c-797c075b7b82@googlegroups.com> References: <58576851-f30e-4e19-9d0c-797c075b7b82@googlegroups.com> Message-ID: <51424D36.4000708@boscolini.eu> Il 12/03/2013 16:58, Huseyin Emre Guner ha scritto: > Hello, > I am newbie in Python. I would like to make a project using python. > The main ideo of this project is that a user enters the x,y values to the Gui(PyQt or Gtk) and then a 2-D map is plotted due to the x,y values. First, I use Pygame commands "(pygame.draw.line(window, (255, 255, 255), (10, 10), (200, 400))" However I could not establish a gui with pygame. Now I would like to use the PyQt. Could you please give me advice for this project? have a look at : http://sourceforge.net/projects/pythoncad/ it's also integrated with sympy .. regards, Matteo From nh.jones01 at gmail.com Tue Mar 12 13:03:08 2013 From: nh.jones01 at gmail.com (Norah Jones) Date: Tue, 12 Mar 2013 17:03:08 +0000 Subject: Finding the Min for positive and negative in python 3.3 list Message-ID: For example: a=[-15,-30,-10,1,3,5] I want to find a negative and a positive minimum. example: negative print(min(a)) = -30 positive print(min(a)) = 1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Mar 12 13:45:01 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 12 Mar 2013 18:45:01 +0100 (CET) Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: Message-ID: <1604147031.4067302.1363110301286.JavaMail.root@sequans.com> ----- Original Message ----- > For example: > a=[-15,-30,-10,1,3,5] > I want to find a negative and a positive minimum. > example: negative > print(min(a)) = -30 > positive > print(min(a)) = 1 > -- > http://mail.python.org/mailman/listinfo/python-list min(a) and min([e for e in a if e >=0] Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From jeanpierreda at gmail.com Tue Mar 12 13:49:40 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 12 Mar 2013 13:49:40 -0400 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: <1604147031.4067302.1363110301286.JavaMail.root@sequans.com> References: <1604147031.4067302.1363110301286.JavaMail.root@sequans.com> Message-ID: > min(a) This does not return a negative minimum on input [1] (because there is none). > and > > min([e for e in a if e >=0] This does not return a positive minimum on input [0] (because there is none). I would have said: pos_min = min(e for e in a if e > 0) neg_min = min(e for e in a if e < 0) And then deal with the ValueError when there is no such minimum, as appropriate. -- Devin From wolfgang.maier at biologie.uni-freiburg.de Tue Mar 12 13:48:34 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 12 Mar 2013 17:48:34 +0000 (UTC) Subject: Finding the Min for positive and negative in python 3.3 list References: Message-ID: Norah Jones gmail.com> writes: > > For example: > a=[-15,-30,-10,1,3,5] > I want to find a negative and a positive minimum. > example: negative > print(min(a)) = -30 > positive > print(min(a)) = 1 > > > try this: min(a) => -30 min([n for n in a if i>0]) => 1 of course, you have to figure out what you want to do with a zero value. From wolfgang.maier at biologie.uni-freiburg.de Tue Mar 12 14:13:14 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 12 Mar 2013 18:13:14 +0000 (UTC) Subject: Finding the Min for positive and negative in python 3.3 list References: Message-ID: Wolfgang Maier biologie.uni-freiburg.de> writes: > > Norah Jones gmail.com> writes: > > > > > For example: > > a=[-15,-30,-10,1,3,5] > > I want to find a negative and a positive minimum. > > example: negative > > print(min(a)) = -30 > > positive > > print(min(a)) = 1 > > > > > > > > try this: > min(a) => -30 > min([n for n in a if n>0]) => 1 > > of course, you have to figure out what you want to do with a zero value. > > the i above has to be an n, of course, sorry for that typo. by the way, if you need both values and your list is really huge, an explicit for loop checking each number whether it's the current negative and positive minimum might be faster, but that would have to be tested. Also, I'm wondering whether you could somehow exploit the fact that if your list contains 0 (or 1 depending on how you want to treat zero values) you have for sure found the minimum for your positive numbers? From tjreedy at udel.edu Tue Mar 12 13:57:08 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Mar 2013 13:57:08 -0400 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: Message-ID: On 3/12/2013 1:03 PM, Norah Jones wrote: > For example: > a=[-15,-30,-10,1,3,5] > > I want to find a negative and a positive minimum. > > example: negative > print(min(a)) = -30 > > positive > print(min(a)) = 1 If this is homework, stop reading and do it yourself ;-) Otherwise... >>> min(i for i in a if i >0) 1 >>> max(i for i in a if i < 0) -10 >>> min(i for i in a if i < 0) -30 You did not specify if you would include 0 in a pos min (0 is neither really positive or negative). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Mar 12 21:57:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2013 01:57:16 GMT Subject: Finding the Min for positive and negative in python 3.3 list References: Message-ID: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Mar 2013 17:03:08 +0000, Norah Jones wrote: > For example: > a=[-15,-30,-10,1,3,5] > > I want to find a negative and a positive minimum. > > example: negative > print(min(a)) = -30 > > positive > print(min(a)) = 1 Thank you for providing examples, but they don't really cover all the possibilities. For example, if you had: a = [-1, -2, -3, 100, 200, 300] I can see that you consider -3 to be the "negative minimum". Do you consider the "positive minimum" to be 100, or 1? If you expect it to be 100, then the solution is: min([item for item in a if item > 0]) If you expect it to be 1, then the solution is: min([abs(item) for item in a]) which could also be written as: min(map(abs, a)) A third alternative is in Python 3.3: min(a, key=abs) which will return -1. -- Steven From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 13 06:43:38 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 13 Mar 2013 10:43:38 +0000 (UTC) Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano pearwood.info> writes: > > On Tue, 12 Mar 2013 17:03:08 +0000, Norah Jones wrote: > > > For example: > > a=[-15,-30,-10,1,3,5] > > > > I want to find a negative and a positive minimum. > > > > example: negative > > print(min(a)) = -30 > > > > positive > > print(min(a)) = 1 > > Thank you for providing examples, but they don't really cover all the > possibilities. For example, if you had: > > a = [-1, -2, -3, 100, 200, 300] > > I can see that you consider -3 to be the "negative minimum". Do you > consider the "positive minimum" to be 100, or 1? > > If you expect it to be 100, then the solution is: > > min([item for item in a if item > 0]) > > If you expect it to be 1, then the solution is: > > min([abs(item) for item in a]) > > which could also be written as: > > min(map(abs, a)) > > A third alternative is in Python 3.3: > > min(a, key=abs) > > which will return -1. > thinking again about the question, then the min() solutions suggested so far certainly do the job and they are easy to understand. However, if you need to run the function repeatedly on larger lists, using min() is suboptimal because its performance is an O(n) one. It's faster, though less intuitive, to sort your list first, then use bisect on it to find the zero position in it. Two manipulations running at O(log(n)). compare these two functions: def with_min(x): return (min(n for n in a if n<0), min(n for n in a if n>=0)) def with_bisect(x): b=sorted(x) return (b[0] if b[0]<0 else None, b[bisect.bisect_left(b,0)]) then either time them for small lists or try: a=range(-10000000,10000000) with_min(a) with_bisect(a) of course, the disadvantage is that you create a huge sorted list in memory and that it's less readable. Best, Wolfgang From oscar.j.benjamin at gmail.com Wed Mar 13 07:23:22 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 13 Mar 2013 11:23:22 +0000 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13 March 2013 10:43, Wolfgang Maier wrote: > > thinking again about the question, then the min() solutions suggested so far > certainly do the job and they are easy to understand. > However, if you need to run the function repeatedly on larger lists, using min() > is suboptimal because its performance is an O(n) one. > It's faster, though less intuitive, to sort your list first, then use bisect on > it to find the zero position in it. Two manipulations running at O(log(n)). Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) minimum finding algorithm. No valid sorting algorithm can have even a best case performance that is better than O(n). This is because it takes O(n) just to verify that a list is sorted. Oscar From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 13 07:34:08 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 13 Mar 2013 11:34:08 +0000 (UTC) Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Oscar Benjamin gmail.com> writes: > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > minimum finding algorithm. No valid sorting algorithm can have even a > best case performance that is better than O(n). This is because it > takes O(n) just to verify that a list is sorted. > > Oscar > Oops, you're right of course. Wrote this in a hurry before and got confused a bit. So, the two min()s take O(n) each, the sort takes O(n), but the bisect takes O(log n), which means that sorting and bisecting together should still be faster than 2xmin(), although it's a bit less striking than what I wrote first. Thanks for the correction, Wolfgang From rosuav at gmail.com Wed Mar 13 07:38:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2013 22:38:59 +1100 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 13, 2013 at 10:34 PM, Wolfgang Maier wrote: > Oscar Benjamin gmail.com> writes: > >> >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). This is because it >> takes O(n) just to verify that a list is sorted. >> >> Oscar >> > > Oops, you're right of course. > Wrote this in a hurry before and got confused a bit. > So, the two min()s take O(n) each, the sort takes O(n), > but the bisect takes O(log n), > which means that sorting and bisecting together should still be faster > than 2xmin(), although it's a bit less striking than what I wrote first. > Thanks for the correction, > Wolfgang Your sort is usually going to be O(n log n), not O(log n). ChrisA From __peter__ at web.de Wed Mar 13 08:00:26 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Mar 2013 13:00:26 +0100 Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Wolfgang Maier wrote: > Oscar Benjamin gmail.com> writes: > >> >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). This is because it >> takes O(n) just to verify that a list is sorted. >> >> Oscar >> > > Oops, you're right of course. > Wrote this in a hurry before and got confused a bit. > So, the two min()s take O(n) each, the sort takes O(n), O(n*log(n)) according to > but the bisect takes O(log n), > which means that sorting and bisecting together should still be faster > than 2xmin(), although it's a bit less striking than what I wrote first. That's not how big-O math works. 2*O(n) is still O(n). 2*O(n) == O(n) As n grows an O(log(n)) approach will eventually be faster than O(n), but that's asymptotical behaviour and allows for an arbitrary constant factor. For a given n you cannot decide if the O(n) or the O(log(n)) algorithm is faster unless you know these constant factors. Put another way: Iterating twice over the list doubles an unknown constant factor. From rosuav at gmail.com Wed Mar 13 07:36:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2013 22:36:21 +1100 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 13, 2013 at 10:23 PM, Oscar Benjamin wrote: > On 13 March 2013 10:43, Wolfgang Maier > wrote: >> >> thinking again about the question, then the min() solutions suggested so far >> certainly do the job and they are easy to understand. >> However, if you need to run the function repeatedly on larger lists, using min() >> is suboptimal because its performance is an O(n) one. >> It's faster, though less intuitive, to sort your list first, then use bisect on >> it to find the zero position in it. Two manipulations running at O(log(n)). > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > minimum finding algorithm. No valid sorting algorithm can have even a > best case performance that is better than O(n). This is because it > takes O(n) just to verify that a list is sorted. Or looking at it another way: Sorting a list will require, at a bare minimum, comparing every element against at least one other element - if you could reduce it below that, there would be some element whose position you cannot know. Finding the minimum requires precisely that number of comparisons: each item against the one current minimum. :) ChrisA From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 13 10:17:54 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 13 Mar 2013 14:17:54 +0000 (UTC) Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico gmail.com> writes: > > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > > minimum finding algorithm. No valid sorting algorithm can have even a > > best case performance that is better than O(n). This is because it > > takes O(n) just to verify that a list is sorted. > > Or looking at it another way: Sorting a list will require, at a bare > minimum, comparing every element against at least one other element - > if you could reduce it below that, there would be some element whose > position you cannot know. Finding the minimum requires precisely that > number of comparisons: each item against the one current minimum. :) > > ChrisA > Shame on me! You really shouldn't post things, while working on something else that needs all your attention. You're absolutely right with what you're saying. I was so fixed on speeding things up with the use of bisect that I wasn't really thinking carefully about the sorting, and I was delighted when I saw that my solution was speeding up the range() input example. Unfortunately, it's only speedy for this example because the input is actually sorted from the start (so sorted just checks the list -> O(n)). When you use it on shuffled input, performance is really poor as opposed to the simple min() solution, so as pointed out by you the costs of sorting are higher than the gain from using bisect. What started this whole mess was my gut feeling that you should somehow be able to exploit all the information you have, and that is that the second minimum you're looking for cannot be negative, so is at least 0 (or 1 depending on how you decide to treat 0). So I thought that under this restriction there should be a faster way to find the minimum than with min(). It only fooled me into thinking that bisect could be used for it though. Is it really impossible to beat the min() solution then? Thanks for your feedback, Wolfgang From steve+comp.lang.python at pearwood.info Wed Mar 13 10:43:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2013 14:43:36 GMT Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51409098$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Mar 2013 11:34:08 +0000, Wolfgang Maier wrote: > Oscar Benjamin gmail.com> writes: > > >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). This is because it >> takes O(n) just to verify that a list is sorted. >> >> Oscar >> >> > Oops, you're right of course. > Wrote this in a hurry before and got confused a bit. So, the two min()s > take O(n) each, the sort takes O(n), but the bisect takes O(log n), > which means that sorting and bisecting together should still be faster > than 2xmin(), although it's a bit less striking than what I wrote first. Not quite. In general, Big Oh values add by taking the *largest* term. Calling min() twice is O(n) + O(n) or 2*O(n), which is just O(n) since Big Oh analysis ignores any multiplicative constant. Sorting in general is O(n*log n), not O(n). If you have arbitrary, unsorted data, then sorting it first and then bisecting is O(n*log n) + O(log n), which is just O(n*log n), which is slower than O(n). Since Big Oh doesn't tell you the actual physical cost of operations, or how long they take, beware of relying too much on Big Oh analysis without doing actual physical timings. And in practice, min() is such a straight-forward, simple operation that it is hard to imagine anything beating it under normal circumstances. Unless you have truly vast amounts of data, the simplest solution is usually the best. -- Steven From steve+comp.lang.python at pearwood.info Wed Mar 13 10:12:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2013 14:12:12 GMT Subject: Finding the Min for positive and negative in python 3.3 list References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5140893b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Mar 2013 11:23:22 +0000, Oscar Benjamin wrote: > On 13 March 2013 10:43, Wolfgang Maier > wrote: >> >> thinking again about the question, then the min() solutions suggested >> so far certainly do the job and they are easy to understand. However, >> if you need to run the function repeatedly on larger lists, using min() >> is suboptimal because its performance is an O(n) one. It's faster, >> though less intuitive, to sort your list first, then use bisect on it >> to find the zero position in it. Two manipulations running at >> O(log(n)). > > Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) > minimum finding algorithm. No valid sorting algorithm can have even a > best case performance that is better than O(n). This is because it takes > O(n) just to verify that a list is sorted. That's almost true. It applies to comparison sorts, that is, the kind of sort algorithm where you have to compare the elements being sorted to know where they go. But it doesn't necessarily apply to non-comparison sorts. For example, Bead sort could in principle operate in O(sqrt(n)) time, or even O(1), although in practice it is O(n). Another example is Bitonic sort, which is O(log(n)**2). In practical terms though, you are right. There is no practical, general purpose sorting algorithm that can beat O(n) for arbitrary lists of data. -- Steven From breamoreboy at yahoo.co.uk Wed Mar 13 10:37:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 13 Mar 2013 14:37:33 +0000 Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: <5140893b$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> <5140893b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13/03/2013 14:12, Steven D'Aprano wrote: > On Wed, 13 Mar 2013 11:23:22 +0000, Oscar Benjamin wrote: > >> On 13 March 2013 10:43, Wolfgang Maier >> wrote: >>> >>> thinking again about the question, then the min() solutions suggested >>> so far certainly do the job and they are easy to understand. However, >>> if you need to run the function repeatedly on larger lists, using min() >>> is suboptimal because its performance is an O(n) one. It's faster, >>> though less intuitive, to sort your list first, then use bisect on it >>> to find the zero position in it. Two manipulations running at >>> O(log(n)). >> >> Sort cannot be O(log(n)) and it cannot be faster than a standard O(n) >> minimum finding algorithm. No valid sorting algorithm can have even a >> best case performance that is better than O(n). This is because it takes >> O(n) just to verify that a list is sorted. > > That's almost true. It applies to comparison sorts, that is, the kind of > sort algorithm where you have to compare the elements being sorted to > know where they go. But it doesn't necessarily apply to non-comparison > sorts. For example, Bead sort could in principle operate in O(sqrt(n)) > time, or even O(1), although in practice it is O(n). > > Another example is Bitonic sort, which is O(log(n)**2). > > In practical terms though, you are right. There is no practical, general > purpose sorting algorithm that can beat O(n) for arbitrary lists of data. > For the newbies hanging around there's Python's own Timsort which apparantly has worst case performance O(n log n), best case O(n) and average case O(n log n). Please don't shoot the messenger :) -- Cheers. Mark Lawrence From dihedral88888 at googlemail.com Thu Mar 14 07:45:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 14 Mar 2013 04:45:30 -0700 (PDT) Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <07814312-20ef-4920-8287-b389dcbab031@googlegroups.com> Wolfgang Maier? 2013?3?13????UTC+8??6?43?38???? > Steven D'Aprano pearwood.info> writes: > > > > > > > > On Tue, 12 Mar 2013 17:03:08 +0000, Norah Jones wrote: > > > > > > > For example: > > > > a=[-15,-30,-10,1,3,5] > > > > > > > > I want to find a negative and a positive minimum. > > > > > > > > example: negative > > > > print(min(a)) = -30 > > > > > > > > positive > > > > print(min(a)) = 1 > > > > > > Thank you for providing examples, but they don't really cover all the > > > possibilities. For example, if you had: > > > > > > a = [-1, -2, -3, 100, 200, 300] > > > > > > I can see that you consider -3 to be the "negative minimum". Do you > > > consider the "positive minimum" to be 100, or 1? > > > > > > If you expect it to be 100, then the solution is: > > > > > > min([item for item in a if item > 0]) > > > > > > If you expect it to be 1, then the solution is: > > > > > > min([abs(item) for item in a]) > > > > > > which could also be written as: > > > > > > min(map(abs, a)) > > > > > > A third alternative is in Python 3.3: > > > > > > min(a, key=abs) > > > > > > which will return -1. > > > > > > > thinking again about the question, then the min() solutions suggested so far > > certainly do the job and they are easy to understand. > > However, if you need to run the function repeatedly on larger lists, using min() > > is suboptimal because its performance is an O(n) one. > > It's faster, though less intuitive, to sort your list first, then use bisect on > > it to find the zero position in it. Two manipulations running at O(log(n)). > > > > compare these two functions: > > > > def with_min(x): > > return (min(n for n in a if n<0), min(n for n in a if n>=0)) > > > > def with_bisect(x): > > b=sorted(x) > > return (b[0] if b[0]<0 else None, b[bisect.bisect_left(b,0)]) > > > > then either time them for small lists or try: > > > > a=range(-10000000,10000000) > > with_min(a) > > with_bisect(a) > > > > of course, the disadvantage is that you create a huge sorted list in memory and > > that it's less readable. > > > > Best, > > Wolfgang Sorting numbers of such range M in a list of length N by radix sort is faster but requires more memory. From dihedral88888 at googlemail.com Thu Mar 14 07:45:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 14 Mar 2013 04:45:30 -0700 (PDT) Subject: Finding the Min for positive and negative in python 3.3 list In-Reply-To: References: <513fdcfc$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <07814312-20ef-4920-8287-b389dcbab031@googlegroups.com> Wolfgang Maier? 2013?3?13????UTC+8??6?43?38???? > Steven D'Aprano pearwood.info> writes: > > > > > > > > On Tue, 12 Mar 2013 17:03:08 +0000, Norah Jones wrote: > > > > > > > For example: > > > > a=[-15,-30,-10,1,3,5] > > > > > > > > I want to find a negative and a positive minimum. > > > > > > > > example: negative > > > > print(min(a)) = -30 > > > > > > > > positive > > > > print(min(a)) = 1 > > > > > > Thank you for providing examples, but they don't really cover all the > > > possibilities. For example, if you had: > > > > > > a = [-1, -2, -3, 100, 200, 300] > > > > > > I can see that you consider -3 to be the "negative minimum". Do you > > > consider the "positive minimum" to be 100, or 1? > > > > > > If you expect it to be 100, then the solution is: > > > > > > min([item for item in a if item > 0]) > > > > > > If you expect it to be 1, then the solution is: > > > > > > min([abs(item) for item in a]) > > > > > > which could also be written as: > > > > > > min(map(abs, a)) > > > > > > A third alternative is in Python 3.3: > > > > > > min(a, key=abs) > > > > > > which will return -1. > > > > > > > thinking again about the question, then the min() solutions suggested so far > > certainly do the job and they are easy to understand. > > However, if you need to run the function repeatedly on larger lists, using min() > > is suboptimal because its performance is an O(n) one. > > It's faster, though less intuitive, to sort your list first, then use bisect on > > it to find the zero position in it. Two manipulations running at O(log(n)). > > > > compare these two functions: > > > > def with_min(x): > > return (min(n for n in a if n<0), min(n for n in a if n>=0)) > > > > def with_bisect(x): > > b=sorted(x) > > return (b[0] if b[0]<0 else None, b[bisect.bisect_left(b,0)]) > > > > then either time them for small lists or try: > > > > a=range(-10000000,10000000) > > with_min(a) > > with_bisect(a) > > > > of course, the disadvantage is that you create a huge sorted list in memory and > > that it's less readable. > > > > Best, > > Wolfgang Sorting numbers of such range M in a list of length N by radix sort is faster but requires more memory. From nh.jones01 at gmail.com Tue Mar 12 13:11:10 2013 From: nh.jones01 at gmail.com (Norah Jones) Date: Tue, 12 Mar 2013 17:11:10 +0000 Subject: How can i create a random array of floats from 0 to 5 in python Message-ID: I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lothiraldan at gmail.com Tue Mar 12 13:25:36 2013 From: lothiraldan at gmail.com (Boris FELD) Date: Tue, 12 Mar 2013 18:25:36 +0100 Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: Message-ID: You can use [random.random() * 5 for x in range(100)] but works only on range [0, 5). If you want to include 5, you will need more code. Cheers, FELD Boris 2013/3/12 Norah Jones : > I want to create a random float array of size 100, with the values in the > array ranging from 0 to 5. I have tried random.sample(range(5),100) but that > does not work. How can i get what i want to achieve? > -- > http://mail.python.org/mailman/listinfo/python-list > From gherron at digipen.edu Tue Mar 12 13:26:35 2013 From: gherron at digipen.edu (Gary Herron) Date: Tue, 12 Mar 2013 10:26:35 -0700 Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: Message-ID: <513F654B.6050701@digipen.edu> On 03/12/2013 10:11 AM, Norah Jones wrote: > I want to create a random float array of size 100, with the values in > the array ranging from 0 to 5. I have tried > random.sample(range(5),100) but that does not work. How can i get what > i want to achieve? > > >>> [random.uniform(0,5) for i in range(100)] [0.035440065542497456, 1.437405027400226, 4.3729265564939235, 1.8571876890801535, 3.3707291675828355, 3.8527038142772803, 2.335308526527048, 1.6648256912958126, 2.619282525564386, 0.49146229156297017, 0.44118757769151584, 4.739666518393803, 2.382053744691543, 0.49644235270002446, 3.2450874430280967, 2.907453418492667, 4.476790608458042, 3.6331854165844604, 4.048234752835737, 1.0561381241342283, 2.812909536326582, 3.561597391575344, 2.6487355099594017, 0.29397014028037627, 2.4479483428627753, 3.958448741888134, 2.407241234096458, 1.3214223763910538, 2.13697973410729, 0.5948251249983533, 1.7529836288331397, 1.5086813377327446, 1.8586362776340244, 1.2208704263132752, 0.641484635760266, 1.3848412838385726, 0.9293523709719054, 2.186001913964843, 4.573380203193875, 2.139476734752273, 2.9472883699144536, 2.896233361842901, 3.6862386168483736, 0.34731746668937247, 0.32240948705737016, 3.5558945043043533, 3.2122777306650474, 4.361615595368701, 0.015650980269780734, 3.6657002416980946, 2.559029702763296, 3.1821909947792215, 1.110074378492174, 4.631074891897119, 0.34141410223593516, 4.857392826027885, 3.527794364975918, 1.1557966421173278, 3.052715879227505, 3.5157974813529522, 1.1124961331040095, 0.3481541778415814, 4.669841649649461, 0.5971397176504589, 2.558151735886299, 1.2604807126742945, 2.281602331386756, 2.1519211043558695, 3.3468967934451657, 1.8240743647766071, 2.91696855571327, 0.6894263573879533, 2.7732038929294616, 4.783919829213994, 4.082864012400709, 0.16128311206877133, 4.959480373070126, 2.8458909583600187, 4.494888799994467, 4.647426388056034, 3.111088594459788, 4.261340689865024, 1.6013438490852865, 3.6386026965034852, 1.212916907042898, 3.3586184962657706, 3.6105733007635954, 0.5372141790624257, 0.9433843973095679, 3.113889114931214, 3.054082222169326, 2.360224809741029, 2.026697918525358, 1.322913986495805, 4.341848866805052, 0.970311202088483, 2.002058149505537, 0.07453277198439523, 1.9633241018322773, 4.22967258746455] -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From maarten.sneep at knmi.nl Tue Mar 12 13:47:25 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Tue, 12 Mar 2013 10:47:25 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: Message-ID: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? Use numpy import numpy as np np.random.uniform(0, 5, 100) # note that the values are from the interval [0, 5) Maarten From maarten.sneep at knmi.nl Tue Mar 12 13:47:25 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Tue, 12 Mar 2013 10:47:25 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: Message-ID: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? Use numpy import numpy as np np.random.uniform(0, 5, 100) # note that the values are from the interval [0, 5) Maarten From llanitedave at veawb.coop Tue Mar 12 16:21:16 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 12 Mar 2013 13:21:16 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> References: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> Message-ID: On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote: > On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > > > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? > > > > Use numpy > > > > import numpy as np > > np.random.uniform(0, 5, 100) > > > > # note that the values are from the interval [0, 5) > > > > Maarten While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need. This is like recommending an RPG to fix a sticky door hinge. From llanitedave at veawb.coop Tue Mar 12 16:21:16 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 12 Mar 2013 13:21:16 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> References: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> Message-ID: On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote: > On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > > > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? > > > > Use numpy > > > > import numpy as np > > np.random.uniform(0, 5, 100) > > > > # note that the values are from the interval [0, 5) > > > > Maarten While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need. This is like recommending an RPG to fix a sticky door hinge. From oscar.j.benjamin at gmail.com Tue Mar 12 17:59:29 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 12 Mar 2013 21:59:29 +0000 Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> Message-ID: On 12 March 2013 20:21, llanitedave wrote: > On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote: >> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: >> >> > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? >> >> Use numpy [SNIP] > > While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need. This is like recommending an RPG to fix a sticky door hinge. This suggestion comes after others that show how to use the stdlib's random module. I don't think it's unreasonable to recommend numpy for this. If you want to create *arrays* of random numbers then why not use a library that provides an API specifically for that? You can test yourself to see that numpy is 10x faster for large arrays: Python 2.7 on Linux: $ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x in range(1000)]' 1000 loops, best of 3: 729 usec per loop $ python -m timeit -s 'import random' -- '[random.random() * 5 for x in range(1000)]' 1000 loops, best of 3: 296 usec per loop $ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)' 10000 loops, best of 3: 32.2 usec per loop I would use numpy for this mainly because if I'm creating arrays of random numbers I probably want to use them in ways that are easier with numpy arrays. There's also a chance the OP might benefit more generally from using numpy depending on what they're working on. Oscar From llanitedave at veawb.coop Wed Mar 13 01:35:51 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 12 Mar 2013 22:35:51 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> Message-ID: <94642099-575e-4124-b0f6-43f26f880048@googlegroups.com> On Tuesday, March 12, 2013 2:59:29 PM UTC-7, Oscar Benjamin wrote: > On 12 March 2013 20:21, llanitedave wrote: > > > On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote: > > >> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > > >> > > >> > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? > > >> > > >> Use numpy > > [SNIP] > > > > > > While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need. This is like recommending an RPG to fix a sticky door hinge. > > > > This suggestion comes after others that show how to use the stdlib's > > random module. I don't think it's unreasonable to recommend numpy for > > this. If you want to create *arrays* of random numbers then why not > > use a library that provides an API specifically for that? You can test > > yourself to see that numpy is 10x faster for large arrays: > > > > Python 2.7 on Linux: > > $ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x > > in range(1000)]' > > 1000 loops, best of 3: 729 usec per loop > > $ python -m timeit -s 'import random' -- '[random.random() * 5 for x > > in range(1000)]' > > 1000 loops, best of 3: 296 usec per loop > > $ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)' > > 10000 loops, best of 3: 32.2 usec per loop > > > > I would use numpy for this mainly because if I'm creating arrays of > > random numbers I probably want to use them in ways that are easier > > with numpy arrays. There's also a chance the OP might benefit more > > generally from using numpy depending on what they're working on. > > > > > > Oscar I don't think numpy is unreasonable for you or me. I just started learning it recently, and I'm pretty jazzed about its possibilities. I obtained an app for work that uses it, and now it's up to me to maintain it, so learning it is a good idea for me regardless. Now I'm starting to fantasize about other things I could do with it. But the OP appears like a pretty basic beginner, and I really think that for such a entry-level knowledge scale, we should stick to the standard library until they're ready to take on more sophisticated tasks. "Premature Optimization" is the analogy that comes to mind. From llanitedave at veawb.coop Wed Mar 13 01:35:51 2013 From: llanitedave at veawb.coop (llanitedave) Date: Tue, 12 Mar 2013 22:35:51 -0700 (PDT) Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: <0aa38f5a-0e5e-43cd-b6ba-69af6f37e94e@googlegroups.com> Message-ID: <94642099-575e-4124-b0f6-43f26f880048@googlegroups.com> On Tuesday, March 12, 2013 2:59:29 PM UTC-7, Oscar Benjamin wrote: > On 12 March 2013 20:21, llanitedave wrote: > > > On Tuesday, March 12, 2013 10:47:25 AM UTC-7, Maarten wrote: > > >> On Tuesday, March 12, 2013 6:11:10 PM UTC+1, Norah Jones wrote: > > >> > > >> > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? > > >> > > >> Use numpy > > [SNIP] > > > > > > While numpy would work, I fail to see how encouraging the op to download and install a separate library and learn a whole new set of tools would be beneficial by default, without knowing the purpose of the need. This is like recommending an RPG to fix a sticky door hinge. > > > > This suggestion comes after others that show how to use the stdlib's > > random module. I don't think it's unreasonable to recommend numpy for > > this. If you want to create *arrays* of random numbers then why not > > use a library that provides an API specifically for that? You can test > > yourself to see that numpy is 10x faster for large arrays: > > > > Python 2.7 on Linux: > > $ python -m timeit -s 'import random' -- '[random.uniform(0, 5) for x > > in range(1000)]' > > 1000 loops, best of 3: 729 usec per loop > > $ python -m timeit -s 'import random' -- '[random.random() * 5 for x > > in range(1000)]' > > 1000 loops, best of 3: 296 usec per loop > > $ python -m timeit -s 'import numpy' -- 'numpy.random.uniform(0, 5, 1000)' > > 10000 loops, best of 3: 32.2 usec per loop > > > > I would use numpy for this mainly because if I'm creating arrays of > > random numbers I probably want to use them in ways that are easier > > with numpy arrays. There's also a chance the OP might benefit more > > generally from using numpy depending on what they're working on. > > > > > > Oscar I don't think numpy is unreasonable for you or me. I just started learning it recently, and I'm pretty jazzed about its possibilities. I obtained an app for work that uses it, and now it's up to me to maintain it, so learning it is a good idea for me regardless. Now I'm starting to fantasize about other things I could do with it. But the OP appears like a pretty basic beginner, and I really think that for such a entry-level knowledge scale, we should stick to the standard library until they're ready to take on more sophisticated tasks. "Premature Optimization" is the analogy that comes to mind. From davea at davea.name Tue Mar 12 16:52:35 2013 From: davea at davea.name (Dave Angel) Date: Tue, 12 Mar 2013 16:52:35 -0400 Subject: How can i create a random array of floats from 0 to 5 in python In-Reply-To: References: Message-ID: <513F9593.9050307@davea.name> On 03/12/2013 01:11 PM, Norah Jones wrote: > I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve? > > None of the responses so far actually give you what you asked for, as they assume you didn't mean 'array' but meant 'list.' I suspect they're right, but here's an approach for array.array. If you really want a multiprocess.Array, or numpy's array, please say so, and somebody'll tell you how to put random numbers in one of them. import array import random floats = (random.random() * 5 for _ in xrange(100)) data = array.array('d', floats) print data print type(data) -- DaveA From skip at pobox.com Tue Mar 12 14:06:19 2013 From: skip at pobox.com (Skip Montanaro) Date: Tue, 12 Mar 2013 13:06:19 -0500 Subject: image transforming web proxy? Message-ID: I stumbled upon an old FFT tutorial on astro.berkeley.edu website whose images are in xbm format. Neither Chrome nor Firefox knows how to display X bitmap format and for Chrome at least, I've been unable to find an extension to do the conversion (didn't hunt for a FF extension). I can clearly download the whole kit-n-kaboodle, use any of a number of different tools to convert the images from xbm to png, then view things locally. I finally figured out that Opera supports xbm and downloaded it. I wonder though, if there is a Python-based web proxy out there which can transparently transform "obsolete" image formats like xbm into png, jpeg, presumably using PIL? Thanks, Skip From jiewei24 at gmail.com Tue Mar 12 20:21:12 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Tue, 12 Mar 2013 17:21:12 -0700 (PDT) Subject: A string and an integer to appear in tuple (python 2.7) Message-ID: <36706e17-0a2d-46eb-b222-09b90ec6ab58@googlegroups.com> Hi all, I'm currently stuck at this question on Writing a function len_str that takes a string as an argument and returns a pair consisting of the length of the string and the string itself. Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of life'). I can only think of this : len_str = ('welcome to life' ) print (len(len_str,), len_str) However that not an correct answer I need to make a def len_str but I can't seen to get it right. From oscar.j.benjamin at gmail.com Tue Mar 12 20:43:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 13 Mar 2013 00:43:54 +0000 Subject: A string and an integer to appear in tuple (python 2.7) In-Reply-To: <36706e17-0a2d-46eb-b222-09b90ec6ab58@googlegroups.com> References: <36706e17-0a2d-46eb-b222-09b90ec6ab58@googlegroups.com> Message-ID: On 13 March 2013 00:21, Jiewei Huang wrote: > Hi all, > > I'm currently stuck at this question on > > Writing a function len_str that takes a string as an argument and returns a pair consisting of the length of the string and the string itself. > > Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of life'). > > > I can only think of this : > > len_str = ('welcome to life' ) > > print (len(len_str,), len_str) > > > However that not an correct answer I need to make a def len_str but I can't seen to get it right. Perhaps an example will help. Let's say we have a variable called x that we initialise with x = 2 Here's a line of code that prints 2*x: print(2 * x) This will print out 4 but that's not what you want. Here's a function that prints its argument multiplied by 2: def double(y): print(2 * y) Now we have a function and we can call it with double(x) so that it prints 4. Again, though, you didn't want to print it. You wanted to *return* the value. So here's a function that *returns* 2 times its argument: def double(x): return 2 * x Now if we do z = double(x) z will have the value 4. You can check this with print(z) Try the code above and see if you can apply the same principles to your problem. Oscar From vlastimil.brom at gmail.com Tue Mar 12 21:06:59 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 13 Mar 2013 02:06:59 +0100 Subject: A string and an integer to appear in tuple (python 2.7) In-Reply-To: <36706e17-0a2d-46eb-b222-09b90ec6ab58@googlegroups.com> References: <36706e17-0a2d-46eb-b222-09b90ec6ab58@googlegroups.com> Message-ID: 2013/3/13 Jiewei Huang : > Hi all, > > I'm currently stuck at this question on > > Writing a function len_str that takes a string as an argument and returns a pair consisting of the length of the string and the string itself. > > Example: len_str('Meaning of life') should return the tuple (15, 'Meaning of life'). > > > I can only think of this : > > len_str = ('welcome to life' ) > > print (len(len_str,), len_str) > > > However that not an correct answer I need to make a def len_str but I can't seen to get it right. > -- > http://mail.python.org/mailman/listinfo/python-list Hi, unless you are required to code the length-counting by hand as a part of the exercise, you would simply use the built-in function for that, i.e. http://docs.python.org/3.3/library/functions.html#len Tuples are created using the coma delimiter; optionally with enclosing parens. http://docs.python.org/3.3/library/stdtypes.html#tuples >>> input_string = "Meaning of life" >>> input_string 'Meaning of life' >>> len(input_string) 15 >>> (len(input_string), input_string) (15, 'Meaning of life') >>> Now you have to put the needed code to the function body; see http://docs.python.org/3.3/tutorial/controlflow.html#defining-functions (Be sure not to forget the "return" statement containing the result of your function.) hth, vbr From manishreddytirumala at gmail.com Wed Mar 13 04:34:07 2013 From: manishreddytirumala at gmail.com (Manish) Date: Wed, 13 Mar 2013 01:34:07 -0700 (PDT) Subject: Getting started with Python: The ultimate list with Tips, Tools and Resources Message-ID: <23bedc20-8608-4282-bd66-2b9d0f31a80e@googlegroups.com> Getting started with Python: The ultimate list with Tips, Tools and Resources http://lurnq.com/lesson/Getting-started-with-Python-Tips-Tools-and-Resources/ Here is a lesson which includes a great set of resources including Books, MOOCs, Video Tutorials, Interactive tutorials, exercises which can get you started with Python. I have included my review along with some resources, which I have used while teaching Python myself. If I missed out some good book or resources, do leave the link as a comment so that I can update the list. Thanks From wxjmfauth at gmail.com Wed Mar 13 05:36:17 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 13 Mar 2013 02:36:17 -0700 (PDT) Subject: A reply for rusi (FSR) Message-ID: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> As a reply to rusi's comment: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a7689b158fdca29e# >From string creation to the itertools usage. A medley. Some timings. Important: The real/absolute values of these experiments are not important. I do not care and I'm not complaining at all. These values are expected, I expected such values and they are only confirming (*FOR ME*) my understanding of the coding of the characters (and Unicode). #~ py323 py330 #~ test 1: 0.015357737412819 0.019290216142579 #~ test 2: 0.015698801667198 0.020386269052436 #~ test 3: 0.015613338684288 0.018769561472500 #~ test 4: 0.023235297708529 0.032253414679390 #~ test 5: 0.023327062109534 0.029621391108935 #~ test 6: 1.119958127076760 1.095467665651482 #~ test 7: 0.420158472788311 0.565518010043673 #~ test 8: 0.649444234615974 1.061556978013171 #~ test 9: 0.712335144072079 1.211614222458175 #~ test 10: 0.704622996001357 1.160909074081441 #~ test 11: 0.614674584923621 1.053985430333688 #~ test 12: 0.660336235792764 1.059443246081010 #~ test 13: 4.821435927771570 5.795325214218677 #~ test 14: 0.494012668213403 0.729330462512273 #~ test 15: 0.504894429585788 0.879966255906103 #~ test 16: 0.693093370081103 1.132884304782264 #~ test 17: 0.749076743789461 3.013804437852462 #~ test 18: 7.467055989281286 13.387841650089342 #~ test 19: 7.581776062566778 13.593412812594643 #~ test 20: 9.477877493343140 15.235388291413805 #~ test 21: 0.022614608026196 0.020984116094176 #~ test 22: 6.685022041178975 12.687538276191944 #~ test 23: 6.946794763994170 12.986701250949636 #~ test 24: 0.097796827314760 0.156285014715777 #~ test 25: 0.024915807146677 0.034190706904894 #~ test 26: 0.024996544066013 0.032191582014335 #~ test 27: 0.000693943667684 0.001315421027272 #~ test 28: 0.000679765476967 0.001305968900141 #~ test 29: 0.001614344548152 0.025543979763000 #~ test 30: 0.000204008410812 0.000286714523313 #~ test 31: 0.000213460537964 0.000301286552656 #~ test 32: 0.000204008410819 0.000291440586878 #~ test 33: 0.249692904327539 0.497374474766957 #~ test 34: 0.248750448483740 0.513947598194790 #~ test 35: 0.099810130396032 0.249129715085319 jmf From rustompmody at gmail.com Wed Mar 13 06:07:32 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Mar 2013 03:07:32 -0700 (PDT) Subject: A reply for rusi (FSR) References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Mar 13, 2:36?pm, jmfauth wrote: > As a reply to rusi's comment:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > From string creation to the itertools usage. A medley. Some timings. > > Important: > The real/absolute values of these experiments are not important. I do > not care and I'm not complaining at all. > > These values are expected, I expected such values and they are only > confirming (*FOR ME*) my understanding of the coding of the characters > (and Unicode). > > #~ py323 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?py330 > > #~ test ? 1: ? ? ? ? 0.015357737412819 ? ? ? ?0.019290216142579 > #~ test ? 2: ? ? ? ? 0.015698801667198 ? ? ? ?0.020386269052436 > #~ test ? 3: ? ? ? ? 0.015613338684288 ? ? ? ?0.018769561472500 > #~ test ? 4: ? ? ? ? 0.023235297708529 ? ? ? ?0.032253414679390 > #~ test ? 5: ? ? ? ? 0.023327062109534 ? ? ? ?0.029621391108935 > #~ test ? 6: ? ? ? ? 1.119958127076760 ? ? ? ?1.095467665651482 > #~ test ? 7: ? ? ? ? 0.420158472788311 ? ? ? ?0.565518010043673 > #~ test ? 8: ? ? ? ? 0.649444234615974 ? ? ? ?1.061556978013171 > #~ test ? 9: ? ? ? ? 0.712335144072079 ? ? ? ?1.211614222458175 > #~ test ?10: ? ? ? ? 0.704622996001357 ? ? ? ?1.160909074081441 > #~ test ?11: ? ? ? ? 0.614674584923621 ? ? ? ?1.053985430333688 > #~ test ?12: ? ? ? ? 0.660336235792764 ? ? ? ?1.059443246081010 > #~ test ?13: ? ? ? ? 4.821435927771570 ? ? ? ?5.795325214218677 > #~ test ?14: ? ? ? ? 0.494012668213403 ? ? ? ?0.729330462512273 > #~ test ?15: ? ? ? ? 0.504894429585788 ? ? ? ?0.879966255906103 > #~ test ?16: ? ? ? ? 0.693093370081103 ? ? ? ?1.132884304782264 > #~ test ?17: ? ? ? ? 0.749076743789461 ? ? ? ?3.013804437852462 > #~ test ?18: ? ? ? ? 7.467055989281286 ? ? ? 13.387841650089342 > #~ test ?19: ? ? ? ? 7.581776062566778 ? ? ? 13.593412812594643 > #~ test ?20: ? ? ? ? 9.477877493343140 ? ? ? 15.235388291413805 > #~ test ?21: ? ? ? ? 0.022614608026196 ? ? ? ?0.020984116094176 > #~ test ?22: ? ? ? ? 6.685022041178975 ? ? ? 12.687538276191944 > #~ test ?23: ? ? ? ? 6.946794763994170 ? ? ? 12.986701250949636 > #~ test ?24: ? ? ? ? 0.097796827314760 ? ? ? ?0.156285014715777 > #~ test ?25: ? ? ? ? 0.024915807146677 ? ? ? ?0.034190706904894 > #~ test ?26: ? ? ? ? 0.024996544066013 ? ? ? ?0.032191582014335 > #~ test ?27: ? ? ? ? 0.000693943667684 ? ? ? ?0.001315421027272 > #~ test ?28: ? ? ? ? 0.000679765476967 ? ? ? ?0.001305968900141 > #~ test ?29: ? ? ? ? 0.001614344548152 ? ? ? ?0.025543979763000 > #~ test ?30: ? ? ? ? 0.000204008410812 ? ? ? ?0.000286714523313 > #~ test ?31: ? ? ? ? 0.000213460537964 ? ? ? ?0.000301286552656 > #~ test ?32: ? ? ? ? 0.000204008410819 ? ? ? ?0.000291440586878 > #~ test ?33: ? ? ? ? 0.249692904327539 ? ? ? ?0.497374474766957 > #~ test ?34: ? ? ? ? 0.248750448483740 ? ? ? ?0.513947598194790 > #~ test ?35: ? ? ? ? 0.099810130396032 ? ? ? ?0.249129715085319 > > jmf Thank you jmf. I believe that for the first time you have moved beyond a single point of complaint to a swathe of data points which evidently show performance regression. You would need to provide data of what these tests 1-35 are. From rustompmody at gmail.com Wed Mar 13 06:11:18 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Mar 2013 03:11:18 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Mar 13, 3:07?pm, rusi wrote: > On Mar 13, 2:36?pm, jmfauth wrote: > > > > > > > > > > > As a reply to rusi's comment:http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > From string creation to the itertools usage. A medley. Some timings. > > > Important: > > The real/absolute values of these experiments are not important. I do > > not care and I'm not complaining at all. > > > These values are expected, I expected such values and they are only > > confirming (*FOR ME*) my understanding of the coding of the characters > > (and Unicode). > > > #~ py323 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?py330 > > > #~ test ? 1: ? ? ? ? 0.015357737412819 ? ? ? ?0.019290216142579 > > #~ test ? 2: ? ? ? ? 0.015698801667198 ? ? ? ?0.020386269052436 > > #~ test ? 3: ? ? ? ? 0.015613338684288 ? ? ? ?0.018769561472500 > > #~ test ? 4: ? ? ? ? 0.023235297708529 ? ? ? ?0.032253414679390 > > #~ test ? 5: ? ? ? ? 0.023327062109534 ? ? ? ?0.029621391108935 > > #~ test ? 6: ? ? ? ? 1.119958127076760 ? ? ? ?1.095467665651482 > > #~ test ? 7: ? ? ? ? 0.420158472788311 ? ? ? ?0.565518010043673 > > #~ test ? 8: ? ? ? ? 0.649444234615974 ? ? ? ?1.061556978013171 > > #~ test ? 9: ? ? ? ? 0.712335144072079 ? ? ? ?1.211614222458175 > > #~ test ?10: ? ? ? ? 0.704622996001357 ? ? ? ?1.160909074081441 > > #~ test ?11: ? ? ? ? 0.614674584923621 ? ? ? ?1.053985430333688 > > #~ test ?12: ? ? ? ? 0.660336235792764 ? ? ? ?1.059443246081010 > > #~ test ?13: ? ? ? ? 4.821435927771570 ? ? ? ?5.795325214218677 > > #~ test ?14: ? ? ? ? 0.494012668213403 ? ? ? ?0.729330462512273 > > #~ test ?15: ? ? ? ? 0.504894429585788 ? ? ? ?0.879966255906103 > > #~ test ?16: ? ? ? ? 0.693093370081103 ? ? ? ?1.132884304782264 > > #~ test ?17: ? ? ? ? 0.749076743789461 ? ? ? ?3.013804437852462 > > #~ test ?18: ? ? ? ? 7.467055989281286 ? ? ? 13.387841650089342 > > #~ test ?19: ? ? ? ? 7.581776062566778 ? ? ? 13.593412812594643 > > #~ test ?20: ? ? ? ? 9.477877493343140 ? ? ? 15.235388291413805 > > #~ test ?21: ? ? ? ? 0.022614608026196 ? ? ? ?0.020984116094176 > > #~ test ?22: ? ? ? ? 6.685022041178975 ? ? ? 12.687538276191944 > > #~ test ?23: ? ? ? ? 6.946794763994170 ? ? ? 12.986701250949636 > > #~ test ?24: ? ? ? ? 0.097796827314760 ? ? ? ?0.156285014715777 > > #~ test ?25: ? ? ? ? 0.024915807146677 ? ? ? ?0.034190706904894 > > #~ test ?26: ? ? ? ? 0.024996544066013 ? ? ? ?0.032191582014335 > > #~ test ?27: ? ? ? ? 0.000693943667684 ? ? ? ?0.001315421027272 > > #~ test ?28: ? ? ? ? 0.000679765476967 ? ? ? ?0.001305968900141 > > #~ test ?29: ? ? ? ? 0.001614344548152 ? ? ? ?0.025543979763000 > > #~ test ?30: ? ? ? ? 0.000204008410812 ? ? ? ?0.000286714523313 > > #~ test ?31: ? ? ? ? 0.000213460537964 ? ? ? ?0.000301286552656 > > #~ test ?32: ? ? ? ? 0.000204008410819 ? ? ? ?0.000291440586878 > > #~ test ?33: ? ? ? ? 0.249692904327539 ? ? ? ?0.497374474766957 > > #~ test ?34: ? ? ? ? 0.248750448483740 ? ? ? ?0.513947598194790 > > #~ test ?35: ? ? ? ? 0.099810130396032 ? ? ? ?0.249129715085319 > > > jmf > > Thank you jmf. I believe that for the first time you have moved beyond > a single point of complaint to a swathe of data points which evidently > show performance regression. ?You would need to provide data of what > these tests 1-35 are. Uhhh.. Making the subject line useful for all readers From rosuav at gmail.com Wed Mar 13 06:59:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2013 21:59:08 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: > Uhhh.. > Making the subject line useful for all readers I should have read this one before replying in the other thread. jmf, I'd like to see evidence that there has been a performance regression compared against a wide build of Python 3.2. You still have never answered this fundamental, that the narrow builds of Python are *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you me, the utterly unnecessary hassles I have had to deal with when permitting user-provided .js code to script my engine have wasted rather more dev hours than you would believe - there are rather a lot of stupid edge cases to deal with. The PEP 393 string is simply a memory-optimized version of UTF-32. It guarantees O(1) indexing and slicing, while still remaining tight in many cases. Its worst case is a constant amount larger than pure UTF-32 (the overhead of recording the string width), its best case is equivalent to ASCII (if all strings are seven-bit). The flexible string representation is not brand new. It has been tested and proven in another language, one very similar to Python; and its performance has been provably sufficient for everyday operations. Pike's string type behaves just as Python 3.3's, and has done for longer than I can trace backward. In terms of Unicode compliance, it is perfect; in terms of performance, quite acceptable; the worst-case operation is taking an ASCII string and overwriting one character in it with an astral character - which Python flat-out doesn't permit, but Pike does, as a known-slow operation. (It triggers a copy of the string, so it's always going to be slow.) There are two broad areas of complaint that you have raised. One is of Unicode compliance and correctness. I believe those complaints are utterly unfounded, and you have yet to show any serious evidence to support them. Py 3.3 is perfectly compliant with everything I have yet checked. The other complaint is of performance, and the issue of being US-centric. While it's true that ASCII and Latin-1 strings will be smaller/faster under Py 3.3 than 3.2, this is not purely to the benefit of the US at the cost of everyone else; it's also a benefit to the myriad non-US programs that use a lot of ASCII strings - for instance, delimiters, HTML tags, builtin function names... all of these are ASCII, even if the rest of the code isn't. And there's no penalty for non-English speakers, when compared against a non-buggy wide build. The very worst case is only a constant factor worse, and that assumes astral characters in every single string... which does not happen, trust me on that. ChrisA From rustompmody at gmail.com Wed Mar 13 12:49:46 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 13 Mar 2013 09:49:46 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Mar 13, 3:59?pm, Chris Angelico wrote: > On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: > > Uhhh.. > > Making the subject line useful for all readers > > I should have read this one before replying in the other thread. > > jmf, I'd like to see evidence that there has been a performance > regression compared against a wide build of Python 3.2. You still have > never answered this fundamental, that the narrow builds of Python are > *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you > me, the utterly unnecessary hassles I have had to deal with when > permitting user-provided .js code to script my engine have wasted > rather more dev hours than you would believe - there are rather a lot > of stupid edge cases to deal with. This assumes that there are only three choices: - narrow build that is buggy (surrogate pairs for astral characters) - wide build that is 4-fold space inefficient for wide variety of common (ASCII) use-cases - flexible string engine that chooses a small tradeoff of space efficiency over time efficiency. There is a fourth choice: narrow build that chooses to be partial over being buggy. ie when an astral character is encountered, an exception is thrown rather than trying to fudge it into a 16-bit representation. I am hardly a unicode expert, my impression is this: While in today's internationalized world, going back to ASCII is not an option, most actual uses of unicode stay within the BMP Further if the choice is not between two python executables but between string-engines chosen at startup by command-line switches or equivalent, the price may be quite small. From rosuav at gmail.com Wed Mar 13 19:43:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 10:43:58 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: > On Mar 13, 3:59 pm, Chris Angelico wrote: >> On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >> > Uhhh.. >> > Making the subject line useful for all readers >> >> I should have read this one before replying in the other thread. >> >> jmf, I'd like to see evidence that there has been a performance >> regression compared against a wide build of Python 3.2. You still have >> never answered this fundamental, that the narrow builds of Python are >> *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you >> me, the utterly unnecessary hassles I have had to deal with when >> permitting user-provided .js code to script my engine have wasted >> rather more dev hours than you would believe - there are rather a lot >> of stupid edge cases to deal with. > > This assumes that there are only three choices: > - narrow build that is buggy (surrogate pairs for astral characters) > - wide build that is 4-fold space inefficient for wide variety of > common (ASCII) use-cases > - flexible string engine that chooses a small tradeoff of space > efficiency over time efficiency. > > There is a fourth choice: narrow build that chooses to be partial over > being buggy. ie when an astral character is encountered, an exception > is thrown rather than trying to fudge it into a 16-bit > representation. As a simple factual matter, narrow builds of Python 3.2 don't do that. So it doesn't factor into my original statement. But if you're talking about a proposal for 3.4, then sure, that's a theoretical possibility. It wouldn't be "buggy" in the sense of "string indexing/slicing unexpectedly does the wrong thing", but it would still be incomplete Unicode support, and I don't think people would appreciate it. Much better to have graceful degradation: if there are non-BMP characters in the string, then instead of throwing an exception, it just makes the string wider. > I am hardly a unicode expert, my impression is this: While in today's > internationalized world, going back to ASCII is not an option, most > actual uses of unicode stay within the BMP That's a valid line of argument for an optimization, but not for a hard limitation. A general-purpose language, function, system, whatever, will need to cope with astral characters at some point; it just won't need them *often*. > Further if the choice is not between two python executables but > between string-engines chosen at startup by command-line switches or > equivalent, the price may be quite small. It's complexity cost, though, and people would need to know when it would be worth giving Python that switch to change its string format. Plus, every C extension would need to cope with both formats. I personally doubt it'd be worth it, but if you want to knock together a patched CPython and get some timing stats, I'm sure this list or python-dev will be happy to discuss the matter. :) ChrisA From python at mrabarnett.plus.com Wed Mar 13 20:52:08 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Mar 2013 00:52:08 +0000 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: <51411F38.1040901@mrabarnett.plus.com> On 13/03/2013 23:43, Chris Angelico wrote: > On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: >> On Mar 13, 3:59 pm, Chris Angelico wrote: >>> On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >>> > Uhhh.. >>> > Making the subject line useful for all readers >>> >>> I should have read this one before replying in the other thread. >>> >>> jmf, I'd like to see evidence that there has been a performance >>> regression compared against a wide build of Python 3.2. You still have >>> never answered this fundamental, that the narrow builds of Python are >>> *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you >>> me, the utterly unnecessary hassles I have had to deal with when >>> permitting user-provided .js code to script my engine have wasted >>> rather more dev hours than you would believe - there are rather a lot >>> of stupid edge cases to deal with. >> >> This assumes that there are only three choices: >> - narrow build that is buggy (surrogate pairs for astral characters) >> - wide build that is 4-fold space inefficient for wide variety of >> common (ASCII) use-cases >> - flexible string engine that chooses a small tradeoff of space >> efficiency over time efficiency. >> >> There is a fourth choice: narrow build that chooses to be partial over >> being buggy. ie when an astral character is encountered, an exception >> is thrown rather than trying to fudge it into a 16-bit >> representation. > > As a simple factual matter, narrow builds of Python 3.2 don't do that. > So it doesn't factor into my original statement. But if you're talking > about a proposal for 3.4, then sure, that's a theoretical possibility. > It wouldn't be "buggy" in the sense of "string indexing/slicing > unexpectedly does the wrong thing", but it would still be incomplete > Unicode support, and I don't think people would appreciate it. Much > better to have graceful degradation: if there are non-BMP characters > in the string, then instead of throwing an exception, it just makes > the string wider. > [snip] Do you mean that instead of switching between 1/2/4 bytes per codepoint it would switch between 2/4 bytes per codepoint? From rosuav at gmail.com Wed Mar 13 20:55:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 11:55:47 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <51411F38.1040901@mrabarnett.plus.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> Message-ID: On Thu, Mar 14, 2013 at 11:52 AM, MRAB wrote: > On 13/03/2013 23:43, Chris Angelico wrote: >> >> On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: >>> >>> On Mar 13, 3:59 pm, Chris Angelico wrote: >>>> >>>> On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >>>> > Uhhh.. >>>> > Making the subject line useful for all readers >>>> >>>> I should have read this one before replying in the other thread. >>>> >>>> jmf, I'd like to see evidence that there has been a performance >>>> regression compared against a wide build of Python 3.2. You still have >>>> never answered this fundamental, that the narrow builds of Python are >>>> *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you >>>> me, the utterly unnecessary hassles I have had to deal with when >>>> permitting user-provided .js code to script my engine have wasted >>>> rather more dev hours than you would believe - there are rather a lot >>>> of stupid edge cases to deal with. >>> >>> >>> This assumes that there are only three choices: >>> - narrow build that is buggy (surrogate pairs for astral characters) >>> - wide build that is 4-fold space inefficient for wide variety of >>> common (ASCII) use-cases >>> - flexible string engine that chooses a small tradeoff of space >>> efficiency over time efficiency. >>> >>> There is a fourth choice: narrow build that chooses to be partial over >>> being buggy. ie when an astral character is encountered, an exception >>> is thrown rather than trying to fudge it into a 16-bit >>> representation. >> >> >> As a simple factual matter, narrow builds of Python 3.2 don't do that. >> So it doesn't factor into my original statement. But if you're talking >> about a proposal for 3.4, then sure, that's a theoretical possibility. >> It wouldn't be "buggy" in the sense of "string indexing/slicing >> unexpectedly does the wrong thing", but it would still be incomplete >> Unicode support, and I don't think people would appreciate it. Much >> better to have graceful degradation: if there are non-BMP characters >> in the string, then instead of throwing an exception, it just makes >> the string wider. >> > [snip] > Do you mean that instead of switching between 1/2/4 bytes per codepoint > it would switch between 2/4 bytes per codepoint? That's my point. We already have the better version. :) ChrisA From python at mrabarnett.plus.com Wed Mar 13 22:01:35 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Mar 2013 02:01:35 +0000 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> Message-ID: <51412F7F.7040608@mrabarnett.plus.com> On 14/03/2013 00:55, Chris Angelico wrote: > On Thu, Mar 14, 2013 at 11:52 AM, MRAB wrote: >> On 13/03/2013 23:43, Chris Angelico wrote: >>> >>> On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: >>>> >>>> On Mar 13, 3:59 pm, Chris Angelico wrote: >>>>> >>>>> On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >>>>> > Uhhh.. >>>>> > Making the subject line useful for all readers >>>>> >>>>> I should have read this one before replying in the other thread. >>>>> >>>>> jmf, I'd like to see evidence that there has been a performance >>>>> regression compared against a wide build of Python 3.2. You still have >>>>> never answered this fundamental, that the narrow builds of Python are >>>>> *BUGGY* in the same way that JavaScript/ECMAScript is. And believe you >>>>> me, the utterly unnecessary hassles I have had to deal with when >>>>> permitting user-provided .js code to script my engine have wasted >>>>> rather more dev hours than you would believe - there are rather a lot >>>>> of stupid edge cases to deal with. >>>> >>>> >>>> This assumes that there are only three choices: >>>> - narrow build that is buggy (surrogate pairs for astral characters) >>>> - wide build that is 4-fold space inefficient for wide variety of >>>> common (ASCII) use-cases >>>> - flexible string engine that chooses a small tradeoff of space >>>> efficiency over time efficiency. >>>> >>>> There is a fourth choice: narrow build that chooses to be partial over >>>> being buggy. ie when an astral character is encountered, an exception >>>> is thrown rather than trying to fudge it into a 16-bit >>>> representation. >>> >>> >>> As a simple factual matter, narrow builds of Python 3.2 don't do that. >>> So it doesn't factor into my original statement. But if you're talking >>> about a proposal for 3.4, then sure, that's a theoretical possibility. >>> It wouldn't be "buggy" in the sense of "string indexing/slicing >>> unexpectedly does the wrong thing", but it would still be incomplete >>> Unicode support, and I don't think people would appreciate it. Much >>> better to have graceful degradation: if there are non-BMP characters >>> in the string, then instead of throwing an exception, it just makes >>> the string wider. >>> >> [snip] >> Do you mean that instead of switching between 1/2/4 bytes per codepoint >> it would switch between 2/4 bytes per codepoint? > > That's my point. We already have the better version. :) > If a later version of Python switched between 2/4 bytes per codepoint, how much difference would it make in terms of memory and speed compared to Python 3.2 (fixed width) and Python 3.3 (3 widths)? The vast majority of the time, 2 bytes per codepoint is sufficient, but would that result in less switching between widths and therefore higher performance, or would the use of more memory (2 bytes when 1 byte would do) offset that? (And I'm talking about significant differences here.) From steve+comp.lang.python at pearwood.info Thu Mar 14 00:05:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2013 04:05:11 GMT Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> Message-ID: <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Mar 2013 02:01:35 +0000, MRAB wrote: > On 14/03/2013 00:55, Chris Angelico wrote: >> On Thu, Mar 14, 2013 at 11:52 AM, MRAB >> wrote: >>> On 13/03/2013 23:43, Chris Angelico wrote: >>>> >>>> On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: >>>>> >>>>> On Mar 13, 3:59 pm, Chris Angelico wrote: >>>>>> >>>>>> On Wed, Mar 13, 2013 at 9:11 PM, rusi >>>>>> wrote: >>>>>> > Uhhh.. >>>>>> > Making the subject line useful for all readers >>>>>> >>>>>> I should have read this one before replying in the other thread. >>>>>> >>>>>> jmf, I'd like to see evidence that there has been a performance >>>>>> regression compared against a wide build of Python 3.2. You still >>>>>> have never answered this fundamental, that the narrow builds of >>>>>> Python are *BUGGY* in the same way that JavaScript/ECMAScript is. >>>>>> And believe you me, the utterly unnecessary hassles I have had to >>>>>> deal with when permitting user-provided .js code to script my >>>>>> engine have wasted rather more dev hours than you would believe - >>>>>> there are rather a lot of stupid edge cases to deal with. >>>>> >>>>> >>>>> This assumes that there are only three choices: - narrow build that >>>>> is buggy (surrogate pairs for astral characters) - wide build that >>>>> is 4-fold space inefficient for wide variety of common (ASCII) >>>>> use-cases >>>>> - flexible string engine that chooses a small tradeoff of space >>>>> efficiency over time efficiency. >>>>> >>>>> There is a fourth choice: narrow build that chooses to be partial >>>>> over being buggy. ie when an astral character is encountered, an >>>>> exception is thrown rather than trying to fudge it into a 16-bit >>>>> representation. >>>> >>>> >>>> As a simple factual matter, narrow builds of Python 3.2 don't do >>>> that. So it doesn't factor into my original statement. But if you're >>>> talking about a proposal for 3.4, then sure, that's a theoretical >>>> possibility. It wouldn't be "buggy" in the sense of "string >>>> indexing/slicing unexpectedly does the wrong thing", but it would >>>> still be incomplete Unicode support, and I don't think people would >>>> appreciate it. Much better to have graceful degradation: if there are >>>> non-BMP characters in the string, then instead of throwing an >>>> exception, it just makes the string wider. >>>> >>> [snip] >>> Do you mean that instead of switching between 1/2/4 bytes per >>> codepoint it would switch between 2/4 bytes per codepoint? >> >> That's my point. We already have the better version. :) >> > If a later version of Python switched between 2/4 bytes per codepoint, > how much difference would it make in terms of memory and speed compared > to Python 3.2 (fixed width) and Python 3.3 (3 widths)? > > The vast majority of the time, 2 bytes per codepoint is sufficient, but > would that result in less switching between widths and therefore higher > performance, or would the use of more memory (2 bytes when 1 byte would > do) offset that? > > (And I'm talking about significant differences here.) That depends on how you use the strings. Because strings are immutable, there isn't really anything like "switching between widths" -- the width is set when the string is created, and then remains fixed. It is true that when you create a string, Python sometimes has to do some work to determine what width it needs, but that's effectively a fixed- cost per string. It's relatively trivial compared to the cost of other string operations, but it is a real cost. If all you do is create the strings then throw them away, as JMF tends to do in his benchmarks, you repeatedly pay the cost without seeing the benefit. On the other hand, Python is *full* of large numbers of ASCII strings, and many users use lots of Latin1 strings. Both of these save significant amounts of memory: almost 50% of what they would otherwise use in a narrow build, and almost 75% in a wide build. This memory saving has real consequences, performance-wise. Python's memory management can be more efficient, since objects in the heap are smaller. I'm not sure if objects ever move in the heap (I think Java's memory manager does move objects around, hence Jython will do so, but I'm not sure about CPython), but even if they don't, its obviously faster to allocate a certain sized block of memory the more free memory you have, and you'll have more free memory if any pre-existing objects in the heap are smaller. I expect that traversing a block of memory byte-by-byte may be faster than traversing it 2x or 4x bytes at a time. My testing suggests that iterating over a 1-byte width string is about three times faster than iterating over a 2-byte or 4-byte wide string. But that may depend on your OS and hardware. Finally, there may be CPU effects, to do with how quickly strings can be passed through the CPU pipelines, whether data is found in the CPU cache or not, etc. Obviously this too will depend on the size of the strings. You can squeeze 1K of data through the CPU faster than 4K of data. In practice, how much of an effect will this have? It's hard to say without testing, but indications with real-world applications indicate that Python 3.3 not only saves significant memory over 3.2 narrow builds, but for real-world code, it can often be a little faster as well. -- Steven From rosuav at gmail.com Thu Mar 14 02:47:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 17:47:12 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 14, 2013 at 3:05 PM, Steven D'Aprano wrote: > That depends on how you use the strings. Because strings are immutable, > there isn't really anything like "switching between widths" -- the width > is set when the string is created, and then remains fixed. The nearest thing to "switching" is where you repeatedly replace() or append/slice to add/remove the one non-ASCII character that your contrived test is using. Let's see... Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 ASCII -> ASCII: >>> timeit.timeit("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) 0.14999895238081962 ASCII -> BMP: >>> timeit.timeit("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) 1.7513426985832012 BMP -> BMP: >>> timeit.timeit("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) 0.22562895563542895 ASCII -> SMP: >>> timeit.timeit("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) 1.9037101084076369 BMP -> SMP: >>> timeit.timeit("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) 1.9659967956821163 SMP -> SMP: >>> timeit.timeit("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) 0.7214749360603037 So there *is* cost to "changing size". Trying them again in Python 2.6 Narrow: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 ASCII -> ASCII: >>> timeit.timeit("s=s[:-1]+u'\u0034'","s=u'asdf'*10000",number=10000) 0.53506213778566547 ASCII -> BMP: >>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'asdf'*10000",number=10000) 0.57752172412974268 BMP -> BMP: >>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'\u1234sdf'*10000",number=10000) 0.53309121690045913 ASCII -> SMP: >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'asdf'*10000",number=10000) 0.55128347317885584 BMP -> SMP: >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'\u1234sdf'*10000",number=10000) 0.55610140394938412 SMP -> SMP: >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'\U00012345sdf'*10000",number=10000) 0.6599570615818493 Much more consistent. (Note that the SMP timings are quite probably a bit off as the string will continue to grow - I'm taking off one 16-bit character and putting on two.) I don't have a 2.6 wide build on the same hardware, so these times don't truly compare to the above ones. This is slower hardware than the above tests. Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 >>> timeit.timeit("s=s[:-1]+u'\u0034'","s=u'asdf'*10000",number=10000) 1.5774970054626465 >>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'asdf'*10000",number=10000) 1.5743560791015625 >>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'\u1234sdf'*10000",number=10000) 1.6072981357574463 >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'asdf'*10000",number=10000) 1.6745591163635254 >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'\u1234sdf'*10000",number=10000) 1.6705770492553711 >>> timeit.timeit("s=s[:-1]+u'\U00012345'","s=u'\U00012345sdf'*10000",number=10000) 1.7078530788421631 Here's my reading of all these stats. Python 3.3's str is faster than 2.6's unicode when the copy can be done directly (ie when the size isn't changing), but converting sizes costs a lot (suggestion: memcpy is blazingly fast, no surprise there). Since MOST string operations won't change the size, this is a benefit to most programs. I expect that Python 3.2 will behave comparably to the 2.6 stats, but I don't have 3.2s handy - can someone confirm please? ChrisA From rustompmody at gmail.com Thu Mar 14 06:48:08 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 14 Mar 2013 03:48:08 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com> On Mar 14, 11:47?am, Chris Angelico wrote: > I expect that Python 3.2 will behave comparably to the 2.6 stats, but > I don't have 3.2s handy - can someone confirm please? I have 3.2 but not 3.3. Can run it later today if no one does. But better if someone with both on the same machine do the comparison. jmf will you please run Chris' examples on all your pythons? From tjreedy at udel.edu Thu Mar 14 19:14:32 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Mar 2013 19:14:32 -0400 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com> Message-ID: On 3/14/2013 6:48 AM, rusi wrote: > On Mar 14, 11:47 am, Chris Angelico wrote: > >> I expect that Python 3.2 will behave comparably to the 2.6 stats, but >> I don't have 3.2s handy - can someone confirm please? > > I have 3.2 but not 3.3. Can run it later today if no one does. > But better if someone with both on the same machine do the comparison. The python devs use the microbenchmarks in Tools/stringbench/stringbench.py, which covers all string operations, as the basis for improving particular string functions. Overall, Unicode is nearly as fast as bytes and 3.3 as fast as 3.2. Find/replace is the notable exception in stringbench, so it is an anomaly. Other things are faster in 3.3. In selecting the new implementation, the devs also considered space and speed gains that do not show up in microbenchmarks. -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 14 20:48:16 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Mar 2013 20:48:16 -0400 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com> Message-ID: On 3/14/2013 7:14 PM, Terry Reedy wrote: > On 3/14/2013 6:48 AM, rusi wrote: >> On Mar 14, 11:47 am, Chris Angelico wrote: >> >>> I expect that Python 3.2 will behave comparably to the 2.6 stats, but >>> I don't have 3.2s handy - can someone confirm please? >> >> I have 3.2 but not 3.3. Can run it later today if no one does. >> But better if someone with both on the same machine do the comparison. > > The python devs use the microbenchmarks in > Tools/stringbench/stringbench.py, which covers all string operations, as > the basis for improving particular string functions. Overall, Unicode is > nearly as fast as bytes and 3.3 as fast as 3.2. Find/replace is the > notable exception in stringbench, so it is an anomaly. Other things are > faster in 3.3. In selecting the new implementation, the devs also > considered space and speed gains that do not show up in microbenchmarks. Links to the readme and code for stringbench can be found here: http://hg.python.org/cpython/file/c25bc2587c48/Tools/stringbench -- Terry Jan Reedy From rustompmody at gmail.com Fri Mar 15 13:07:48 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 10:07:48 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <51411F38.1040901@mrabarnett.plus.com> <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com> <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com> Message-ID: <4eb54568-3135-4e81-9784-ff3ed989916b@mz7g2000pbb.googlegroups.com> 3.2 and 2.7 results on my desktop using Chris examples (Hope I cut-pasted them correctly) ----------------------------- Welcome to the Emacs shell ~ $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from timeit import timeit >>> timeit("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) 0.2893378734588623 >>> timeit("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) 0.2842249870300293 >>> timeit("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) 0.28406381607055664 >>> timeit("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) 0.28420209884643555 >>> timeit("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) 0.2853250503540039 >>> timeit("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) 0.283905029296875 >>> ~ $ python Python 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from timeit import timeit >>> timeit("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) 0.20418286323547363 >>> timeit("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) 0.20579099655151367 >>> timeit("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) 0.5055279731750488 >>> timeit("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) 0.28449511528015137 >>> timeit("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) 0.6001529693603516 >>> timeit("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) 0.8430721759796143 From andriy.kornatskyy at live.com Fri Mar 15 14:04:24 2013 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Fri, 15 Mar 2013 21:04:24 +0300 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <4eb54568-3135-4e81-9784-ff3ed989916b@mz7g2000pbb.googlegroups.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com>, , , , , , <51411F38.1040901@mrabarnett.plus.com>, , , <51414c75$0$29965$c3e8da3$5496439d@news.astraweb.com>, , <7cd57e96-663b-4a3b-a2c8-2fdbf730fa9b@hd10g2000pbc.googlegroups.com>, <4eb54568-3135-4e81-9784-ff3ed989916b@mz7g2000pbb.googlegroups.com> Message-ID: $ python3.2 Python 3.2.3 (default, Jun 25 2012, 22:55:05)? [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from timeit import repeat >>> repeat("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) [0.2566258907318115, 0.14485502243041992, 0.14464998245239258] >>> repeat("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) [0.25584888458251953, 0.1340939998626709, 0.1338820457458496] >>> repeat("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) [0.2571289539337158, 0.13403892517089844, 0.13388800621032715] >>> repeat("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) [0.5022759437561035, 0.3970041275024414, 0.3764481544494629] >>> repeat("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) [0.5213770866394043, 0.38585615158081055, 0.40251588821411133] >>> repeat("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) [0.768744945526123, 0.5852570533752441, 0.6029140949249268] $ python3.3 Python 3.3.0 (default, Sep 29 2012, 15:35:49)? [GCC 4.7.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from timeit import repeat >>> repeat("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) [0.0985728640225716, 0.0984080360212829, 0.07457763599813916] >>> repeat("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) [0.901988381985575, 0.7517840950167738, 0.7540924890199676] >>> repeat("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) [0.3069786810083315, 0.17701858800137416, 0.1769046070112381] >>> repeat("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) [1.081760977016529, 0.9099628589756321, 0.9926943230093457] >>> repeat("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) [1.2101859120011795, 1.1039280130062252, 0.9306247030035593] >>> repeat("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) [0.4759294819959905, 0.35435649199644104, 0.3540659479913302] ---------------------------------------- > Date: Fri, 15 Mar 2013 10:07:48 -0700 > Subject: Re: String performance regression from python 3.2 to 3.3 > From: rustompmody at gmail.com > To: python-list at python.org > > 3.2 and 2.7 results on my desktop using Chris examples > (Hope I cut-pasted them correctly) > ----------------------------- > Welcome to the Emacs shell > > ~ $ python3 > Python 3.2.3 (default, Feb 20 2013, 17:02:41) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from timeit import timeit > >>> timeit("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) > 0.2893378734588623 > >>> timeit("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) > 0.2842249870300293 > > >>> timeit("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) > 0.28406381607055664 > >>> timeit("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) > 0.28420209884643555 > >>> timeit("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) > 0.2853250503540039 > >>> timeit("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) > 0.283905029296875 > >>> > > ~ $ python > Python 2.7.3 (default, Jan 2 2013, 16:53:07) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from timeit import timeit > >>> timeit("s=s[:-1]+'\u0034'","s='asdf'*10000",number=10000) > 0.20418286323547363 > >>> timeit("s=s[:-1]+'\u1234'","s='asdf'*10000",number=10000) > > 0.20579099655151367 > >>> timeit("s=s[:-1]+'\u1234'","s='\u1234sdf'*10000",number=10000) > 0.5055279731750488 > >>> timeit("s=s[:-1]+'\U00012345'","s='asdf'*10000",number=10000) > 0.28449511528015137 > >>> timeit("s=s[:-1]+'\U00012345'","s='\u1234sdf'*10000",number=10000) > 0.6001529693603516 > >>> timeit("s=s[:-1]+'\U00012345'","s='\U00012345sdf'*10000",number=10000) > 0.8430721759796143 > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Wed Mar 13 22:35:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Mar 2013 22:35:44 -0400 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On 3/13/2013 7:43 PM, Chris Angelico wrote: > On Thu, Mar 14, 2013 at 3:49 AM, rusi wrote: > >> This assumes that there are only three choices: >> - narrow build that is buggy (surrogate pairs for astral characters) >> - wide build that is 4-fold space inefficient for wide variety of >> common (ASCII) use-cases >> - flexible string engine that chooses a small tradeoff of space >> efficiency over time efficiency. Wrong. Python almost certainly runs faster with the new string representation. This has been explained previously more than once. >> There is a fourth choice: narrow build that chooses to be partial over >> being buggy. ie when an astral character is encountered, an exception >> is thrown rather than trying to fudge it into a 16-bit >> representation. This is what tcl/tk does, and it is a dammed nuisance. Completely unacceptible for Python's string type. ... > It's complexity cost, though, and people would need to know when it > would be worth giving Python that switch to change its string format. > Plus, every C extension would need to cope with both formats. I > personally doubt it'd be worth it, but if you want to knock together a > patched CPython and get some timing stats, I'm sure this list or > python-dev will be happy to discuss the matter. :) I presume the smiley indicates that you know that python developers are too busy with real problems to have any interest in bogus solutions to bogus problems. -- Terry Jan Reedy From rosuav at gmail.com Thu Mar 14 02:21:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 17:21:00 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: On Thu, Mar 14, 2013 at 1:35 PM, Terry Reedy wrote: >On 3/13/2013 7:43 PM, Chris Angelico wrote: >> It's complexity cost, though, and people would need to know when it >> would be worth giving Python that switch to change its string format. >> Plus, every C extension would need to cope with both formats. I >> personally doubt it'd be worth it, but if you want to knock together a >> patched CPython and get some timing stats, I'm sure this list or >> python-dev will be happy to discuss the matter. :) > > > I presume the smiley indicates that you know that python developers are too > busy with real problems to have any interest in bogus solutions to bogus > problems. It indicates more that the list(s) would almost certainly open up with quite a bit of discussion - especially this one. It's not hard to get talk happening, as evidenced by the number of times we've already discussed this very topic. Frankly, I doubt there'll be anything to discuss - that the patched version will be consistently worse; but if I've learned one thing about timings, it's that there are surprises *everywhere*, so I'm not prepared to state categorically that it *cannot* be better. (I will, however, state that I do not expect any such improvement to be worth the trouble of writing it.) ChrisA From PointedEars at web.de Wed Mar 13 13:42:21 2013 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 13 Mar 2013 18:42:21 +0100 Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: <2992273.neLn1eVAPo@PointedEars.de> Chris Angelico wrote: > On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >> Uhhh.. >> Making the subject line useful for all readers > > I should have read this one before replying in the other thread. > > jmf, I'd like to see evidence that there has been a performance > regression compared against a wide build of Python 3.2. You still have > never answered this fundamental, that the narrow builds of Python are > *BUGGY* in the same way that JavaScript/ECMAScript is. Interesting. From my work I was under the impression that I knew ECMAScript and its implementations fairly well, yet I have never heard of this before. What do you mean by ?narrow build? and ?wide build? and what exactly is the bug ?narrow builds? of Python 3.2 have in common with JavaScript/ECMAScript? To which implementation of ECMAScript are you referring ? or are you referring to the Specification as such? -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From rosuav at gmail.com Wed Mar 13 20:19:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 11:19:11 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <2992273.neLn1eVAPo@PointedEars.de> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> Message-ID: On Thu, Mar 14, 2013 at 4:42 AM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> On Wed, Mar 13, 2013 at 9:11 PM, rusi wrote: >>> Uhhh.. >>> Making the subject line useful for all readers >> >> I should have read this one before replying in the other thread. >> >> jmf, I'd like to see evidence that there has been a performance >> regression compared against a wide build of Python 3.2. You still have >> never answered this fundamental, that the narrow builds of Python are >> *BUGGY* in the same way that JavaScript/ECMAScript is. > > Interesting. From my work I was under the impression that I knew ECMAScript > and its implementations fairly well, yet I have never heard of this before. > > What do you mean by ?narrow build? and ?wide build? and what exactly is the > bug ?narrow builds? of Python 3.2 have in common with JavaScript/ECMAScript? > To which implementation of ECMAScript are you referring ? or are you > referring to the Specification as such? The ECMAScript spec says that strings are stored and represented in UTF-16. Python versions up to 3.2 came in two varieties: narrow, which included (I believe) the Windows builds available on python.org, and wide, which was (again, I think) the default Linux config. The problem predates Python 3 and its default string being Unicode - the Py2 unicode type has the same issue: Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 >>> u"\U00012345" u'\U00012345' >>> len(_) 2 Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> u"\U00012345" u'\U00012345' >>> len(_) 1 That's the Python msi installer, and the default system Python from an Ubuntu 10.10. The exact same code does different things on different platforms, and on the Windows (narrow-build), it's possible to split surrogates: >>> u"\U00012345"[0] u'\ud808' >>> u"\U00012345"[1] u'\udf45' You can see the same thing in Javascript too. Here's a little demo I just knocked together:
    Give it an ASCII string and you'll see, as expected, one index (based on string indexing or charCodeAt, same thing) for each character. Same if it's all BMP. But put an astral character in and you'll see 00.00.d8.00/24 (oh wait, CIDR notation doesn't work in Unicode) come up. I raised this issue on the Google V8 list and on the ECMAScript list es-discuss at mozilla.org, and was basically told that since JavaScript has been buggy for so long, there's no chance of ever making it bug-free: https://mail.mozilla.org/pipermail/es-discuss/2012-December/027384.html Fortunately for Python, there are version numbers, and policies that permit bugs to actually get fixed. (Which is why, for instance, Debian Squeeze still ships Python 2.6 rather than upgrading to 2.7 - in case some script is broken by that change. Can't do that with web browsers.) As of Python 3.3, all Pythons function the same way: it's semantically a "wide build" (UTF-32), but with a memory usage optimization. That's how it needs to be. ChrisA From PointedEars at web.de Fri Mar 15 22:44:35 2013 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 16 Mar 2013 03:44:35 +0100 Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> Message-ID: <2202673.rtQqbKup0V@PointedEars.de> Chris Angelico wrote: > Thomas 'PointedEars' Lahn [?] wrote: >> Chris Angelico wrote: >>> jmf, I'd like to see evidence that there has been a performance >>> regression compared against a wide build of Python 3.2. You still have >>> never answered this fundamental, that the narrow builds of Python are >>> *BUGGY* in the same way that JavaScript/ECMAScript is. >> >> Interesting. From my work I was under the impression that I knew >> ECMAScript and its implementations fairly well, yet I have never heard of >> this before. >> >> What do you mean by ?narrow build? and ?wide build? and what exactly is >> the bug ?narrow builds? of Python 3.2 have in common with >> JavaScript/ECMAScript? To which implementation of ECMAScript are you >> referring ? or are you referring to the Specification as such? > > The ECMAScript spec says that strings are stored and represented in > UTF-16. No, it does not (which Edition?). It says in Edition 5.1: | 8.4 The String Type | | The String type is the set of all finite ordered sequences of zero or more | 16-bit unsigned integer values (?elements?). [?] Each element is regarded | as occupying a position within the sequence. These positions are indexed | with nonnegative integers. The first element (if any) is at position 0, | the next element (if any) at position 1, and so on. The length of a | String is the number of elements (i.e., 16-bit values) within it. | | [?] | When a String contains actual textual data, each element is considered to | be a single UTF-16 code unit. Whether or not this is the actual storage | format of a String, the characters within a String are numbered by | their initial code unit element position as though they were represented | using UTF-16. All operations on Strings (except as otherwise stated) treat | them as sequences of undifferentiated 16-bit unsigned integers; they do | not ensure the resulting String is in normalised form, nor do they ensure | language-sensitive results. | | NOTE | The rationale behind this design was to keep the implementation of Strings | as simple and high-performing as possible. The intent is that textual data | coming into the execution environment from outside (e.g., user input, text | read from a file or received over the network, etc.) be converted to | Unicode Normalised Form C before the running program sees it. Usually this | would occur at the same time incoming text is converted from its original | character encoding to Unicode (and would impose no additional overhead). | Since it is recommended that ECMAScript source code be in Normalised Form | C, string literals are guaranteed to be normalised (if source text is | guaranteed to be normalised), as long as they do not contain any Unicode | escape sequences. > You can see the same thing in Javascript too. Here's a little demo I > just knocked together: > > > value="Show">
    What an awful piece of code. > Give it an ASCII string You mean a string of Unicode characters that can also be represented with the US-ASCII encoding. There are no "ASCII strings" in conforming ECMAScript implementations. And a string of Unicode characters with code points within the BMP will suffice already. > and you'll see, as expected, one index (based on string indexing or > charCodeAt, same thing) for each character. Same if it's all BMP. But put > an astral character in and you'll see 00.00.d8.00/24 (oh wait, CIDR > notation doesn't work in Unicode) come up. I raised this issue on the > Google V8 list and on the ECMAScript list es-discuss at mozilla.org, and was > basically told that since JavaScript has been buggy for so long, there's > no chance of ever making it bug-free: > > https://mail.mozilla.org/pipermail/es-discuss/2012-December/027384.html You misunderstand, and I am not buying Rick's answer. The problem is not that String values are defined as units of 16 bits. The problem is that the length of a primitive String value in ECMAScript, and the position of a character, is defined in terms of 16-bit units instead of characters. There is no bug, because ECMAScript specifies that Unicode characters beyond the Basic Multilingual Plane (BMP) need not be supported: | 2 Conformance | | A conforming implementation of this Standard shall interpret characters in | conformance with the Unicode Standard, Version 3.0 or later and ISO/IEC | 10646-1 with either UCS-2 or UTF-16 as the adopted encoding form, | implementation level 3. If the adopted ISO/IEC 10646-1 subset is not | otherwise specified, it is presumed to be the BMP subset, collection 300. | If the adopted encoding form is not otherwise specified, it presumed to | be the UTF-16 encoding form. But they can: | A conforming implementation of ECMAScript is permitted to provide | additional types, values, objects, properties, and functions beyond those | described in this specification. In particular, a conforming | implementation of ECMAScript is permitted to provide properties not | described in this specification, and values for those properties, for | objects that are described in this specification. | | A conforming implementation of ECMAScript is permitted to support program | and regular expression syntax not described in this specification. In | particular, a conforming implementation of ECMAScript is permitted to | support program syntax that makes use of the ?future reserved words? | listed in 7.6.1.2 of this specification. People have found ways to make this work in ECMAScript implementations. For example, it is possible to scan a normalized string for lead surrogates: String.fromCharCode = (function () { var _fromCharCode = String.fromCharCode; var span; return function () { var a = []; for (var i = 0, len = arguments.length; i < len; ++i) { var arg = arguments[i]; var ch; if (arg > 0xFFFF) { if (typeof span == "undefined") { span = document.createElement("span"); } span.innerHTML = "&#" + arg + ";"; ch = span.firstChild.nodeValue; } else { ch = _fromCharCode(arg); } a.push(ch); } return a.join(""); }; }()); /* "?" (U+1D122 MUSICAL SYMBOL F CLEF) */ var sFClef = String.fromCharCode(0x1D122); String.prototype.getLength = function () { return (this.match(/[\uD800-\uDBFF][^\uD800-\uDBFF]|[\S\s]/g) || []).length; }; /* 1 */ sFClef.getLength() (String.prototype.charAt() etc. are left as an exercise to the reader.) Tested in Chromium 25.0.1364.160 Debian 7.0 (186726), which according to Wikipedia should feature V8 3.15.11.5. But yes, there should be native support for Unicode characters with code points beyond the BMP, and evidently that does _not_ require a second language; just a few tweaks to the algorithms. > Fortunately for Python, there are version numbers, and policies that > permit bugs to actually get fixed. (Which is why, for instance, Debian > Squeeze still ships Python 2.6 rather than upgrading to 2.7 - in case > some script is broken by that change. Debian already ships Python 3.1 in Stable, disproving your argument. > Can't do that with web browsers.) Yes, you could. It has been done before. > As of Python 3.3, all Pythons function the same way: it's > semantically a "wide build" (UTF-32), but with a memory usage > optimization. That's how it needs to be. It is _not_ necessary to use the memory-expensive UTF-32 or a memory-cheaper mixed encoding to represent characters beyond the BMP. UTF-32 would be more runtime-efficient than any other encoding for such strings, though, because you could divide by 32 for the length and would not have to find lead surrogates to determine a character's position. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From breamoreboy at yahoo.co.uk Fri Mar 15 23:56:31 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 16 Mar 2013 03:56:31 +0000 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <2202673.rtQqbKup0V@PointedEars.de> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > Thomas and Chris, would the two of you be kind enough to explain to morons such as myself how all the ECMAScript stuff relates to Python's unicode as implemented via PEP 393 as you've lost me, easily done I know. -- Cheers. Mark Lawrence From rosuav at gmail.com Sat Mar 16 00:09:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Mar 2013 15:09:56 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: On Sat, Mar 16, 2013 at 2:56 PM, Mark Lawrence wrote: > On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: >> >> Chris Angelico wrote: >> > > Thomas and Chris, would the two of you be kind enough to explain to morons > such as myself how all the ECMAScript stuff relates to Python's unicode as > implemented via PEP 393 as you've lost me, easily done I know. Sure. Here's the brief version: It's all about how a string is exposed to a script. * Python 3.2 Narrow gives you UTF-16. Non-BMP characters count twice. * Python 3.2 Wide gives you UTF-32. Each character counts once. * Python 3.3 gives you UTF-32, but will store it as compactly as possible. * ECMAScript specifies the semantics of Python 3.2 Narrow. Python 3.2 was either buggy or inefficient. (Generally, Windows builds were buggy and Linux builds were inefficient, but you could pick at compilation time.) String indexing followed obvious rules, as long as everything fitted inside UCS-2, or you paid the four-bytes-per-character price of a wide build. Otherwise, stuff went off-kilter. PEP 393 fixed the matter, and the arguments were about implementation, efficiency, and so on - but (far as I know) nobody ever argued that the semantics of UTF-16 strings should be kept. That's the difference with ES - that behaviour, peculiar though it be, is actually mandated by the spec. I have banged my head against it at work (amazingly, PHP's complete lack of native Unicode support is actually easier to work with there - though mainly I just throw the stuff at PostgreSQL, which will throw an error back if anything's wrong); it's an insane mandate. But it's part of the spec, and it can't be changed now. ChrisA From rustompmody at gmail.com Sat Mar 16 00:35:42 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 21:35:42 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> On Mar 16, 9:09?am, Chris Angelico wrote: > On Sat, Mar 16, 2013 at 2:56 PM, Mark Lawrence wrote: > > On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: > > >> Chris Angelico wrote: > > > Thomas and Chris, would the two of you be kind enough to explain to morons > > such as myself how all the ECMAScript stuff relates to Python's unicode as > > implemented via PEP 393 as you've lost me, easily done I know. > > Sure. Here's the brief version: It's all about how a string is exposed > to a script. > > * Python 3.2 Narrow gives you UTF-16. Non-BMP characters count twice. > * Python 3.2 Wide gives you UTF-32. Each character counts once. > * Python 3.3 gives you UTF-32, but will store it as compactly as possible. Framing issue here (made famous by en.wikipedia.org/wiki/ George_Lakoff) When one uses words like 'compact' 'flexible' etc it loads the dice in favour of 3.3 choices. And ignores that 3.3 trades time for space. From breamoreboy at yahoo.co.uk Sat Mar 16 00:56:41 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 16 Mar 2013 04:56:41 +0000 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> Message-ID: On 16/03/2013 04:35, rusi wrote: > On Mar 16, 9:09 am, Chris Angelico wrote: >> On Sat, Mar 16, 2013 at 2:56 PM, Mark Lawrence wrote: >>> On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: >> >>>> Chris Angelico wrote: >> >>> Thomas and Chris, would the two of you be kind enough to explain to morons >>> such as myself how all the ECMAScript stuff relates to Python's unicode as >>> implemented via PEP 393 as you've lost me, easily done I know. >> >> Sure. Here's the brief version: It's all about how a string is exposed >> to a script. >> >> * Python 3.2 Narrow gives you UTF-16. Non-BMP characters count twice. >> * Python 3.2 Wide gives you UTF-32. Each character counts once. >> * Python 3.3 gives you UTF-32, but will store it as compactly as possible. > > Framing issue here (made famous by en.wikipedia.org/wiki/ > George_Lakoff) > > When one uses words like 'compact' 'flexible' etc it loads the dice in > favour of 3.3 choices. > And ignores that 3.3 trades time for space. > As stated in PEP 393 so what's all the fuss about? -- Cheers. Mark Lawrence From tjreedy at udel.edu Sat Mar 16 01:05:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Mar 2013 01:05:15 -0400 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> Message-ID: On 3/16/2013 12:35 AM, rusi wrote: > And ignores that 3.3 trades time for space. This is at least a partial falsehood. It is really sad to see you parroting this. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Mar 16 01:38:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2013 05:38:37 GMT Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <8b4723a3-b2dd-4b31-84ca-261483842f69@y7g2000pbu.googlegroups.com> Message-ID: <5144055c$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Mar 2013 21:35:42 -0700, rusi wrote: > And ignores that 3.3 trades time for space. So what? Lists, dicts and sets trade time for space: they are generally over-allocated to ensure a certainly level of performance. The language designers are perfectly permitted to make that choice. If somebody wants to make another choice they can design their own language, or write their own data structures, or put in a bug report and hope to influence the language designers to change their minds. Why should strings be treated any differently? -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 16 01:25:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2013 05:25:10 GMT Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: <51440235$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Mar 2013 15:09:56 +1100, Chris Angelico wrote: > On Sat, Mar 16, 2013 at 2:56 PM, Mark Lawrence > wrote: >> On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: >>> >>> Chris Angelico wrote: >>> >>> >> Thomas and Chris, would the two of you be kind enough to explain to >> morons such as myself how all the ECMAScript stuff relates to Python's >> unicode as implemented via PEP 393 as you've lost me, easily done I >> know. > > Sure. Here's the brief version: It's all about how a string is exposed > to a script. > > * Python 3.2 Narrow gives you UTF-16. Non-BMP characters count twice. > * Python 3.2 Wide gives you UTF-32. Each character counts once. > * Python 3.3 gives you UTF-32, but will store it as compactly as > possible. > * ECMAScript specifies the semantics of Python 3.2 Narrow. And just for the record: Unicode actually doesn't define what a "character" is. Instead, it talks about "code points", but for our purposes we can gloss over the differences and pretend that they are almost the same thing, except where noted. Some code points represent characters, some represent non- characters, and some are currently unused. UTF-16 is a *variable length* storage mechanism that says each code point takes either two or four bytes. Since Unicode includes more code points than will fit in two bytes, UTF-16 includes a mechanism for dealing with the additional code points: * The first 65,536 code points are defined as the "Basic Multilingual Plane", or BMP. Each code point in the BMP is represented in UTF-16 by a 16-bit value. * The remaining 16 sets of 65,536 code points are defined as "Supplementary Multilingual Planes", or SMPs. Each code point in a SMP is represented by two 16 bit values, called a "surrogate pair". The "lead surrogate" will be in the range 0xD800...0xDBFF and the "trail surrogate" will be in the range 0xDC00...0xDFFF. The disadvantage here is that you can't tell how far into a string you need to go to get to (say) the 1000th character (code point). If all of the first 1000 code points are in the BMP, then you can jump directly to byte offset 2000. If all of them are in a SMP, then you can jump directly to byte offset 4000. But since you don't usually know how many SMP code points are in the string, you have to walk through the string: # Pseudo-code to return the code-point in string at index. offset = 0 # Offset in pairs of bytes. counter = 0 while offset < length of string counted in pairs of bytes: if string[offset] in 0xD800...0xDBFF: # Lead surrogate of a surrogate pair. if counter == index: return string[offset:offset+1] else: counter += 1 index += 2 # Skip the next pair. elif string[offset] in 0xDC00...0xDFFF: # Trail surrogate found outside of a surrogate pair. raise Error else: # BMP code point. if counter == index: return string[offset] else: counter += 1 index += 1 What a mess! Slow and annoying to get right. Not surprisingly, most implementations of UTF-16 don't do this, and Python is one of them. Instead, they assume that all code points take up the same space, and consequently they let you create *invalid Unicode strings* by splitting a surrogate pair: This is in Python 3.2 narrow build: py> s = chr(70000) py> len(s) 2 py> a = s[0] py> a == s False py> print(a) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'utf-8' codec can't encode character '\ud804' in position 0: surrogates not allowed Oops! We have created an invalid Unicode string. A wide build will fix this, because it uses UTF-32 instead. UTF-32 is a *fixed width* storage mechanism where every code point takes exactly four bytes. Since the entire Unicode range will fit in four bytes, that ensures that every code point is covered, and there is no need to walk the string every time you perform an indexing operation. But it means that if you're one of the 99.9% of users who mostly use characters in the BMP, your strings take twice as much space as necessary. If you only use Latin1 or ASCII, your strings take four times as much space as necessary. So a Python wide build uses more memory, but gets string processing right. Python 3.3 has the best of both worlds, fixing the invalid string processing and avoiding memory waste. One of the complications here is that often people conflate UTF-16 and UCS-2. It isn't entirely clear to me, but it seems that ECMAScript may be doing that. UCS-2 specifies that *all characters* are represented by *exactly* 16 bits (two bytes), and hence it is completely unable to deal with the Supplementary Multilingual Planes at all. If I have read the ECMAScript spec correctly, it *completely ignores* the issue of surrogate pairs, and so is underspecified. Instead it talks about normalised form, which is entirely unrelated. Normalisation relates to the idea that many characters can be represented in two or more ways. For example, the character "?" can be represented in at least two forms: Normalised form: U+00E4 LATIN SMALL LETTER A WITH DIAERESIS Canonical decomposition: U+0061 LATIN SMALL LETTER A + U+0308 COMBINING DIAERESIS So both of these two strings represent the same letter, even though the second uses two code points and the first only one: py> a = "\N{LATIN SMALL LETTER A WITH DIAERESIS}" py> b = "a\N{COMBINING DIAERESIS}" Arguably, they should print the same way too, although I think that will depend on how smart your terminal is, and/or on the font you use. But I digress. The ECMAScript spec carefully specifies that it makes no guarantees about normalisation, which is right and proper for a language, but it says nothing about surrogates, and that is very poor. So as I said, I suspect that ECMAScript is actually referring to UCS-2 when it mentions UTF-16. If I'm right, that's pretty lousy. -- Steven From roy at panix.com Sat Mar 16 09:29:01 2013 From: roy at panix.com (Roy Smith) Date: Sat, 16 Mar 2013 09:29:01 -0400 Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51440235$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51440235$0$29965$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > UTF-32 is a *fixed width* storage mechanism where every code point takes > exactly four bytes. Since the entire Unicode range will fit in four > bytes, that ensures that every code point is covered, and there is no > need to walk the string every time you perform an indexing operation. But > it means that if you're one of the 99.9% of users who mostly use > characters in the BMP, your strings take twice as much space as > necessary. If you only use Latin1 or ASCII, your strings take four times > as much space as necessary. I suspect that eventually, UTF-32 will win out. I'm not sure when "eventually" is, but maybe sometime in the next 10-20 years. When I was starting out, the computer industry had a variety of character encodings designed to take up less than 8 bits per character. Sixbit, Rad-50, BCD, and so on. Each of these added complexity and took away character set richness, but saved a few bits. At the time, memory was so expensive and so precious, it was worth it. Over the years, memory became cheaper, address spaces grew from 16 to 32 to 64 bits, and the pressure to use richer character sets kept increasing. So, now we're at the point where people are (mostly) using Unicode, but are still arguing about which encoding to use because the "best" complexity/space tradeoff isn't obvious. At some point in the future, memory will be so cheap, and so ubiquitous, that people will be wondering why us neanderthals bothered worrying about trying to save 16 bits per character. Of course, by then, we'll be migrating to Mongocode and arguing about UTF-64 :-) From rustompmody at gmail.com Sat Mar 16 12:39:29 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 16 Mar 2013 09:39:29 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51440235$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <70844d17-22bd-4394-86e2-d7ef3efc6cf7@ps9g2000pbb.googlegroups.com> On Mar 16, 6:29?pm, Roy Smith wrote: > In article <51440235$0$29965$c3e8da3$54964... at news.astraweb.com>, > ?Steven D'Aprano wrote: > > > UTF-32 is a *fixed width* storage mechanism where every code point takes > > exactly four bytes. Since the entire Unicode range will fit in four > > bytes, that ensures that every code point is covered, and there is no > > need to walk the string every time you perform an indexing operation. But > > it means that if you're one of the 99.9% of users who mostly use > > characters in the BMP, your strings take twice as much space as > > necessary. If you only use Latin1 or ASCII, your strings take four times > > as much space as necessary. > > I suspect that eventually, UTF-32 will win out. ?I'm not sure when > "eventually" is, but maybe sometime in the next 10-20 years. There is an article by Tim O'Reilly IIRC that talks of a certain prognostication that went wrong. [If someone knows this article please give me the link] The gist as I remember it was: First there were audio cassettes and LPs. Then came CDs with far better fidelity. As Moore's law went its relentless way, the audio industry puts its hope into formats that would double CD quality. Whereas the public went with mp3s, ie a distinctly lower quality format, because putting a thousand CDs into my pocket beats the pants of some super-duper hi- fi new CD. So while Moore's law takes its course, public demand and therefore big money and therefore new standards may go some other way, including reverse. I believe that there are many things about unicode that are less than satisfactory. Some are downright asinine like the 'prime-real-estate' devoted to the control characters and never used. In short, I am not betting on UTF-32. Of course the reverse side also is there: Some of the world's most un- optimal standards are also the most ubiquitous, like the qwerty keyboard. From roy at panix.com Sat Mar 16 14:00:32 2013 From: roy at panix.com (Roy Smith) Date: Sat, 16 Mar 2013 14:00:32 -0400 Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51440235$0$29965$c3e8da3$5496439d@news.astraweb.com> <70844d17-22bd-4394-86e2-d7ef3efc6cf7@ps9g2000pbb.googlegroups.com> Message-ID: In article <70844d17-22bd-4394-86e2-d7ef3efc6cf7 at ps9g2000pbb.googlegroups.com>, rusi wrote: > I believe that there are many things about unicode that are less than > satisfactory. Some are downright asinine like the 'prime-real-estate' > devoted to the control characters and never used. Ah, but in UTF-32, all real-estate is the same price :-) From wxjmfauth at gmail.com Sat Mar 16 16:42:06 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 16 Mar 2013 13:42:06 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51440235$0$29965$c3e8da3$5496439d@news.astraweb.com> <70844d17-22bd-4394-86e2-d7ef3efc6cf7@ps9g2000pbb.googlegroups.com> Message-ID: ------ utf-32 is already here. You are all most probably [*] using it without noticing it. How? By using OpenType fonts, without counting the text processing applications using them. Why? Because there is no other way to do it. [*] depending of the font, the internal table(s), eg "cmap" table, are in utf-16 or utf-32. jmf From rosuav at gmail.com Fri Mar 15 23:59:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Mar 2013 14:59:47 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <2202673.rtQqbKup0V@PointedEars.de> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: On Sat, Mar 16, 2013 at 1:44 PM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: >> The ECMAScript spec says that strings are stored and represented in >> UTF-16. > > No, it does not (which Edition?). It says in Edition 5.1: Okay, I was sloppy in my terminology. A language will seldom, if ever, specify the actual storage. But it does specify a representation (to the script) of UTF-16, and I seriously cannot imagine any reason for an implementation to store a string in any other way, given that string indexing is specifically based on UTF-16: > | The length of a > | String is the number of elements (i.e., 16-bit values) within it. > | > | [?] > | When a String contains actual textual data, each element is considered to > | be a single UTF-16 code unit. Whether or not this is the actual storage > | format of a String, the characters within a String are numbered by > | their initial code unit element position as though they were represented > | using UTF-16. So, yes, it could be stored in some other way, but in terms of what I was saying (comparing against Python 3.2 and 3.3), it's still a specification that doesn't allow for the change that Python did. If narrow builds are all you compare against (as jmf does), then Python 3.2 is exactly like ECMAScript, and Python 3.3 isn't. >> You can see the same thing in Javascript too. Here's a little demo I >> just knocked together: >> >> >> > value="Show">
    > > What an awful piece of code. Ehh, it's designed to be short, not beautiful. Got any serious criticisms of it? It demonstrates what I'm talking about without being a page of code. >> Give it an ASCII string > > You mean a string of Unicode characters that can also be represented with > the US-ASCII encoding. There are no "ASCII strings" in conforming > ECMAScript implementations. And a string of Unicode characters with code > points within the BMP will suffice already. You can get a string of ASCII characters and paste them into the entry field. They'll be turned into Unicode characters before the script sees them. But yes, okay, my terminology was a bit sloppy. >> and you'll see, as expected, one index (based on string indexing or >> charCodeAt, same thing) for each character. Same if it's all BMP. But put >> an astral character in and you'll see 00.00.d8.00/24 (oh wait, CIDR >> notation doesn't work in Unicode) come up. I raised this issue on the >> Google V8 list and on the ECMAScript list es-discuss at mozilla.org, and was >> basically told that since JavaScript has been buggy for so long, there's >> no chance of ever making it bug-free: >> >> https://mail.mozilla.org/pipermail/es-discuss/2012-December/027384.html > > You misunderstand, and I am not buying Rick's answer. The problem is not > that String values are defined as units of 16 bits. The problem is that the > length of a primitive String value in ECMAScript, and the position of a > character, is defined in terms of 16-bit units instead of characters. There > is no bug, because ECMAScript specifies that Unicode characters beyond the > Basic Multilingual Plane (BMP) need not be supported: So what you're saying is that an ES implementation is allowed to be even buggier than I described, and that's somehow a justification? > People have found ways to make this work in ECMAScript implementations. For > example, it is possible to scan a normalized string for lead surrogates: And it's possible to write a fully conforming Unicode handler in C, using char[] and relying on (say) UTF-8 encoding. That has nothing to do with the language actually providing facilities. > But yes, there should be native support for Unicode characters with code > points beyond the BMP, and evidently that does _not_ require a second > language; just a few tweaks to the algorithms. No, it requires either a complete change of the language, or the acceptance that O(1) operations can now become O(n) on the length of the string (if the string is left in UTF-16 but indexed in Unicode), or the creation of a new user-space data type (which then has to be converted any time it's given to any standard library function). >> Fortunately for Python, there are version numbers, and policies that >> permit bugs to actually get fixed. (Which is why, for instance, Debian >> Squeeze still ships Python 2.6 rather than upgrading to 2.7 - in case >> some script is broken by that change. > > Debian already ships Python 3.1 in Stable, disproving your argument. Separate branch. Debian stable ships one from each branch; Debian unstable does, too (2.7.3 and 3.2.3). Same argument applies to each, though - even Debian unstable hasn't yet introduced Python 3.3, in case it breaks stuff. Argument not disproved. >> Can't do that with web browsers.) > > Yes, you could. It has been done before. Not easily. Assuming you can't make one a perfect super/subset of the other (as with "use strict"), it needs to be done as a completely separate language. Now, maybe it's time the >>> >> value="Show">
    >> >> What an awful piece of code. > > Ehh, it's designed to be short, not beautiful. Got any serious > criticisms of it? Better not here, lest another ?moron? would complain. > It demonstrates what I'm talking about without being a page of code. It could have been written readable and efficient without that. >>> Give it an ASCII string >> >> You mean a string of Unicode characters that can also be represented with >> the US-ASCII encoding. There are no "ASCII strings" in conforming >> ECMAScript implementations. And a string of Unicode characters with code >> points within the BMP will suffice already. > > You can get a string of ASCII characters and paste them into the entry > field. Not likely these days, no. > They'll be turned into Unicode characters before the script > sees them. They will have become Windows-1252 or even Unicode characters long before. > But yes, okay, my terminology was a bit sloppy. It still is. >>> and you'll see, as expected, one index (based on string indexing or >>> charCodeAt, same thing) for each character. Same if it's all BMP. But >>> put an astral character in and you'll see 00.00.d8.00/24 (oh wait, CIDR >>> notation doesn't work in Unicode) come up. I raised this issue on the >>> Google V8 list and on the ECMAScript list es-discuss at mozilla.org, and >>> was basically told that since JavaScript has been buggy for so long, >>> there's no chance of ever making it bug-free: >>> >>> https://mail.mozilla.org/pipermail/es-discuss/2012-December/027384.html >> >> You misunderstand, and I am not buying Rick's answer. The problem is not >> that String values are defined as units of 16 bits. The problem is that >> the length of a primitive String value in ECMAScript, and the position of >> a character, is defined in terms of 16-bit units instead of characters. >> There is no bug, because ECMAScript specifies that Unicode characters >> beyond the Basic Multilingual Plane (BMP) need not be supported: > > So what you're saying is that an ES implementation is allowed to be > even buggier than I described, and that's somehow a justification? No, I am saying that you have no clue what you are talking about. >> But yes, there should be native support for Unicode characters with code >> points beyond the BMP, and evidently that does _not_ require a second >> language; just a few tweaks to the algorithms. > > No, it requires either a complete change of the language, [?] No, it does not. Get yourself informed. >>> Can't do that with web browsers.) >> >> Yes, you could. It has been done before. > > Not easily. You have still no clue what you are talking about. Get yourself informed at least about the (deprecated/obsolete) ?language? and the (standards- compliant) ?type? attribute of SCRIPT/?script? elements before you post on this again. -- PointedEars From rosuav at gmail.com Sat Mar 16 00:20:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Mar 2013 15:20:05 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <1435794.39vPVZTDCl@PointedEars.de> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <1435794.39vPVZTDCl@PointedEars.de> Message-ID: On Sat, Mar 16, 2013 at 3:12 PM, Thomas 'PointedEars' Lahn wrote: > You have still no clue what you are talking about. Fine. I'll shut up on the topic. Go ahead, the floor is yours, go and make whatever point you want to make. Clearly I have absolutely no idea about characters, strings, Unicode, or in fact anything to do with programming, as I obviously have no real-world experience with string manipulation in REXX, Perl, PHP, Python, Pike, JavaScript/ECMAScript/etc, or the "language" of bash+GNU utilities, and clearly I should just let the experts discuss this stuff. Have fun. ChrisA From rustompmody at gmail.com Sat Mar 16 01:21:21 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 22:21:21 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <1435794.39vPVZTDCl@PointedEars.de> Message-ID: On Mar 16, 9:12?am, Thomas 'PointedEars' Lahn wrote: > You have still no clue what you are talking about. ?Get yourself informed at > least about the (deprecated/obsolete) ?language? and the (standards- > compliant) ?type? attribute of SCRIPT/?script? elements before you post on > this again. > > -- > PointedEars An emotional 'PointedEars?' Now have I dropped into an alternate universe? From rustompmody at gmail.com Sat Mar 16 00:26:28 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 21:26:28 -0700 (PDT) Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: On Mar 16, 8:56?am, Mark Lawrence wrote: > On 16/03/2013 02:44, Thomas 'PointedEars' Lahn wrote: > > > Chris Angelico wrote: > > Thomas and Chris, would the two of you be kind enough to explain to > morons such as myself how all the ECMAScript stuff relates to Python's > unicode as implemented via PEP 393 as you've lost me, easily done I know. > > -- > Cheers. > > Mark Lawrence The unicode standard is language-agnostic. Unicode implementations exist withing a language x implementation x C- compiler implementation x ? -- Notice the gccs in Andriy's comparison. Do they signify? On Mar 15, 11:04 pm, Andriy Kornatskyy wrote: > $ python3.2 > Python 3.2.3 (default, Jun 25 2012, 22:55:05) > [GCC 4.6.3] on linux2 > $ python3.3 > Python 3.3.0 (default, Sep 29 2012, 15:35:49) > [GCC 4.7.1] on linux The number of actual python implementations is small -- 2.7, 3.1, 3.2, 3.3 -- at most enlarged with wides and narrows; The number of possible implementations is large (in principle infinite) -- a small example of a point in design-space that is not explored: eg There are 17 planes x 2^16 chars in a plane < 32 x 2^16 = 2^5 x 2^16 = 2^21 ie wide unicode (including the astral planes) can fit into 21 bits ie 3 wide-chars can fit into 64 bit slot rather than 2. Is this option worth considering? Ive no idea and I would wager that no one does until some trials are done So? Coming back to your question? Checking what other languages are doing speeds up the dream->design->implement->performance-check cycle From steve+comp.lang.python at pearwood.info Sat Mar 16 04:47:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2013 08:47:06 GMT Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> Message-ID: <51443189$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Mar 2013 21:26:28 -0700, rusi wrote: > The unicode standard is language-agnostic. Unicode implementations exist > withing a language x implementation x C- compiler implementation x ? -- > Notice the gccs in Andriy's comparison. Do they signify? They should not. Ideally, the behaviour of Python should be identical regardless of the compiler used to build the Python interpreter. In practice, this is not necessarily the case. One compiler might generate more efficient code than another. But aside from *performance*, the semantics of what Python does should be identical, except where noted as "implementation dependent". > The number of actual python implementations is small -- 2.7, 3.1, 3.2, > 3.3 -- at most enlarged with wides and narrows; The number of possible > implementations is large (in principle infinite) IronPython and Jython will, if I understand correctly, inherit their string implementations from .Net and Java. > -- a small example of a point in design-space that is not explored: eg > > There are 17 planes x 2^16 chars in a plane < 32 x 2^16 > = 2^5 x 2^16 > = 2^21 > > ie wide unicode (including the astral planes) can fit into 21 bits ie 3 > wide-chars can fit into 64 bit slot rather than 2. Is this option worth > considering? Ive no idea and I would wager that no one does until some > trials are done As I understand it, modern CPUs and memory chips are optimized for dealing with either two things: - single bytes; - even numbers of bytes, e.g. 16 bits, 32 bits, 64 bits, ... but not odd numbers of bytes, e.g. 24 bits, 40 bits, 72 bits, ... So while you might save memory by using "UTF-24" instead of UTF-32, it would probably be slower because you would have to grab three bytes at a time instead of four, and the hardware probably does not directly support that. -- Steven From nhodgson at iinet.net.au Sat Mar 16 18:00:32 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Sun, 17 Mar 2013 09:00:32 +1100 Subject: String performance regression from python 3.2 to 3.3 In-Reply-To: <51443189$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51443189$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano: > So while you might save memory by using "UTF-24" instead of UTF-32, it > would probably be slower because you would have to grab three bytes at a > time instead of four, and the hardware probably does not directly support > that. Low-level string manipulation often deals with blocks larger than an individual character for speed. Generally 32 or 64-bits at a time using the CPU or 128 or 256 using the vector unit. Then there may be entry/exit code to handle initial alignment to a block boundary and dealing with a smaller than block-size tail. For an example of this kind of thing, see find_max_char in python\Objects\stringlib\find_max_char.h which can examine a char* 32 or 64-bits at a time. 24-bit is likely to be a win in many circumstances due to decreased memory traffic. a 12-bit implementation may also be worthwhile as the low 0x1000 characters of Unicode contains Latin (with extensions), Greek, Cyrillic, Arabic, Hebrew, and most Indic scripts. Neil From roy at panix.com Sat Mar 16 18:10:01 2013 From: roy at panix.com (Roy Smith) Date: Sat, 16 Mar 2013 18:10:01 -0400 Subject: String performance regression from python 3.2 to 3.3 References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> <2992273.neLn1eVAPo@PointedEars.de> <2202673.rtQqbKup0V@PointedEars.de> <51443189$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Neil Hodgson wrote: > Low-level string manipulation often deals with blocks larger than > an individual character for speed. Generally 32 or 64-bits at a time > using the CPU or 128 or 256 using the vector unit. Then there may be > entry/exit code to handle initial alignment to a block boundary and > dealing with a smaller than block-size tail. Duff's Device! From rosuav at gmail.com Wed Mar 13 06:32:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2013 21:32:34 +1100 Subject: A reply for rusi (FSR) In-Reply-To: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> References: <23a42297-9262-4ace-87ad-138999b1ddd6@z3g2000vbg.googlegroups.com> Message-ID: n Wed, Mar 13, 2013 at 8:36 PM, jmfauth wrote: > #~ py323 py330 > > #~ test 1: 0.015357737412819 0.019290216142579 > ... > #~ test 35: 0.099810130396032 0.249129715085319 > But these numbers are utterly useless on their own. We need to know quite a bit more: 1) What are these tests doing? Preferably, share the exact code so that we can replicate your tests and see the same performance regression. 2) Full details on the platforms being tested. (Operating system? Word size (32/64)? Narrow/wide build of 3.2.3?) 3) Preferably, evidence that these tests are a fair sample of real-world use-cases. 4) Also preferable but not critical: Some indication of which operations have slowed down, which could then be used to open a ticket that someone can look into. ChrisA From bv4bv4bv4 at gmail.com Wed Mar 13 08:57:10 2013 From: bv4bv4bv4 at gmail.com (BV BV) Date: Wed, 13 Mar 2013 05:57:10 -0700 (PDT) Subject: Top Bible scholar leaves Christianity Message-ID: Top Bible scholar leaves Christianity This is a short interview with a renowned Bible scholar who talks about why he left Christianity. http://www.youtube.com/v/aYSDTXYmdvs?rel=0 thank you From olsr.kamal at gmail.com Wed Mar 13 11:06:18 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Wed, 13 Mar 2013 08:06:18 -0700 (PDT) Subject: =?ISO-8859-1?Q?how_to_get_the_coordonn=E9e_of_a_line_from_his_Id_in_?= =?ISO-8859-1?Q?canvas_python=3F=3F?= Message-ID: <868f42fd-d652-4b97-a50a-97903b37498c@googlegroups.com> how to get the coordonn?e of a line from his Id in canvas python?? From breamoreboy at yahoo.co.uk Wed Mar 13 11:46:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 13 Mar 2013 15:46:13 +0000 Subject: how to get the =?ISO-8859-1?Q?coordonn=E9e_of_a_line_?= =?ISO-8859-1?Q?from_his_Id_in_canvas_python=3F=3F?= In-Reply-To: <868f42fd-d652-4b97-a50a-97903b37498c@googlegroups.com> References: <868f42fd-d652-4b97-a50a-97903b37498c@googlegroups.com> Message-ID: On 13/03/2013 15:06, olsr.kamal at gmail.com wrote: > how to get the coordonn?e of a line from his Id in canvas python?? > Write some code after you've referred to the response you got when you posted the same question on 9th March. Please don't post to the mailing list and the gmane group as they're linked, select one or the other. -- Cheers. Mark Lawrence From olsr.kamal at gmail.com Wed Mar 13 11:06:29 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Wed, 13 Mar 2013 08:06:29 -0700 (PDT) Subject: =?ISO-8859-1?Q?how_to_get_the_coordonn=E9e_of_a_line_from_his_Id_in_?= =?ISO-8859-1?Q?canvas_python=3F=3F?= Message-ID: <356933b5-55fa-4e9e-89b2-517e8ad13dc1@googlegroups.com> how to get the coordonn?e of a line from his Id in canvas python?? From ch.valderanis at gmail.com Wed Mar 13 12:53:17 2013 From: ch.valderanis at gmail.com (ch.valderanis at gmail.com) Date: Wed, 13 Mar 2013 09:53:17 -0700 (PDT) Subject: IOError:[Errno 27] File too large Message-ID: Hi, Relatively newcomer here. The following code fails with the above error: python version used 2.6.2 under linux filestring='somestring' for files in glob.glob('*'): f2=open(files.replace('.xml','.sub'),'w') f2.write(filestring+files) f2.close() The glob commands returns around 10k files. I want to create 10k new files. the filename should have a different extension (sub instead of xml)and the content of the new file should be some filestring with the addition of the original filename. I am pretty sure that the files is less than 1kB. Is there another reason for the operation to fail? Any other comments,remarks welcomed. Thanks, Makis From steve+comp.lang.python at pearwood.info Wed Mar 13 13:32:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Mar 2013 17:32:59 GMT Subject: IOError:[Errno 27] File too large References: Message-ID: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Mar 2013 09:53:17 -0700, ch.valderanis wrote: > Hi, > > Relatively newcomer here. > The following code fails with the above error: python version used 2.6.2 > under linux Which part of the code fails? Please copy and paste the entire traceback, starting with the line "Traceback (most recent call last)" and ending with the complete error message. Which file does it fail on? > filestring='somestring' > for files in glob.glob('*'): > f2=open(files.replace('.xml','.sub'),'w') > f2.write(filestring+files) > f2.close() Some other comments: You use the name "files" to represent a single filename, rather than multiple files. That is misleading, a poor choice of name. "f2" is also a poor name. You try to change the file extension using string.replace method. This is risky, and will fail if some file has ".xml" in the filename apart from the file extension. Worse, if you have a file *without* ".xml", your code will over-write that file. Better to use the os.path.splitext function for this. Is filestring really a constant string like in the snippet above? Is there any change that it could be an enormous string? Re-writing your code snippet: import os filestring = 'somestring' for filename in glob.glob('*.xml'): newname = os.path.splitext(filename)[0] + '.sub' newfile = open(newname, 'w') newfile.write(filestring + filename) newfile.close() > I am pretty sure that the files is less than 1kB. "Pretty sure"? You need to be 100% certain. We can't tell you whether this is the case or not. > Is there another reason for the operation to fail? We don't know which operation has failed. That's why you need to show the complete traceback. -- Steven From ch.valderanis at gmail.com Wed Mar 13 18:35:19 2013 From: ch.valderanis at gmail.com (ch.valderanis at gmail.com) Date: Wed, 13 Mar 2013 15:35:19 -0700 (PDT) Subject: IOError:[Errno 27] File too large In-Reply-To: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dear Steven, Thank you very much both for your answer and of course your comments. They are taken into account. I found out that when I touch FILENAME.sub in the command line, I get the same error. So I guess it isn't a problem with the language but rather deeper. I will solve this first before I come back. Just for completeness: > Which part of the code fails? Please copy and paste the entire traceback, > starting with the line "Traceback (most recent call last)" and ending > with the complete error message. The code is corrected according to your advice: Here it the error: Traceback (most recent call last): File "createsubmitfiles.py", line 12, in newfile=open(newname,'w') IOError: [Errno 27] File too large: 'FILENAME.sub;' I have changed the actual filename reported by the traceback. FILENAME.xml does exist before the code is run FILENAME.sub is not created FILENAME has a length of 160 characters I do have space to write all the files in the directory > Is filestring really a constant string like in the snippet above? Is > there any change that it could be an enormous string? Yes. It is a constant string > > I am pretty sure that the files is less than 1kB. > "Pretty sure"? You need to be 100% certain. We can't tell you whether > this is the case or not. When I do an ls -l before I run the code and after the code has failed, all I see are files with size <1kB. Makis From steve+comp.lang.python at pearwood.info Wed Mar 13 22:46:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2013 02:46:16 GMT Subject: IOError:[Errno 27] File too large References: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514139f8$0$29965$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Mar 2013 15:35:19 -0700, ch.valderanis wrote: > Traceback (most recent call last): > File "createsubmitfiles.py", line 12, in > newfile=open(newname,'w') > IOError: [Errno 27] File too large: 'FILENAME.sub;' > > I have changed the actual filename reported by the traceback. > FILENAME.xml does exist before the code is run FILENAME.sub is not > created > FILENAME has a length of 160 characters I do have space to write all the > files in the directory You are not trying to create a file called "FILENAME.sub". You are trying to create a file called "FILENAME.sub;", notice the semi-colon. Taking a wild guess, I think that you are using a Samba share on a Linux server. A file "FILENAME.xml;" was accidentally creating on this share from the Linux filesystem layer, since Linux will allow you to use semicolons in file names. But samba enforces the same restrictions as Windows, so when you access the file system through sambda, it gives an error when you try to create a new file "FILENAME.sub;". This is a wild guess, and could be completely wrong. Please come back and tell us the solution when you have solved it. Good luck! -- Steven From ch.valderanis at gmail.com Thu Mar 14 16:12:03 2013 From: ch.valderanis at gmail.com (ch.valderanis at gmail.com) Date: Thu, 14 Mar 2013 13:12:03 -0700 (PDT) Subject: IOError:[Errno 27] File too large In-Reply-To: <514139f8$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> <514139f8$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6895f767-cfd9-4501-8368-25c3dbf8b643@googlegroups.com> > Taking a wild guess, I think that you are using a Samba share on a Linux > > server. A file "FILENAME.xml;" was accidentally creating on this share > > from the Linux filesystem layer, since Linux will allow you to use > > semicolons in file names. But samba enforces the same restrictions as > > Windows, so when you access the file system through sambda, it gives an > > error when you try to create a new file "FILENAME.sub;". > > This is a wild guess, and could be completely wrong. Please come back and > > tell us the solution when you have solved it. So, let me report the solution. All the files were in an afs filesystem. afs has a limit for the total length of the filenames per directory. for more details take a look at http://www.inf.ed.ac.uk/systems/AFS/topten.html#Tip13 In my case 10k files with ~160characters per filename were just hitting the limit. The error message is basically misleading. Makis From davea at davea.name Thu Mar 14 21:32:49 2013 From: davea at davea.name (Dave Angel) Date: Thu, 14 Mar 2013 21:32:49 -0400 Subject: IOError:[Errno 27] File too large In-Reply-To: <6895f767-cfd9-4501-8368-25c3dbf8b643@googlegroups.com> References: <5140b84b$0$29965$c3e8da3$5496439d@news.astraweb.com> <514139f8$0$29965$c3e8da3$5496439d@news.astraweb.com> <6895f767-cfd9-4501-8368-25c3dbf8b643@googlegroups.com> Message-ID: <51427A41.3010801@davea.name> On 03/14/2013 04:12 PM, ch.valderanis at gmail.com wrote: > >> Taking a wild guess, I think that you are using a Samba share on a Linux >> >> server. A file "FILENAME.xml;" was accidentally creating on this share >> >> from the Linux filesystem layer, since Linux will allow you to use >> >> semicolons in file names. But samba enforces the same restrictions as >> >> Windows, so when you access the file system through sambda, it gives an >> >> error when you try to create a new file "FILENAME.sub;". >> >> This is a wild guess, and could be completely wrong. Please come back and >> >> tell us the solution when you have solved it. > > So, let me report the solution. > All the files were in an afs filesystem. afs has a limit for the total length of the filenames per directory. for more details take a look at http://www.inf.ed.ac.uk/systems/AFS/topten.html#Tip13 > In my case 10k files with ~160characters per filename were just hitting the limit. The error message is basically misleading. > > Makis > Aha! So the file that was too large was the directory file. -- DaveA From info at egenix.com Wed Mar 13 14:32:36 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 13 Mar 2013 19:32:36 +0100 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.1.1.0.1.5 Message-ID: <5140C644.7000003@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.1.1.0.1.5 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.1.1.0.1.5.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included OpenSSL version to 1.0.1c. New in OpenSSL 1.0.1e since our last release for OpenSSL 1.0.1c --------------------------------------------------------------- OpenSSL 1.0.1e includes several important fixes: * OpenSSL security advisory: ?http://www.openssl.org/news/secadv_20130204.txt - also known as "Lucky 13" ?http://www.h-online.com/security/news/item/TLS-tripped-up-by-Lucky-13-1798423.html * OpenSSL security advisory: ?http://www.openssl.org/news/secadv_20130205.txt * corrected fix for CVE-2013-0169 in 1.0.1e: ?http://www.mail-archive.com/openssl-users at openssl.org/msg70100.html * fixes the SSL3_GET_RECORD:wrong version number problem: http://openssl.6102.n7.nabble.com/error-1408F10B-SSL-routines-SSL3-GET-RECORD-wrong-version-number-td22477.html as well as several other new features compared to 1.0.0: http://lwn.net/Articles/486426/ fixes vulnerabilities relative to 1.0.1c: http://openssl.org/news/vulnerabilities.html and includes a number of stability enhancements as well as extra protection against attacks: http://openssl.org/news/changelog.html New in the eGenix pyOpenSSL Distribution ---------------------------------------- * Changed the package version scheme to be PEP 386 compatible. The new scheme no longer contains underscores or patch level letters. * Added a CA root certificate bundle file ca-bundle.crt, which is created from the current Mozilla root CA certificate list. This allows verifying server certificates without having to rely on the system root CA certificate list. The bundle file will be updated with each new release of eGenix pyOpenSSL. We also make the file available as separate download. Please see the product page for details. * Added pyOpenSSL examples/ directory to the source distribution. * Added a new OpenSSL.ca_bundle module which provides easy to use access to the embedded ca-bundle.crt file. * Added new example https_client.py to the examples/ directory, which demonstrates setting up an SSL connection and using the new OpenSSL.ca_bundle module. * Windows x64 builds now have assembler code turned back on again, after a problem with OpenSSL 1.0.1c. As always, we provide binaries that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distribution, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 13 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From tinnews at isbd.co.uk Wed Mar 13 14:40:07 2013 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 13 Mar 2013 18:40:07 +0000 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? Message-ID: <7pt61a-am1.ln1@chris.zbmc.eu> I want to write a fairly trivial database driven application, it will basically present a few columns from a database, allow the user to add and/or edit rows, recalculate the values in one column and write the data back to the database. I want to show the data and allow editing of the data in a datagrid as being able to see adjacent/previous data will help a huge amount when entering data. So what toolkits are there out there for doing this sort of thing? A GUI toolkit would be lovely (allowing layout etc.) but isn't absolutely necessary. I'm a reasonably experienced programmer and know python quite well but I'm fairly much a beginner with event driven GUI stuff so I need a user friendly framework. -- Chris Green From walterhurry at lavabit.com Wed Mar 13 15:35:37 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Wed, 13 Mar 2013 19:35:37 +0000 (UTC) Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> Message-ID: On Wed, 13 Mar 2013 18:40:07 +0000, tinnews wrote: > I want to write a fairly trivial database driven application, it will > basically present a few columns from a database, allow the user to add > and/or edit rows, recalculate the values in one column and write the > data back to the database. > > I want to show the data and allow editing of the data in a datagrid as > being able to see adjacent/previous data will help a huge amount when > entering data. > > So what toolkits are there out there for doing this sort of thing? A > GUI toolkit would be lovely (allowing layout etc.) but isn't absolutely > necessary. > > I'm a reasonably experienced programmer and know python quite well but > I'm fairly much a beginner with event driven GUI stuff so I need a user > friendly framework. I use wxglade to generate the GUI source for wxpython, and then write my database code into the generated source for population of the grid and responding to events. I's very easy and painless. I mostly use Postgres (with Psycopg2) for the database, but sometimes sqlite. One big advantage for me is that I can go back to wxglade, change the layout, regenerate the source and my own code is untouched. From tinnews at isbd.co.uk Wed Mar 13 17:03:09 2013 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 13 Mar 2013 21:03:09 +0000 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> Message-ID: Walter Hurry wrote: > On Wed, 13 Mar 2013 18:40:07 +0000, tinnews wrote: > > > I want to write a fairly trivial database driven application, it will > > basically present a few columns from a database, allow the user to add > > and/or edit rows, recalculate the values in one column and write the > > data back to the database. > > > > I want to show the data and allow editing of the data in a datagrid as > > being able to see adjacent/previous data will help a huge amount when > > entering data. > > > > So what toolkits are there out there for doing this sort of thing? A > > GUI toolkit would be lovely (allowing layout etc.) but isn't absolutely > > necessary. > > > > I'm a reasonably experienced programmer and know python quite well but > > I'm fairly much a beginner with event driven GUI stuff so I need a user > > friendly framework. > > I use wxglade to generate the GUI source for wxpython, and then write my > database code into the generated source for population of the grid and > responding to events. > > I's very easy and painless. I mostly use Postgres (with Psycopg2) for the > database, but sometimes sqlite. > > One big advantage for me is that I can go back to wxglade, change the > layout, regenerate the source and my own code is untouched. Thanks, that sounds useful, I'll go and take a look at wxglade. I'll probably use sqlite as it's very lightweight and can happily just run on my desktop machine. -- Chris Green From ian.g.kelly at gmail.com Wed Mar 13 16:01:09 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Mar 2013 14:01:09 -0600 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? In-Reply-To: <7pt61a-am1.ln1@chris.zbmc.eu> References: <7pt61a-am1.ln1@chris.zbmc.eu> Message-ID: On Wed, Mar 13, 2013 at 12:40 PM, wrote: > I want to write a fairly trivial database driven application, it will > basically present a few columns from a database, allow the user to add > and/or edit rows, recalculate the values in one column and write the > data back to the database. > > I want to show the data and allow editing of the data in a datagrid as > being able to see adjacent/previous data will help a huge amount when > entering data. > > So what toolkits are there out there for doing this sort of thing? A > GUI toolkit would be lovely (allowing layout etc.) but isn't > absolutely necessary. > > I'm a reasonably experienced programmer and know python quite well > but I'm fairly much a beginner with event driven GUI stuff so I need > a user friendly framework. I've done something similar using wxPython and sqlalchemy. I use a wxGrid with a wxGridTableBase subclass that keeps a sqlalchemy ORM Session to access the database. The whole application is around 1300 lines of code but is probably more complex than what you need -- it currently has five different views built in and supports some fancier things like dropdown editing of foreign keys and many-to-many relations; cells with type-ahead; filtering and sorting. I don't know if that's the easiest way to do it, but I can at least report that it can be done. From feliphil at gmx.net Thu Mar 14 09:24:00 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 14 Mar 2013 14:24:00 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> Message-ID: <20130314142400.f3219c33fe828acfb17923e8@gmx.net> > I want to write a fairly trivial database driven application, it will > basically present a few columns from a database, allow the user to add > and/or edit rows, recalculate the values in one column and write the > data back to the database. > > I want to show the data and allow editing of the data in a datagrid as > being able to see adjacent/previous data will help a huge amount when > entering data. > > So what toolkits are there out there for doing this sort of thing? A > GUI toolkit would be lovely (allowing layout etc.) but isn't > absolutely necessary. > > I'm a reasonably experienced programmer and know python quite well > but I'm fairly much a beginner with event driven GUI stuff so I need > a user friendly framework. This is becoming an FAQ. The currently available (non-web) database application development frameworks for Python are: using wxPython: Dabo http://www.dabodev.com Defis http://sourceforge.net/projects/defis/ (Russian only) GNUe http://www.gnuenterprise.org/ using PyQt: Pypapi https://pypi.python.org/pypi/PyPaPi Camelot http://www.python-camelot.com/ Qtalchemy http://www.qtalchemy.org/ Thyme http://clocksoft.co.uk/downloads/ Kexi http://www.kexi-project.org/ using PyGTK: SQLkit http://sqlkit.argolinux.org/ Kiwi http://www.async.com.br/projects/kiwi/ Glom http://www.glom.org Openoffice Base http://www.openoffice.org/product/base.html Libreoffice Base http://www.libreoffice.org/features/base/ OpenERP http://www.openerp.org Tryton http://www.tryton.org Dabo (they're about to release 1.0 for Pycon), Pypapi, Camelot, SQLkit seem to be the most actively developed and best documented ones. OpenERP and Tryton are ERP systems that can also be used as frameworks for non-ERP custom applications. Apparently defunct: Pythoncard http://pythoncard.sourceforge.net/ Boa Constructor http://boa-constructor.sourceforge.net/ Knoda http://www.knoda.org/ Rekall ? Gemello http://abu.sourceforge.net/ Sincerely, Wolfgang From nulla.epistola at web.de Fri Mar 15 08:36:17 2013 From: nulla.epistola at web.de (Sibylle Koczian) Date: Fri, 15 Mar 2013 13:36:17 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? In-Reply-To: <20130314142400.f3219c33fe828acfb17923e8@gmx.net> References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> Message-ID: Am 14.03.2013 14:24, schrieb Wolfgang Keller: > This is becoming an FAQ. > > The currently available (non-web) database application development > frameworks for Python are: > > using wxPython: > Dabo http://www.dabodev.com > Defis http://sourceforge.net/projects/defis/ (Russian only) > GNUe http://www.gnuenterprise.org/ > > using PyQt: > Pypapi https://pypi.python.org/pypi/PyPaPi > Camelot http://www.python-camelot.com/ > Qtalchemy http://www.qtalchemy.org/ > Thyme http://clocksoft.co.uk/downloads/ > Kexi http://www.kexi-project.org/ > > using PyGTK: > SQLkit http://sqlkit.argolinux.org/ > Kiwi http://www.async.com.br/projects/kiwi/ > Glom http://www.glom.org > > Openoffice Base > http://www.openoffice.org/product/base.html > Libreoffice Base > http://www.libreoffice.org/features/base/ > > OpenERP http://www.openerp.org > Tryton http://www.tryton.org > > Dabo (they're about to release 1.0 for Pycon), Pypapi, Camelot, SQLkit > seem to be the most actively developed and best documented ones. > Very helpful collection, only one open question: which of them work with Python 3? Not Dabo, sadly, because wxPython doesn't. And not Camelot when I last looked (some weeks ago, though). Will look at Pypapi and SQLkit. Sibylle From breamoreboy at yahoo.co.uk Fri Mar 15 13:15:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 15 Mar 2013 17:15:26 +0000 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? In-Reply-To: References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> Message-ID: On 15/03/2013 12:36, Sibylle Koczian wrote: > > Very helpful collection, only one open question: which of them work with > Python 3? Not Dabo, sadly, because wxPython doesn't. And not Camelot > when I last looked (some weeks ago, though). > > Will look at Pypapi and SQLkit. > > Sibylle > Note that wxPython is getting there with its so called Phoenix see http://wxpython.org/Phoenix/snapshot-builds/ -- Cheers. Mark Lawrence From feliphil at gmx.net Sat Mar 16 16:30:07 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 16 Mar 2013 21:30:07 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> Message-ID: <20130316213007.0053c639600ca993c3a84b12@gmx.net> > Very helpful collection, only one open question: which of them work > with Python 3? No clue, sorry. Given how many other modules are not yet compatible with Python 3, I haven't investigated that yet. wxwidgets/wxPython already has *just* made the switch to Cocoa (with 2.9) when Carbon support was dropped by Apple, and I don't have a clue about the future of PyGTK (last update 2011, seems to have been replaced by PyGObject). > Will look at Pypapi and SQLkit. Frustrated with Dabo? Why? Sincerely, Wolfgang From nulla.epistola at web.de Sun Mar 17 07:06:09 2013 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 17 Mar 2013 12:06:09 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? In-Reply-To: <20130316213007.0053c639600ca993c3a84b12@gmx.net> References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> <20130316213007.0053c639600ca993c3a84b12@gmx.net> Message-ID: Am 16.03.2013 21:30, schrieb Wolfgang Keller: >> Will look at Pypapi and SQLkit. > Did look: SQLkit needs Python 2. Pypapi, from the link you gave: "The new release of PyPaPi is written in Java. You can find more info in the official site." On this official site - http://www.pypapi.org/ - I can't find anything at all about using PyPaPi with Python. > Frustrated with Dabo? Why? > First and main reason: just because for my needs it's the _only_ package that still forces me to keep a Python 2 installation. Second reason: too often things suddenly break that worked before. Writing to the Dabo list always helps, usually quite quickly, and that list really is one of the friendliest and most helpful I know, but still it's tiresome. Possibly I wouldn't care if English were my native language, but it isn't and so writing to the list is work and no fun. Sincerely Sibylle From rustompmody at gmail.com Sun Mar 17 11:50:41 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 17 Mar 2013 08:50:41 -0700 (PDT) Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> <20130316213007.0053c639600ca993c3a84b12@gmx.net> Message-ID: <756a4d4f-c072-4461-880c-b988954660f4@kk9g2000pbc.googlegroups.com> On Mar 17, 4:06?pm, Sibylle Koczian wrote: > Am 16.03.2013 21:30, schrieb Wolfgang Keller:>> Will look at Pypapi and SQLkit. > > Did look: SQLkit needs Python 2. Pypapi, from the link you gave: "The > new release of PyPaPi is written in Java. You can find more info in the > official site." On this official site -http://www.pypapi.org/- I can't > find anything at all about using PyPaPi with Python. > > > Frustrated with Dabo? Why? > > First and main reason: just because for my needs it's the _only_ package > that still forces me to keep a Python 2 installation. > > Second reason: too often things suddenly break that worked before. > Writing to the Dabo list always helps, usually quite quickly, and that > list really is one of the friendliest and most helpful I know, but still > it's tiresome. Possibly I wouldn't care if English were my native > language, but it isn't and so writing to the list is work and no fun. About your python I cant say, but your English looks/sounds as good as a native's. So dont waste your time getting that right; its good enough! From nulla.epistola at web.de Mon Mar 18 10:09:02 2013 From: nulla.epistola at web.de (Sibylle Koczian) Date: Mon, 18 Mar 2013 15:09:02 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? In-Reply-To: <756a4d4f-c072-4461-880c-b988954660f4@kk9g2000pbc.googlegroups.com> References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> <20130316213007.0053c639600ca993c3a84b12@gmx.net> <756a4d4f-c072-4461-880c-b988954660f4@kk9g2000pbc.googlegroups.com> Message-ID: Am 17.03.2013 16:50, schrieb rusi: > About your python I cant say, but your English looks/sounds as good as > a native's. > So dont waste your time getting that right; its good enough! Thank you. Flowers go to Dorothy L. Sayers, most of them. As far as Dabo is concerned, at the moment I just have to know how to spell "crash" ... Sibylle From feliphil at gmx.net Tue Mar 19 10:16:29 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 19 Mar 2013 15:16:29 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> <20130316213007.0053c639600ca993c3a84b12@gmx.net> <756a4d4f-c072-4461-880c-b988954660f4@kk9g2000pbc.googlegroups.com> Message-ID: <20130319151629.5290bb964d59e25568666d35@gmx.net> > As far as Dabo is concerned, at the moment I just have to know how to > spell "crash" ... Seems like someone is in desperate need of what they call "release management". X-( Sincerely, Wolfgang From feliphil at gmx.net Tue Mar 19 10:17:38 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 19 Mar 2013 15:17:38 +0100 Subject: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)? References: <7pt61a-am1.ln1@chris.zbmc.eu> <20130314142400.f3219c33fe828acfb17923e8@gmx.net> <20130316213007.0053c639600ca993c3a84b12@gmx.net> Message-ID: <20130319151738.92899441669e88dc841095cb@gmx.net> > >> Will look at Pypapi and SQLkit. > > > Did look: SQLkit needs Python 2. Personally I would be more concerned about the apparent end-of-life of PyGTK. > Pypapi, from the link you gave: "The new release of PyPaPi is written > in Java. You can find more info in the official site." On this > official site - http://www.pypapi.org/ - I can't find anything at all > about using PyPaPi with Python. Unfortunately I have lost the URL for the documentation (tutorial etc.) on the Python pages at www.pypapi.org. I'm afraid you'll have to ask the author. Pypapi, which is in production use in version 0.8, had been re-implented in Java for some reason (paying customer?), and the design changes have been back-ported to the Python implementation, yielding the version 0.9, which is considered beta. I liked the approach of this version, because it essentially only requires you to write the declarative Sqlalchemy model, layout the forms in Qt Designer and that's it. At about as little hand coding as possible. If you don't mind source code of an example application being essentially the only documentation, you can also look at Qtalchemy. Sincerely, Wolfgang From kalvinmanual at gmail.com Wed Mar 13 17:11:24 2013 From: kalvinmanual at gmail.com (kalvinmanual at gmail.com) Date: Wed, 13 Mar 2013 14:11:24 -0700 (PDT) Subject: Concepts and Applications of Finite Element Analysis (4th Ed., Cook, Malkus, Plesha & Witt) Message-ID: <28f1a1fa-d899-4666-86c7-c33ff3ad28f2@googlegroups.com> I have solutions manuals to all problems and exercises in these textbooks. To get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com and let me know its title, author and edition. Please this service is NOT free. SOLUTIONS MANUAL TO A First Course in Differential Equations (7th ed.) Zill & Diferential Equations (5th ed.)Zill & Cullen SOLUTIONS MANUAL TO 2500 Solved Problems in Fluid Mechanics & Hydraulics Schaums by Evett, cheng Liu SOLUTIONS MANUAL TO A Course in Game Theory by Osborne, Rubinstein SOLUTIONS MANUAL TO A Course in Modern Mathematical Physics by Peter Szekeres SOLUTIONS MANUAL TO A Course in Ordinary Differential Equations by Swift, Wirkus SOLUTIONS MANUAL TO A First Course in Abstract Algebra (7th Ed., John B. Fraleigh) SOLUTIONS MANUAL TO A First Course in Differential Equations - The Classic Fifth Edition By Zill, Dennis G SOLUTIONS MANUAL TO A First Course in Differential Equations, 9th Ed by Dennis G. Zill SOLUTIONS MANUAL TO A First Course In Probability 7th Edition by Sheldon M. Ross SOLUTIONS MANUAL TO A First Course in Probability Theory, 6th edition, by S. Ross. SOLUTIONS MANUAL TO A First Course in String Theory, 2004, Barton Zwiebach SOLUTIONS MANUAL TO A First Course in the Finite Element Method, 4th Edition logan SOLUTIONS MANUAL TO A Practical Introduction to Data Structures and Algorithm Analysis 2Ed by Shaffer SOLUTIONS MANUAL TO A Quantum Approach to Condensed Matter Physics (Philip L. Taylor & Olle Heinonen) SOLUTIONS MANUAL TO A Short Course in General Relativity 2e by J. Foster and J. D. Nightingale SOLUTIONS MANUAL TO A Short Introduction to Quantum Information and Quantum Computation by Michel Le Bellac SOLUTIONS MANUAL TO A Transition to Advanced Mathematics 5th E by Smith, Eggen, Andre SOLUTIONS MANUAL TO Accounting Principles 8e by Kieso, Kimmel SOLUTIONS MANUAL TO Accounting principles 8th Ed by Weygandt SOLUTIONS MANUAL TO Accounting, 23 Ed by Carl S. Warren, James M. Reeve, Jonathan Duchac SOLUTIONS MANUAL TO Accounting,8th Ed by Horngren,Harrison, Oliver SOLUTIONS MANUAL TO Adaptive Control, 2nd. Ed., by Astrom, Wittenmark SOLUTIONS MANUAL TO Adaptive Filter Theory (4th Ed., Simon Haykin) SOLUTIONS MANUAL TO Advanced Accounting 10E international ED by Beams , Clement, Anthony, Lowensohn SOLUTIONS MANUAL TO Advanced accounting 9th Ed by Hoyle, Schaefer SOLUTIONS MANUAL TO Advanced Calculus Gerald B. Folland SOLUTIONS MANUAL TO Advanced Digital Design with the Verilog HDL by Michael D. Ciletti SOLUTIONS MANUAL TO Advanced Dynamics (Greenwood) SOLUTIONS MANUAL TO Advanced Engineering Electromagnetics by Constantine A. Balanis SOLUTIONS MANUAL TO Advanced Engineering Mathematics 3rd ed zill SOLUTIONS MANUAL TO Advanced Engineering Mathematics 8Ed Erwin Kreyszig SOLUTIONS MANUAL TO Advanced Engineering Mathematics by Erwin Kreyszig, 9th ed SOLUTIONS MANUAL TO Advanced Engineering Mathematics, 6th Edition by Peter V. O'Neil SOLUTIONS MANUAL TO Advanced Engineering Mathematics,2E, by Zill, Cullen SOLUTIONS MANUAL TO Advanced Engineering Thermodynamics, 3rd Edition by Adrian Bejan SOLUTIONS MANUAL TO Advanced Financial Accounting by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 5 Ed by Baker SOLUTIONS MANUAL TO Advanced Financial Accounting 8th Ed by Baker SOLUTIONS MANUAL TO Advanced Industrial Economics by Martin SOLUTIONS MANUAL TO Advanced Industrial Economics, 2nd ED Stephen Martin SOLUTIONS MANUAL TO Advanced Macroeconomics 2nd edition by David Romer SOLUTIONS MANUAL TO Advanced Macroeconomics, by David Romer SOLUTIONS MANUAL TO Advanced Mechanics of Materials 6th ed by Boresi, Schmidt SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 3rd Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics 4th Ed Glyn James SOLUTIONS MANUAL TO Advanced Modern Engineering Mathematics, 3rd Ed., by G. James SOLUTIONS MANUAL TO Advanced Organic Chemistry Part A- Structure and Mechanisms 5th E by Carey, Sundberg SOLUTIONS MANUAL TO Aircraft Structures for Engineering Students (4th Ed., T.H.G. Megson) SOLUTIONS MANUAL TO Algebra & Trigonometry and Precalculus, 3rd Ed By Beecher, Penna, Bittinger SOLUTIONS MANUAL TO Algebra Baldor SOLUTIONS MANUAL TO Algebra-By Thomas W. Hungerford SOLUTIONS MANUAL TO Algorithm Design (Jon Kleinberg & ??va Tardos) SOLUTIONS MANUAL TO An Interactive Introduction to Mathematical Analysis 2nd E (Jonathan Lewin) SOLUTIONS MANUAL TO An Introduction To Analysis 4th Ed by William Wade SOLUTIONS MANUAL TO An Introduction to Database Systems (8th Ed., C.J. Date) SOLUTIONS MANUAL TO An Introduction to Economic Dynamics by Ronald Shone SOLUTIONS MANUAL TO An Introduction to Modern Astrophysics (2nd Ed., Bradley W. Carroll & Dale A. Ostlie) SOLUTIONS MANUAL TO An Introduction to Numerical Analysis By Endre S?li,David F. Mayers SOLUTIONS MANUAL TO An Introduction to Ordinary Differential Equations (James C. Robinson) SOLUTIONS MANUAL TO An Introduction to Signals and Systems by John Stuller SOLUTIONS MANUAL TO An Introduction to Stochastic Modeling 3rd Ed by Taylor, Karlin SOLUTIONS MANUAL TO An Introduction to the Finite Element Method (3rd Ed., J. N. Reddy) SOLUTIONS MANUAL TO An Introduction to Thermal Physics by Schroeder, Daniel V SOLUTIONS MANUAL TO An Introduction to Thermodynamics and Statistical Mechanics (2nd Ed, Keith Stowe) SOLUTIONS MANUAL TO An Introduction to Wavelets through Linear Algebra by Frazier SOLUTIONS MANUAL TO Analog Integrated Circuit Design, by Johns, Martin SOLUTIONS MANUAL TO Analysis and Design of Analog Integrated Circuits (4th Edition) by Gray , Lewis , Meyer SOLUTIONS MANUAL TO Analysis With an Introduction to Proof 4th E by Lay SOLUTIONS MANUAL TO Analytical Chemistry, Higson SOLUTIONS MANUAL TO Analytical Mechanics 7E by Grant R. Fowles, George L. Cassiday SOLUTIONS MANUAL TO Antenna Theory 2nd edition by Balanis SOLUTIONS MANUAL TO Antenna Theory and Design, 2nd Ed Vol.1 by Stutzman, Thiele SOLUTIONS MANUAL TO Antennas for All Applications (3rd Ed., John Kraus & Ronald Marhefka) SOLUTIONS MANUAL TO Applied Calculus by Hallett,Gleason, Lock, Flath SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 7 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Calculus for the Managerial, Life, and Social Sciences, 8 E, by Soo T. Tan SOLUTIONS MANUAL TO Applied Econometric Time Series, 2nd Edition by Enders SOLUTIONS MANUAL TO Applied Finite Element Analysis 2ed, by LJ SEGERLIND SOLUTIONS MANUAL TO Applied Fluid Mechanics (6th Ed., Mott) SOLUTIONS MANUAL TO Applied Linear Regression 3rd Ed by Sanford Weisberg SOLUTIONS MANUAL TO Applied Numerical Analysis, 7th Edition, by Gerald, Wheatley SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists 2nd E by Chapra SOLUTIONS MANUAL TO Applied Numerical Methods with MATLAB for Engineers and Scientists( Steven C. Chapra) SOLUTIONS MANUAL TO Applied Partial Differential Equations (4th Ed., Haberman) SOLUTIONS MANUAL TO Applied Partial Differential Equations by J. David Logan SOLUTIONS MANUAL TO Applied Probability Models with Optimization Applications By Sheldon M. Ross SOLUTIONS MANUAL TO Applied Quantum Mechanics ( A. F. J. Levi ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers ( 2nd Ed., Douglas Montgomery & George Runger ) SOLUTIONS MANUAL TO Applied Statistics and Probability for Engineers (3rd Ed., Douglas Montgomery & George Runger) SOLUTIONS MANUAL TO Applied Strength of Materials (4th Ed., Mott) SOLUTIONS MANUAL TO Applied Strength of Materials (5th Ed., Mott) SOLUTIONS MANUAL TO Applying Maths in the Chemical and Biomolecular Sciences, Beddard SOLUTIONS MANUAL TO Artificial Intelligence A Modern Approach 2e by Russell, Norvig SOLUTIONS MANUAL TO Artificial Neural Networks by B. Yegnanarayana and S. Ramesh SOLUTIONS MANUAL TO Assembly Language for Intel-Based Computers ( 3rd Edition ) by Kip R. Irvine SOLUTIONS MANUAL TO Auditing and Assurance Services- An Integrated Approach 12E by Arens SOLUTIONS MANUAL TO Auditing and Assurance Services, 12th edition, Alvin A Arens, Randal J Elder, Mark Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 13 ed by Arens, Elder, Beasley SOLUTIONS MANUAL TO Auditing and Assurance Services, 2nd Ed by Louwers SOLUTIONS MANUAL TO Automatic Control Systems 9 Ed by Kuo, Golnaraghi SOLUTIONS MANUAL TO Automatic Control Systems, 8E, by Kuo, Golnaraghi SOLUTIONS MANUAL TO Basic Econometrics 4 ed by Damodar N. Gujarati SOLUTIONS MANUAL TO Basic Electrical Engineering By Nagrath, D P Kothari SOLUTIONS MANUAL TO Basic Electromagnetics with Applications by Nannapaneni Narayana Rao SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 7th Ed by David Irwin SOLUTIONS MANUAL TO Basic Engineering Circuit Analysis, 8th Edition by J. David Irwin, R. Mark Nelms SOLUTIONS MANUAL TO Basic Heat and Mass Transfer by A. F. Mills SOLUTIONS MANUAL TO Basic Principles and Calculations in Chemical engineering 7th Edition by David M. Himmelblau, James B. Riggs SOLUTIONS MANUAL TO Basic Probability Theory by Robert B. Ash SOLUTIONS MANUAL TO Bayesian Core by Christian P. Robert and Jean-Michel Marin SOLUTIONS MANUAL TO Bioprocess Engineering Principles (Pauline M. Doran) SOLUTIONS MANUAL TO Business Statistics - Decision Making 7th E by David F. Groebner SOLUTIONS MANUAL TO C++ for Computer Science and Engineering by Vic Broquard SOLUTIONS MANUAL TO C++ How to Program 3rd edition - Deitel SOLUTIONS MANUAL TO CALCULO VECTORIAL 7th Ed. by Louis Leithold SOLUTIONS MANUAL TO Calculus 8th Edition by Varberg, Purcell, Rigdon SOLUTIONS MANUAL TO Calculus - Early Transcendentals, 6th E, by Anton, Bivens, Davis SOLUTIONS MANUAL TO Calculus - Early Transcendentals, 7E, by Anton, Bivens, Davis SOLUTIONS MANUAL TO Calculus - Late Transcendentals Single Variable, 8th Ed by Anton, Bivens, Davis SOLUTIONS MANUAL TO Calculus ( 9th Ed., Dale Varberg, Edwin Purcell & Steve Rigdon) SOLUTIONS MANUAL TO Calculus 2nd edition-M. Spivak SOLUTIONS MANUAL TO Calculus 3rd Ed by Michael Spivak SOLUTIONS MANUAL TO Calculus 6th ed by James Stewart SOLUTIONS MANUAL TO Calculus 8th Ed by Ron Larson, Robert P. Hostetler, Bruce H. Edwards SOLUTIONS MANUAL TO Calculus A Complete Course 6th Edition by by R.A. Adams SOLUTIONS MANUAL TO CALCULUS An Intuitive and Physical Approach 2nd ed by Morris Kline SOLUTIONS MANUAL TO Calculus and its Applications (11th Ed., Larry J Goldstein, Schneider, Lay & Asmar) SOLUTIONS MANUAL TO Calculus by Gilbert Strang SOLUTIONS MANUAL TO Calculus early transcendentals 8th Ed, by Anton Bivens Davis SOLUTIONS MANUAL TO Calculus Early Transcendentals, 5th Edition, JAMES STEWART SOLUTIONS MANUAL TO Calculus George Thomas 10th ed Vol 1 SOLUTIONS MANUAL TO Calculus of Variations MA 4311 LECTURE NOTES ( Russak ) SOLUTIONS MANUAL TO Calculus On Manifolds by Spivak SOLUTIONS MANUAL TO Calculus One & Several Variables 8e by S Salas SOLUTIONS MANUAL TO Calculus Vol 2 by Apostol SOLUTIONS MANUAL TO CALCULUS VOL.1 , 2nd edition by Tom M. Apostol SOLUTIONS MANUAL TO Calculus Volume 1 by J. Marsden, A. Weinstein SOLUTIONS MANUAL TO Calculus With Analytic Geometry 4th ( Henry Edwards & David E. Penney) SOLUTIONS MANUAL TO Calculus with Applications 8 Edition by Lial, Greenwell, Ritchey SOLUTIONS MANUAL TO Calculus, 4th edition stewart SOLUTIONS MANUAL TO Calculus, An Applied Approach, 7E, by Larson SOLUTIONS MANUAL TO Calculus, Early Transcendentals 7 Ed by Edwards & Penney SOLUTIONS MANUAL TO Calculus, Single and Multivariable, 4E.,Vol 1& Vol 2 by Hughes-Hallett,McCallum SOLUTIONS MANUAL TO Calculus, Single Variable, 3E by Hughes-Hallett,McCallum SOLUTIONS MANUAL TO Chemical and Engineering Thermodynamics 3Ed by Stanley I. Sandler SOLUTIONS MANUAL TO Chemical Engineering Design (Coulson & Richardson's Chemical Engineering - Volume 6) - (4th Ed., Sinnott) SOLUTIONS MANUAL TO Chemical Engineering Volume 1, 6th Edition, by Richardson, Coulson,Backhurst, Harker SOLUTIONS MANUAL TO CHEMICAL, BIOCHEMICAL, AND ENGINEERING THERMODYNAMICS, 4TH ED BY SANDLER SOLUTIONS MANUAL TO Chemistry 2nd Edition Vol.1 by Julia Burdge SOLUTIONS MANUAL TO Chemistry, 10th Ed by Chang SOLUTIONS MANUAL TO Chip Design for Submicron VLSI CMOS Layout and Simulation, John P. Uyemura SOLUTIONS MANUAL TO Cisco Technical Solution Series IP Telephony Solution Guide Version 2.0 SOLUTIONS MANUAL TO Classical Dynamics of Particles and Systems, 5th Ed, by Marion, Thornton SOLUTIONS MANUAL TO Classical Dynamics, A Contemporary Approach (Jorge V. Jose) SOLUTIONS MANUAL TO Classical Electrodynamics 2nd edition by John David Jackson SOLUTIONS MANUAL TO Classical Electrodynamics by John David Jackson SOLUTIONS MANUAL TO Classical Electrodynamics by Kasper Van Wijk SOLUTIONS MANUAL TO Classical Mechanics (Douglas Gregory) SOLUTIONS MANUAL TO Classical Mechanics 2nd Ed by Goldstein SOLUTIONS MANUAL TO CMOS Analog Circuit Design, 2ed by Phillip E. Allen, Douglas R. Holberg SOLUTIONS MANUAL TO CMOS- Circuit Design, Layout, and Simulation, Revised 2nd Ed by R. Jacob Baker SOLUTIONS MANUAL TO Cmos Digital Integrated Circuits , Sung-Mo Kang,Yusuf Leblebici SOLUTIONS MANUAL TO CMOS Mixed-Signal Circuit Design, 2nd Ed by R. Jacob Baker SOLUTIONS MANUAL TO CMOS VLSI Design Circuit & Design Perspective 3rd Ed by Haris & West SOLUTIONS MANUAL TO College Algebra 8th Ed by Michael Sullivan SOLUTIONS MANUAL TO COLLEGE ALGEBRA AND TRIGONOMETRY 6th E by Aufmann, Barker, Verity SOLUTIONS MANUAL TO College Geometry A Discovery Approach 2nd E by David Kay SOLUTIONS MANUAL TO College Physics 8 ED by Serway, Faughn, Vuille SOLUTIONS MANUAL TO College Physics 9 ED by Serway, Faughn, Vuille SOLUTIONS MANUAL TO Communication Networks, 2e, Alberto Leon-Garcia, Indra Widjaja SOLUTIONS MANUAL TO Communication Systems (4th Ed., Simon Haykin) SOLUTIONS MANUAL TO Communication Systems An Introduction to Signals and Noise in Electrical Communication, 4E, A. Bruce Carlson SOLUTIONS MANUAL TO Communication Systems Engineering (2nd Ed., John G. Proakis & Masoud Salehi) SOLUTIONS MANUAL TO Complex Variables and Applications 7 ed by JW Brown RV Churchill SOLUTIONS MANUAL TO Complex Variables with Applications, 3rd ED by David A. Wunsch SOLUTIONS MANUAL TO COMPUTATIONAL FINANCE A SCIENTIFIC PERSPECTIVE MILEN KASSABOV,CORNELIS A. LOS SOLUTIONS MANUAL TO Computational Techniques for Fluid Dynamics Srinivas, K., Fletcher, C.A.J. SOLUTIONS MANUAL TO Computer Architecture - A Quantitative Approach, 4th Ed by Hennessy, Patterson SOLUTIONS MANUAL TO Computer Architecture Pipelined & Parallel Processor Design by Michael J Flynn SOLUTIONS MANUAL TO Computer Graphics Using OpenGL 3rd E by Francis S Hill, Jr. & Stephen M Kelley SOLUTIONS MANUAL TO Computer Networking A Top-Down Approach Featuring the Internet, 3E Kurose,Ross SOLUTIONS MANUAL TO Computer Networking: A Top-Down Approach (4th Ed., James F. Kurose & Keith W. Ross) SOLUTIONS MANUAL TO Computer Networks - A Systems Approach 3 ed by Peterson Davie SOLUTIONS MANUAL TO Computer Networks - A Systems Approach 4 ed by Peterson Davie SOLUTIONS MANUAL TO Computer Networks A Systems Approach, 2nd Edition, Larry Peterson, Bruce Davie SOLUTIONS MANUAL TO Computer Networks, 4th Ed., by Andrew S. Tanenbaum SOLUTIONS MANUAL TO Computer Organization 3rd Edition by Carl Hamacher , Zvonoko Vranesic ,Safwat Zaky SOLUTIONS MANUAL TO Computer Organization and Architecture: Designing for Performance (7th Ed., William Stallings) SOLUTIONS MANUAL TO Computer Organization and Design The Hardware Software Interface 4 ed by David A Patterson SOLUTIONS MANUAL TO Computer Organization and Design The Hardware Software Interface, 3rd edition by David A Patterson and John L Hennessy SOLUTIONS MANUAL TO Computer Science Illuminated 4th ed by Nell Dale, John Lewis SOLUTIONS MANUAL TO Computer system architecture 3rd Ed Morris Mano SOLUTIONS MANUAL TO Computer Systems Organization and Architecture by John D. Carpinelli SOLUTIONS MANUAL TO Computer Vision A Modern Approach by Forsyth, Ponce SOLUTIONS MANUAL TO Computer-Controlled Systems 3rd ED by Astrom, Wittenmark SOLUTIONS MANUAL TO Concepts and Applications of Finite Element Analysis (4th Ed., Cook, Malkus, Plesha & Witt) SOLUTIONS MANUAL TO Concepts in Thermal Physics 2nd Ed by Blundell SOLUTIONS MANUAL TO Concepts of Physics (Volume 1 & 2) by H.C. Verma SOLUTIONS MANUAL TO Concepts of Programming Languages 7th ED by Sebesta SOLUTIONS MANUAL TO Construction Surveying and Layout 2ed by Crawford SOLUTIONS MANUAL TO Contemporary Engineering Economics (4th Ed., Chan Park) SOLUTIONS MANUAL TO Contemporary Engineering Economics 5th Ed by Chan S. Park SOLUTIONS MANUAL TO Continuum Electromechanics by James R. Melcher SOLUTIONS MANUAL TO Control Systems Engineering, 4E, by Norman Nise SOLUTIONS MANUAL TO Control Systems Principles and Design 2e by M. Gopal SOLUTIONS MANUAL TO Corporate Finance & MyFinanceLab Student Access Code Card, Global 2 Ed by Berk, DeMarzo SOLUTIONS MANUAL TO Corporate Finance 8th edition by Ross SOLUTIONS MANUAL TO Corporate Finance 9th edition by Ross SOLUTIONS MANUAL TO Corporate Finance The Core plus MyFinanceLab Student Access Kit (Jonathan Berk & Peter DeMarzo) SOLUTIONS MANUAL TO Corporate Finance, 7E, by Ross SOLUTIONS MANUAL TO Corporations, Partnerships, Estates and Trusts ( 2011 ) by Hoffman, Maloney SOLUTIONS MANUAL TO COST ACCOUNTING - Creating Value for Management 5th E by MICHAEL MAHER SOLUTIONS MANUAL TO Cost Accounting-A Managerial Emphasis 13th Ed by Charles Horngren SOLUTIONS MANUAL TO Cryptography and Network Security (4th Ed., William Stallings) SOLUTIONS MANUAL TO Data & Computer Communication, 7th Ed, by William Stallings SOLUTIONS MANUAL TO Data Communications and Networking by Behroz Forouzan SOLUTIONS MANUAL TO Data Communications Networking 4th Ed by Behrouz Forouzan SOLUTIONS MANUAL TO Data Structures with Java by John R. Hubbard, Anita Huray SOLUTIONS MANUAL TO Database Management Systems, 3rd Ed., by Ramakrishnan, Gehrke SOLUTIONS MANUAL TO Database System Concepts 4th ED by Silberschatz , Korth , Sudarshan SOLUTIONS MANUAL TO Database System Concepts 5th ED by Silberschatz, Korth, Sudarshan SOLUTIONS MANUAL TO Database Systems An Application-Oriented Approach (introductory Version ) by Michael Kifer, Arthur Bernstein, Philip M.Lewis, Prabin K. Panigrahi SOLUTIONS MANUAL TO Design Analysis in Rock Mechanics by William G. Pariseau SOLUTIONS MANUAL TO Design and Analysis of Experiments, 6E, by Montgomery SOLUTIONS MANUAL TO Design of Analog CMOS Integrated Circuits by Razavi SOLUTIONS MANUAL TO Design of Analog CMOS Integrated Circuits, 2 Edition, by Razavi Douglas C. Montgomery SOLUTIONS MANUAL TO Design of Fluid Thermal Systems, 2nd Edition janna SOLUTIONS MANUAL TO Design of Machinery (3rd Ed., Norton) SOLUTIONS MANUAL TO Design of machinery 4th ed by Norton SOLUTIONS MANUAL TO Design of Reinforced Concrete, 8th Ed by McCormac, Brown SOLUTIONS MANUAL TO Design with Operational Amplifiers and Analog Integrated Circuits (3rd Ed., Sergio Franco) SOLUTIONS MANUAL TO Device Electronics for Integrated Circuits 3rd Edition by muller kamins SOLUTIONS MANUAL TO Differential Equations & Linear Algebra 3rd ed by C. Henry Edwards & David E. Penney SOLUTIONS MANUAL TO Differential Equations and Boundary Value Problems - Computing and Modeling 4th Ed by Edwards, Penney SOLUTIONS MANUAL TO Differential Equations and Linear Algebra ( 2nd Ed., Jerry Farlow, Hall, McDill & West) SOLUTIONS MANUAL TO Differential Equations and Linear Algebra ( C. Henry Edwards & David E. Penney) SOLUTIONS MANUAL TO Differential Equations and Linear Algebra 3e by Stephen W Goode SOLUTIONS MANUAL TO Differential Equations with Boundary Value Problems (2e, John Polking, Al Boggess & Arnold) SOLUTIONS MANUAL TO Digital & Analog Communication Systems (7th Ed., Leon W. Couch) SOLUTIONS MANUAL TO Digital COMMUNICATION 3rd edition by John R. Barry, Edward A. Lee, David G. Messerschmitt SOLUTIONS MANUAL TO Digital Communications Fundamentals and Applications 2e Bernard Sklar SOLUTIONS MANUAL TO Digital Communications, 4E, by Proakis SOLUTIONS MANUAL TO Digital Control & State Variable Methods 2nd Ed by Madan Gopal SOLUTIONS MANUAL TO Digital Design (4th Ed., M. Morris Mano & Michael D. Ciletti) SOLUTIONS MANUAL TO Digital Design: Principles and Practices Package (4th Ed., John F. Wakerly) SOLUTIONS MANUAL TO Digital Fundamentals ( 10th Ed, Thomas L. Floyd ) SOLUTIONS MANUAL TO Digital Fundamentals ( 9th Ed., Thomas L. Floyd) SOLUTIONS MANUAL TO Digital Image Processing, 2e, by Gonzalez, Woods SOLUTIONS MANUAL TO Digital Integrated Circuits, 2nd Ed., by Rabaey SOLUTIONS MANUAL TO Digital Logic Design by Mano SOLUTIONS MANUAL TO Digital Signal Processing - A Modern Introduction, by Ashok Ambardar SOLUTIONS MANUAL TO Digital Signal Processing Principles, Algorithms and Applications, 3rd Edition by John G. Proakis SOLUTIONS MANUAL TO Digital Signal Processing 4th Ed by Proakis, Manolakis SOLUTIONS MANUAL TO Digital Signal Processing a computer based approach (2nd Ed.) (Mitra) SOLUTIONS MANUAL TO Digital Signal Processing a computer based approach (Mitra) SOLUTIONS MANUAL TO Digital Signal Processing by Proakis & Manolakis SOLUTIONS MANUAL TO Digital Signal Processing by Thomas J. Cavicchi SOLUTIONS MANUAL TO Digital Systems - Principles and Applications (10th Ed., Ronald Tocci, Neal Widmer, Greg Moss) SOLUTIONS MANUAL TO Discrete Mathematics ( 6th Ed., Richard Johnsonbaugh ) SOLUTIONS MANUAL TO Discrete Mathematics ( 6th Edition) by Richard Johnsonbaugh SOLUTIONS MANUAL TO Discrete Mathematics 3rd edition by Edgar, Goodaire and Parmenter SOLUTIONS MANUAL TO Discrete Random Signals and Statistical Signal Processing Charles W. Therrien SOLUTIONS MANUAL TO Discrete Time Signal Processing, 2nd Edition, Oppenheim SOLUTIONS MANUAL TO Discrete-Time Signal Processing 3rd ed by Oppenheim, Schafer SOLUTIONS MANUAL TO DSP First A Multimedia Approach-Mclellan, Schafer & Yoder SOLUTIONS MANUAL TO Dynamic Modeling and Control of Engineering Systems 2 E T. Kulakowski , F. Gardner, Shearer SOLUTIONS MANUAL TO Dynamics of Flight- Stability and Control, 3rd Ed by Etkin, Reid SOLUTIONS MANUAL TO Dynamics of Mechanical Systems by C. T. F. Ross SOLUTIONS MANUAL TO Dynamics of Structures 2nd ED by Clough, Penzien SOLUTIONS MANUAL TO Dynamics of structures 3rd E by Anil K. Chopra SOLUTIONS MANUAL TO Econometric Analysis of Cross Section and Panel Data (2003 ) by Jeffrey M Wooldridge SOLUTIONS MANUAL TO Econometric Analysis, 5E, by Greene SOLUTIONS MANUAL TO Econometric Analysis, 6E, by Greene SOLUTIONS MANUAL TO Econometrics of Financial Markets, by Adamek, Cambell, Lo, MacKinlay, Viceira SOLUTIONS MANUAL TO Econometrics, 2nd edition by Badi H. Baltagi SOLUTIONS MANUAL TO Econometrics: A Modern Introduction (Michael P. Murray) SOLUTIONS MANUAL TO Electric Circuits (7th Ed., James W Nilsson & Susan Riedel) SOLUTIONS MANUAL TO Electric Circuits (8th Ed., James W Nilsson & Susan Riedel) SOLUTIONS MANUAL TO Electric Circuits 9th Ed by Nilsson, Riedel SOLUTIONS MANUAL TO Electric Machinery 6th ed. A.E. Fitzgerald,Kingsley,Umans SOLUTIONS MANUAL TO Electric Machinery and Power System Fundamentals (Chapman) SOLUTIONS MANUAL TO Electric Machinery Fundamentals (4th Ed., Chapman) SOLUTIONS MANUAL TO Electric Machines Analysis and Design Applying MATLAB,Jim Cathey SOLUTIONS MANUAL TO Electric Machines By D. P. Kothari, I. J. Nagrath SOLUTIONS MANUAL TO Electrical Engineering Principles and Applications (3rd Ed., Allan R. Hambley) SOLUTIONS MANUAL TO Electrical Engineering Principles and Applications (4th Ed., Allan R. Hambley) SOLUTIONS MANUAL TO Electrical Machines, Drives and Power Systems (6th Ed., Theodore Wildi) SOLUTIONS MANUAL TO Electromagnetic Fields and Energy by Haus, Melcher SOLUTIONS MANUAL TO Electromagnetics Problem Solver (Problem Solvers) By The Staff of REA SOLUTIONS MANUAL TO Electromagnetism. Principles and Applications by LORRAIN, PAUL ; CORSON, DAVID SOLUTIONS MANUAL TO Electromechanical Dynamics Part 1, 2, 3 by Herbert H. Woodson, James R. Melcher SOLUTIONS MANUAL TO Electronic Circuit Analysis, 2nd Ed., by Donald Neamen SOLUTIONS MANUAL TO Electronic Devices 6th ed and electronic devices Electron Flow Version 4th ed, Floyd SOLUTIONS MANUAL TO Electronic Devices and Circuit Theory 10th Ed by Boylestad, Nashelsky SOLUTIONS MANUAL TO Electronic Devices and Circuit Theory 8th Ed by Robert Boylestad SOLUTIONS MANUAL TO Electronic Physics Strabman SOLUTIONS MANUAL TO Electronics, 2nd Ed., by Allan R. Hambley SOLUTIONS MANUAL TO Elementary Differential Equations ( Werner E. Kohler, Johnson) SOLUTIONS MANUAL TO Elementary Differential Equations and Boundary Value Problems (8th Ed., Boyce & Diprima) SOLUTIONS MANUAL TO Elementary Linear Algebra 5th edition by Stanley I. Grossman SOLUTIONS MANUAL TO Elementary Linear Algebra by Matthews SOLUTIONS MANUAL TO Elementary Linear Algebra with Applications (9th Ed., Howard Anton & Chris Rorres) SOLUTIONS MANUAL TO Elementary Linear Algebra with Applications 9E by Kolman, Hill SOLUTIONS MANUAL TO Elementary Mechanics & Thermodynamics by John W. Norbury SOLUTIONS MANUAL TO Elementary mechanics & thermodynamics jhon w.Nobury SOLUTIONS MANUAL TO ELEMENTARY NUMBER THEORY AND ITS APPLICATIONS, (5TH EDITION, Bart Goddard, Kenneth H. Rosen) SOLUTIONS MANUAL TO Elementary Number Theory and Its Applications, 6th Ed by Kenneth H. Rosen SOLUTIONS MANUAL TO Elementary Principles of Chemical Processes (3rd Ed., Felder & Rousseau) SOLUTIONS MANUAL TO Elementary Statistics Using The Graphing Calculator 9 Ed by MILTON LOYER SOLUTIONS MANUAL TO Elementary Statistics Using the Graphing Calculator For the TI-83-84 Plus (Mario F. Triola) SOLUTIONS MANUAL TO ELEMENTARY SURVEYING AN INTRODUCTION TO GEOMATICS 13TH EDITION BY Charles D. Ghilani and Paul R. Wolf ISBN0132555085 SOLUTIONS MANUAL TO Elements of Information Theory - M. Cover, Joy A. Thomas SOLUTIONS MANUAL TO Elements of Chemical Reaction Engineering by Fogler hubbard, hamman , johnson , 3rd edition SOLUTIONS MANUAL TO Elements of Deductive Inference by Bessie, Glennan SOLUTIONS MANUAL TO Elements of Electromagnetics , 2 ed by Matthew N. O. Sadiku SOLUTIONS MANUAL TO Elements of Electromagnetics , 3ed by Matthew N. O. Sadiku SOLUTIONS MANUAL TO Elements of Forecasting in Business, Finance, Economics and Government by Diebold SOLUTIONS MANUAL TO Embedded Microcomputer Systems Real Time Interfacing, 2nd Edition , Jonathan W. Valvano SOLUTIONS MANUAL TO Engineering and Chemical Thermodynamics (Koretsky) SOLUTIONS MANUAL TO ENGINEERING BIOMECHANICS (STATICS) by Angela Matos, Eladio Pereira, Juan Uribe and Elisandra Valentin SOLUTIONS MANUAL TO Engineering Circuit Analysis 6Ed, Luay Shaban SOLUTIONS MANUAL TO Engineering Circuit Analysis 6th ed by Hayt SOLUTIONS MANUAL TO Engineering Circuit Analysis 7th Ed. by William H. Hayt Jr SOLUTIONS MANUAL TO Engineering Economic Analysis 9th ED by Newnan SOLUTIONS MANUAL TO Engineering Economy and the Decision-Making Process (Joseph C. Hartman) SOLUTIONS MANUAL TO Engineering Economy, 14 Ed by Sullivan SOLUTIONS MANUAL TO Engineering Electromagnetics 6E by William H. Hayt Jr. and John A. Buck SOLUTIONS MANUAL TO Engineering Electromagnetics 7E by William H. Hayt Jr. and John A. Buck SOLUTIONS MANUAL TO Engineering Fluid Mechanics - 8th Ed by Crowe, Elger & Roberson SOLUTIONS MANUAL TO Engineering Fluid Mechanics 7th Ed by Crowe and Donald SOLUTIONS MANUAL TO Engineering Materials Science, by Milton Ohring SOLUTIONS MANUAL TO Engineering Mathematics (4th Ed., John Bird) SOLUTIONS MANUAL TO Engineering Mechanics - Dynamics by Boresi, Schmidt SOLUTIONS MANUAL TO Engineering Mechanics - Dynamics, 5th Ed (J. L. Meriam, L. G. Kraige) SOLUTIONS MANUAL TO Engineering Mechanics - Dynamics, 6th Ed (J. L. Meriam, L. G. Kraige) SOLUTIONS MANUAL TO Engineering Mechanics - Statics (10th Edition) by Russell C. Hibbeler SOLUTIONS MANUAL TO Engineering Mechanics - Statics (11th Edition) by Russell C. Hibbeler SOLUTIONS MANUAL TO Engineering Mechanics - Statics by Boresi, Schmidt SOLUTIONS MANUAL TO Engineering Mechanics - Statics, 4th Ed (J. L. Meriam, L. G. Kraige) SOLUTIONS MANUAL TO Engineering Mechanics - Statics, 6th Ed (J. L. Meriam, L. G. Kraige) SOLUTIONS MANUAL TO Engineering Mechanics : Dynamics (11th Ed., Hibbeler) SOLUTIONS MANUAL TO Engineering Mechanics Dynamic (10th Edition) hibbeler SOLUTIONS MANUAL TO Engineering Mechanics Dynamics (12th Ed., Hibbeler) SOLUTIONS MANUAL TO Engineering Mechanics Dynamics, Bedford & Fowler, 5th Edition SOLUTIONS MANUAL TO Engineering Mechanics Dynamics, by R. C. Hibbeler, 3rd SOLUTIONS MANUAL TO Engineering Mechanics Statics (12th Ed., Hibbeler) SOLUTIONS MANUAL TO Engineering Mechanics Statics, Bedford & Fowler, 5th Edition SOLUTIONS MANUAL TO Engineering Mechanics, Dynamics 2nd E by Riley, Sturges SOLUTIONS MANUAL TO Engineering Mechanics, Statics 2nd E by Riley, Sturges SOLUTIONS MANUAL TO Engineering Statistics (4th Ed., Douglas Montgomery, George Runger & Norma Faris Hubele) SOLUTIONS MANUAL TO Engineering Vibration 3rd Ed by Inman SOLUTIONS MANUAL TO Equilibrium Statistical Physics, 2nd E by Plischke, Bergersen SOLUTIONS MANUAL TO Erosion and sedimentation by Pierre Y. Julien SOLUTIONS MANUAL TO Essentials of Corporate Finance 6th Ed by Ross,Westerfield,Jordan SOLUTIONS MANUAL TO Essentials of Corporate Finance 7th Ed by Ross,Westerfield,Jordan SOLUTIONS MANUAL TO Essentials of Soil Mechanics and Foundations: Basic Geotechnics (7th Ed., David F. McCarthy) SOLUTIONS MANUAL TO Feedback Control of Dynamic Systems (4th Ed., Franklin, Powell & Emami-Naeini) SOLUTIONS MANUAL TO Feedback Control of Dynamic Systems (5th Ed., Franklin, Powell & Emami-Naeini) SOLUTIONS MANUAL TO Feedback Control of Dynamic Systems 6th E by Franklin, Powell, Naeini SOLUTIONS MANUAL TO Field and Wave Electromagnetics 2nd Ed by David K. Cheng SOLUTIONS MANUAL TO Financial Accounting 6th E with Annual Report by Libby, Short SOLUTIONS MANUAL TO Financial Accounting 6th Ed by Harrison SOLUTIONS MANUAL TO Financial Accounting An Integrated Approach, 6th Ed by Gibbins SOLUTIONS MANUAL TO Financial Management- Principles and Applications, 10th Ed by Keown, Scott SOLUTIONS MANUAL TO Financial Management- Theory and Practice 12 th ED by Brigham, Ehrhardt SOLUTIONS MANUAL TO Financial Reporting and Analysis Using Financial Accounting Information 10th Ed by Gibson SOLUTIONS MANUAL TO Financial Reporting and Analysis, 3E by Revsine, Collins, Johnson SOLUTIONS MANUAL TO Finite Element Techniques in Structural Mechanics Ross SOLUTIONS MANUAL TO First Course in Abstract Algebra, 3rd Ed by Joseph J. Rotman SOLUTIONS MANUAL TO First Course in Probability (7th Ed., Sheldon Ross) SOLUTIONS MANUAL TO Fluid Mechanics (5th Ed., White) SOLUTIONS MANUAL TO Fluid Mechanics 4th Ed by Cohen, Kundu SOLUTIONS MANUAL TO Fluid Mechanics 4th Edition by Frank M. White SOLUTIONS MANUAL TO Fluid Mechanics and Thermodynamics of Turbomachinery (5th Ed., S.L. Dixon) SOLUTIONS MANUAL TO Fluid Mechanics by CENGEL SOLUTIONS MANUAL TO Fluid Mechanics Egon Krause SOLUTIONS MANUAL TO Fluid Mechanics Fundamentals and Applications by Cengel & Cimbala SOLUTIONS MANUAL TO Fluid Mechanics with Engineering Applications, 10th Edition, by Finnemore SOLUTIONS MANUAL TO Foundations of Applied Combinatorics by Bender, Williamson SOLUTIONS MANUAL TO Foundations of Colloid Science 2e , Hunter SOLUTIONS MANUAL TO Foundations of Electromagnetic Theory by John R. Reitz, Frederick J. Milford SOLUTIONS MANUAL TO Foundations of Modern Macroeconomics 2nd Ed by Heijdra, Reijnders, Romp SOLUTIONS MANUAL TO Fourier and Laplace Transform - Antwoorden SOLUTIONS MANUAL TO Fractal Geometry Mathematical Foundations and Applications, 2nd Ed Kenneth Falcone SOLUTIONS MANUAL TO fracture mechanics ; fundamentals and applications, 2E, by T.L. Anderson SOLUTIONS MANUAL TO From Polymers to Plastics By A.K. van der Vegt SOLUTIONS MANUAL TO Fundamental Methods of Mathematical Economics 4th E by Chiang,Wainwright SOLUTIONS MANUAL TO Fundamental Quantum Mechanics for Engineers by Leon van Dommelen SOLUTIONS MANUAL TO Fundamentals of Advanced Accounting By Fischer, Taylor SOLUTIONS MANUAL TO Fundamentals of Aerodynamics ( 3 Ed., Anderson) SOLUTIONS MANUAL TO Fundamentals of Aerodynamics (2 Ed., Anderson) SOLUTIONS MANUAL TO Fundamentals of Aircraft Structural Analysis by Howard D. Curtis SOLUTIONS MANUAL TO Fundamentals of Applied Electromagnetics (5th Ed., Fawwaz T. Ulaby) SOLUTIONS MANUAL TO Fundamentals of Chemical Reaction Engineering by Davis SOLUTIONS MANUAL TO Fundamentals of Complex Analysis ( 3rd Ed., E. Saff & Arthur Snider ) SOLUTIONS MANUAL TO Fundamentals of Computer Organization and Architecture by Abd-El-Barr, El-Rewini SOLUTIONS MANUAL TO Fundamentals of Corporate Finance 8th edition by Ross SOLUTIONS MANUAL TO Fundamentals of Corporate Finance 9th edition by Ross SOLUTIONS MANUAL TO Fundamentals of Corporate Finance, 4th Edition (Brealey, Myers, Marcus) SOLUTIONS MANUAL TO Fundamentals of Differential Equations 7E Kent Nagle, B. Saff, Snider SOLUTIONS MANUAL TO Fundamentals of Differential Equations and Boundary Value Problems, 6th Ed by Nagle ,Saff, Snider SOLUTIONS MANUAL TO Fundamentals of Digital Logic with VHDL Design (1st Ed., Stephen Brown Vranesic) SOLUTIONS MANUAL TO Fundamentals of Digital Signal Processing Using Matlab 2nd Edition by Robert J. Schilling, Sandra L. Harris SOLUTIONS MANUAL TO Fundamentals of Electric Circuits (2nd.ed.) by C.K.Alexander M.N.O.Sadiku SOLUTIONS MANUAL TO Fundamentals of Electric Circuits (4E., Charles Alexander & Matthew Sadiku) SOLUTIONS MANUAL TO Fundamentals of Electromagnetics with Engineering Applications (Stuart Wentworth) SOLUTIONS MANUAL TO Fundamentals of Electronic Circuit Design , Comer SOLUTIONS MANUAL TO Fundamentals of Engineering Economics 2nd E by Chan S. Park SOLUTIONS MANUAL TO FUNDAMENTALS OF ENGINEERING ELECTROMAGNETICS, by DAVID CHENG SOLUTIONS MANUAL TO Fundamentals of Engineering Thermodynamics, 5th Ed (Michael J. Moran, Howard N. Shapiro) SOLUTIONS MANUAL TO Fundamentals of Engineering Thermodynamics, 6th Ed (Michael J. Moran, Howard N. Shapiro) SOLUTIONS MANUAL TO Fundamentals of Financial Management 12th edition James C. Van Horne, Wachowicz SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics 5th Ed Munson Young Okiishi SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics 6th Ed by Munson SOLUTIONS MANUAL TO Fundamentals of Fluid Mechanics, 4E (Bruce R. Munson, Donald F. Young, Theodore H.) SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer - 5th Edition F.P. Incropera D.P. DeWitt SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer (4th Ed., Incropera, DeWitt) SOLUTIONS MANUAL TO Fundamentals of Heat and Mass Transfer (6th Ed., Incropera, DeWitt) SOLUTIONS MANUAL TO Fundamentals of Hydraulic Engineering Systems 4th E by Houghtalen,Akan,Hwang SOLUTIONS MANUAL TO Fundamentals of Investments, 5th E by Jordan, Miller SOLUTIONS MANUAL TO Fundamentals of Logic Design, 5th Ed., by Charles Roth SOLUTIONS MANUAL TO Fundamentals of Machine Component Design (3rd Ed., Juvinall) SOLUTIONS MANUAL TO Fundamentals of Machine Component Design 4th Ed by Juvinall SOLUTIONS MANUAL TO Fundamentals of Machine Elements 2nd E by Bernard Hamrock SOLUTIONS MANUAL TO Fundamentals of Machine Elements by Bernard Hamrock SOLUTIONS MANUAL TO Fundamentals of Manufacturing 2nd Edition by Philip D. Rufe SOLUTIONS MANUAL TO Fundamentals of Materials Science and Engineering- An Integrated Approach, 3rd Ed by Callister SOLUTIONS MANUAL TO Fundamentals of Microelectronics by Behzad Razavi SOLUTIONS MANUAL TO Fundamentals of Modern Manufacturing 3rd Ed by Mikell P. Groover SOLUTIONS MANUAL TO Fundamentals of Modern Manufacturing: Materials, Processes, and Systems (2nd Ed., Mikell P. Groover) SOLUTIONS MANUAL TO Fundamentals of Momentum, Heat and Mass Transfer, 4th Ed by Welty,Wilson SOLUTIONS MANUAL TO Fundamentals of Momentum, Heat and Mass Transfer, 5th Ed by Welty,Wilson SOLUTIONS MANUAL TO Fundamentals of Organic Chemistry, 5E, by T. W. Graham Solomons SOLUTIONS MANUAL TO Fundamentals of Physics (7th Ed., David Halliday, Robert Resnick & Jearl Walker) SOLUTIONS MANUAL TO Fundamentals of Physics 9th Ed by Resnick, Walker, Halliday SOLUTIONS MANUAL TO Fundamentals of Physics, 8th Edition Halliday, Resnick, Walker SOLUTIONS MANUAL TO Fundamentals of Power Semiconductor Devices By Jayant Baliga SOLUTIONS MANUAL TO Fundamentals of Probability, with Stochastic Processes (3rd Ed., Saeed Ghahramani) SOLUTIONS MANUAL TO Fundamentals of Quantum Mechanics (C.L. Tang) SOLUTIONS MANUAL TO Fundamentals of Semiconductor Devices, 1st Edition by Anderson SOLUTIONS MANUAL TO Fundamentals of Signals and Systems Using the Web and Matlab (3rd Ed., Kamen & Bonnie S Heck) SOLUTIONS MANUAL TO Fundamentals of Structural Analysis 3rd Ed by Leet SOLUTIONS MANUAL TO Fundamentals of Thermal-Fluid Sciences, 2nd Ed. by Cengel SOLUTIONS MANUAL TO Fundamentals of Thermodynamics 5th Ed by Sonntag, Borgnakke and Van Wylen SOLUTIONS MANUAL TO Fundamentals of Thermodynamics 6th Ed by Sonntag, Borgnakke & Van Wylen SOLUTIONS MANUAL TO Fundamentals of Wireless Communication by Tse and Viswanath SOLUTIONS MANUAL TO Fundamentals of Wireless Communication by Tse, Viswanath From Suzie at FloridaPanhandler'sShithole. Wed Mar 13 19:35:30 2013 From: Suzie at FloridaPanhandler'sShithole. (Trailer Trash Suzie) Date: Wed, 13 Mar 2013 16:35:30 -0700 Subject: Jim Hodges, 6StringStu, Six String Stu, James Stuart Hodges 1405 Message-ID: <1swugicrd0byn.myrj3g9hkr47.dlg@40tude.net> 1405 577 SW Dexter Cir, Apt 201 1442 SW Haygood Loop, Apt 101 Lake City, FL 32025 (386) 438-8968 Local PD: (386) 752-4344 From: "6StringStu" Newsgroups: alt.social-security-disability Date: Fri, 2 Apr 2010 01:02:30 -0500 " Of the three felonies on my record, 1: Violation of the Mann act (federal kidnapping...).... 2nd Felony arrest Homicide........ 3rd felony arrest assault with intent........ Lots of misdomeanors..... fighting hand to hand stuff......" From: "SixStringStu" Newsgroups: alt.social-security-disability,alt.comp.blind-users,free.UseNet,free.spam,free.spirit Date: Mon, 10 Sep 2012 21:39:02 -0400 "My criminal record consists of one count of driving under the influance of alchohol...." From: "6StringStu" Newsgroups: alt.social-security-disability Date: Fri, 2 Apr 2010 01:02:30 -0500 "I used to own quite a few firearms. When I awoke from my coma they had been "liquidated". Nowadys I have......a 357mag revolver (I'd hate to drop a shell casing when doing that close up action. A 30-06 with a good scope that I can hit a fist sized target at 500 yards..." From: "SixStringStu" Newsgroups: alt.social-security-disability Date: Fri, 19 Aug 2011 08:49:53 -0400 "Of the five guys that jummped me, three are rotting corpses, one is walking around with a pronounced limp and no orbs in their sockets and one pisses his pants everytime a car backfires. " From charleshixsn at earthlink.net Wed Mar 13 19:51:28 2013 From: charleshixsn at earthlink.net (Charles Hixson) Date: Wed, 13 Mar 2013 16:51:28 -0700 Subject: Sphinx highlighting Message-ID: <51411100.6070003@earthlink.net> What controls the yellow highlight bar that Sphinx sometimes puts in the documentation? E.g.: .. py:function:: basic_parseStrTest () generates bold-face text, where .. py:function:: basicParseStrTest () generates text with a yellow bar highlight. I actually rather like the yellow bar highlight, but I can't stand having it appear for some of my functions, and not for others, and I haven't been able to figure out what turns it on or off. -- Charles Hixson From jeanmichel at sequans.com Thu Mar 14 05:54:37 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 14 Mar 2013 10:54:37 +0100 (CET) Subject: Sphinx highlighting In-Reply-To: <51411100.6070003@earthlink.net> Message-ID: <71713625.4685355.1363254877079.JavaMail.root@sequans.com> ----- Original Message ----- > What controls the yellow highlight bar that Sphinx sometimes puts in > the > documentation? > E.g.: > .. py:function:: basic_parseStrTest () > generates bold-face text, where > .. py:function:: basicParseStrTest () > generates text with a yellow bar highlight. > > I actually rather like the yellow bar highlight, but I can't stand > having it appear for some of my functions, and not for others, and I > haven't been able to figure out what turns it on or off. > > -- > Charles Hixson I think the yellow bar only shows up when you folllow a link to that function. See for instance the difference between http://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process.start and http://docs.python.org/2/library/multiprocessing.html where you go manually to the start method. Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rosuav at gmail.com Thu Mar 14 02:58:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 17:58:39 +1100 Subject: timeit module in IDLE Message-ID: While putting together some timing stats for the latest Python 3.3 string representation thread, I ran into an oddity in how IDLE handles timeit. The normal way to profile Python code, according to stuff I've found on the internet, is timeit.timeit: >>> import timeit >>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'asdf'*10000",number=10000) 0.57752172412974268 Now I knew that the module I wanted was timeit, but I didn't remember the full incantation, so I did the obvious thing: >>> import timeit >>> timeit. Only one thing came up: Timer. And help(timeit) doesn't mention timeit.timeit either. Whereas the documentation: http://docs.python.org/2/library/timeit.html http://docs.python.org/3/library/timeit.html clearly states that timeit.timeit() is the way to do things. Snooping the source shows that timeit.timeit() is just a tiny convenience function (alongside timeit.repeat()), but it'd still be nice to have that come up in the Ctrl-Space list, since it's the most-normal way to run timing tests. Would there be a problem with adding timeit (and possibly repeat) to __all__? -__all__ = ["Timer"] +__all__ = ["Timer", "timeit"] ChrisA From tjreedy at udel.edu Thu Mar 14 03:21:38 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Mar 2013 03:21:38 -0400 Subject: timeit module in IDLE In-Reply-To: References: Message-ID: On 3/14/2013 2:58 AM, Chris Angelico wrote: > While putting together some timing stats for the latest Python 3.3 > string representation thread, I ran into an oddity in how IDLE handles > timeit. The normal way to profile Python code, according to stuff I've > found on the internet, is timeit.timeit: > >>>> import timeit >>>> timeit.timeit("s=s[:-1]+u'\u1234'","s=u'asdf'*10000",number=10000) > 0.57752172412974268 > > Now I knew that the module I wanted was timeit, but I didn't remember > the full incantation, so I did the obvious thing: > >>>> import timeit >>>> timeit. > > Only one thing came up: Timer. And help(timeit) doesn't mention > timeit.timeit either. Whereas the documentation: > > http://docs.python.org/2/library/timeit.html > http://docs.python.org/3/library/timeit.html > > clearly states that timeit.timeit() is the way to do things. > > Snooping the source shows that timeit.timeit() is just a tiny > convenience function (alongside timeit.repeat()), but it'd still be > nice to have that come up in the Ctrl-Space list, since it's the > most-normal way to run timing tests. > > Would there be a problem with adding timeit (and possibly repeat) to __all__? > > -__all__ = ["Timer"] > +__all__ = ["Timer", "timeit"] I believe everything in the doc should be in __all__. Open an issue on the tracker and add terry.reedy as nosy. Note on the issue that timeit.default_timer is not callable, contrary to the doc (which should also be fixed). -- Terry Jan Reedy From rosuav at gmail.com Thu Mar 14 04:15:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Mar 2013 19:15:41 +1100 Subject: timeit module in IDLE In-Reply-To: References: Message-ID: On Thu, Mar 14, 2013 at 6:21 PM, Terry Reedy wrote: > I believe everything in the doc should be in __all__. Open an issue on the > tracker and add terry.reedy as nosy. > Note on the issue that timeit.default_timer is not callable, contrary to the > doc (which should also be fixed). Thanks! Issue 17414 created. ChrisA From e.tekinalp at gmx.de Thu Mar 14 05:34:31 2013 From: e.tekinalp at gmx.de (e.tekinalp at gmx.de) Date: Thu, 14 Mar 2013 02:34:31 -0700 (PDT) Subject: Getting a list in user defined selection order Message-ID: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> Hello everybody, I want to select components(vertices) in a particular Order with python. So when I create a list the main problem is, that maya is not listing the verts in the correct selected order as I did. Here an example: I have selected from a polySphere the following vtx [sphere.vtx400, sphere.vtx250, sphere.vtx260, sphere.vtx500, sphere.vtx100] so maya is giving me a list like that: [sphere.vtx100, sphere.vtx250, sphere.vtx260, sphere.vtx400, sphere.vtx500] I know that there is a flag in the cmds.ls that created a list in ordered Selection and that you have to enable the tos flag from the selectPref command cmds.selectPref(tso = 1) vtx = cmds.ls(os = 1, flatten = 1) cmds.select(vtx) But then he gives me an empty list, I also tried to toggle it in the preference window, but to be honest that couldn't be the way. So how can I get a list in an userdefined selection order. Thank you guys for any help. Cheerio the turkish engineer From e.tekinalp at gmx.de Thu Mar 14 05:38:42 2013 From: e.tekinalp at gmx.de (e.tekinalp at gmx.de) Date: Thu, 14 Mar 2013 02:38:42 -0700 (PDT) Subject: Getting a list in user defined selection order In-Reply-To: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> References: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> Message-ID: Ah sorry this is the correct snippet cmds.selectPref(tso = 1) vtx = cmds.ls(os = 1, flatten = 1) print vtx the other one wouldn't make any sense. :) From tjreedy at udel.edu Thu Mar 14 18:38:25 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Mar 2013 18:38:25 -0400 Subject: Getting a list in user defined selection order In-Reply-To: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> References: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> Message-ID: On 3/14/2013 5:34 AM, e.tekinalp at gmx.de wrote: > Hello everybody, > > I want to select components(vertices) in a particular Order with python. > So when I create a list the main problem is, that maya is not listing the verts in the correct selected order as I did. > > Here an example: > > I have selected from a polySphere the following vtx > > [sphere.vtx400, sphere.vtx250, sphere.vtx260, sphere.vtx500, sphere.vtx100] > > so maya is giving me a list like that: > > [sphere.vtx100, sphere.vtx250, sphere.vtx260, sphere.vtx400, sphere.vtx500] It is sorting by name. > I know that there is a flag in the cmds.ls that created a list in ordered Selection and that you have to enable the tos flag from the selectPref command > > cmds.selectPref(tso = 1) > vtx = cmds.ls(os = 1, flatten = 1) > cmds.select(vtx) > > But then he gives me an empty list, I also tried to toggle it in the preference window, but to be honest that couldn't be the way. > > So how can I get a list in an userdefined selection order. > > Thank you guys for any help. This is a maya question rather than a python question. Is not there a maye list where you can ask? If not, is a a stackovevflow-like site that covers maya? -- Terry Jan Reedy From e.tekinalp at gmx.de Thu Mar 14 19:13:34 2013 From: e.tekinalp at gmx.de (e.tekinalp at gmx.de) Date: Thu, 14 Mar 2013 16:13:34 -0700 (PDT) Subject: Getting a list in user defined selection order In-Reply-To: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> References: <658b2c00-16e8-4284-940c-c88442e7f169@googlegroups.com> Message-ID: Am Donnerstag, 14. M?rz 2013 10:34:31 UTC+1 schrieb e.tek... at gmx.de: > Hello everybody, > > > > I want to select components(vertices) in a particular Order with python. > > So when I create a list the main problem is, that maya is not listing the verts in the correct selected order as I did. > > > > Here an example: > > > > I have selected from a polySphere the following vtx > > > > [sphere.vtx400, sphere.vtx250, sphere.vtx260, sphere.vtx500, sphere.vtx100] > > > > so maya is giving me a list like that: > > > > [sphere.vtx100, sphere.vtx250, sphere.vtx260, sphere.vtx400, sphere.vtx500] > > > > I know that there is a flag in the cmds.ls that created a list in ordered Selection and that you have to enable the tos flag from the selectPref command > > > > cmds.selectPref(tso = 1) > > vtx = cmds.ls(os = 1, flatten = 1) > > cmds.select(vtx) > > > > But then he gives me an empty list, I also tried to toggle it in the preference window, but to be honest that couldn't be the way. > > > > So how can I get a list in an userdefined selection order. > > > > Thank you guys for any help. > > > > Cheerio > > the turkish engineer ah thank you Terry I was in the wrong group.. XD From anadionisio257 at gmail.com Thu Mar 14 06:12:11 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Thu, 14 Mar 2013 03:12:11 -0700 (PDT) Subject: TypeError: 'float' object is not iterable Message-ID: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Hi!! I keep having this error and I don't know why: TypeError: 'float' object is not iterable. I have this piece of code, that imports to python some data from Excel and saves it in a list: " t_amb = [] for i in range(sh2.nrows): t_amb.append(sh2.cell(i,2).value) print t_amb " Here is everything ok. But then, I need to pass the data again to exel, so I wrote this: " a=8 for b in range (len(t_amb)): a=8 for d in t_amb[b]: a=a+1 sheet.write(a,b+1,d) " The error appear in "for d in t_amb[b]:" and I don't understand why. Can you help me? From joel.goldstick at gmail.com Thu Mar 14 06:31:02 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 14 Mar 2013 06:31:02 -0400 Subject: TypeError: 'float' object is not iterable In-Reply-To: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: On Thu, Mar 14, 2013 at 6:12 AM, Ana Dion?sio wrote: > Hi!! > > I keep having this error and I don't know why: TypeError: 'float' object > is not iterable. > > I have this piece of code, that imports to python some data from Excel and > saves it in a list: > > " > t_amb = [] > > for i in range(sh2.nrows): > t_amb.append(sh2.cell(i,2).value) > > print t_amb > > " > Here is everything ok. > > But then, I need to pass the data again to exel, so I wrote this: > > " > a=8 > for b in range (len(t_amb)): > a=8 > for d in t_amb[b]: > a=a+1 > sheet.write(a,b+1,d) > " > > The error appear in "for d in t_amb[b]:" and I don't understand why. Can > you help me? > Most likely the value of t_amb[[b] is a float. It would have to be a list or a tuple or some other sequence to be iterable. I can't tell what you are trying to do here > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From anadionisio257 at gmail.com Thu Mar 14 06:34:57 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Thu, 14 Mar 2013 03:34:57 -0700 (PDT) Subject: TypeError: 'float' object is not iterable In-Reply-To: References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: <225a4a3e-bb0b-406b-8feb-c845e9ab4c9a@googlegroups.com> But isn't t_amb a list? I thought that the first piece of script would create a list. I'm trying to create a list named t_amb with some values that are in a Excel sheet. And then I need to export that list to another Excel sheet From anadionisio257 at gmail.com Thu Mar 14 06:34:57 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Thu, 14 Mar 2013 03:34:57 -0700 (PDT) Subject: TypeError: 'float' object is not iterable In-Reply-To: References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: <225a4a3e-bb0b-406b-8feb-c845e9ab4c9a@googlegroups.com> But isn't t_amb a list? I thought that the first piece of script would create a list. I'm trying to create a list named t_amb with some values that are in a Excel sheet. And then I need to export that list to another Excel sheet From joel.goldstick at gmail.com Thu Mar 14 06:44:17 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 14 Mar 2013 06:44:17 -0400 Subject: TypeError: 'float' object is not iterable In-Reply-To: <225a4a3e-bb0b-406b-8feb-c845e9ab4c9a@googlegroups.com> References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> <225a4a3e-bb0b-406b-8feb-c845e9ab4c9a@googlegroups.com> Message-ID: On Thu, Mar 14, 2013 at 6:34 AM, Ana Dion?sio wrote: > But isn't t_amb a list? I thought that the first piece of script would > create a list. > t_amb might be a list, but t_amb[b] is apparently a number of type float that is in that list > > I'm trying to create a list named t_amb with some values that are in a > Excel sheet. And then I need to export that list to another Excel sheet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Mar 14 06:43:48 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Mar 2013 10:43:48 +0000 Subject: TypeError: 'float' object is not iterable In-Reply-To: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: <5141A9E4.9030608@mrabarnett.plus.com> On 14/03/2013 10:12, Ana Dion?sio wrote: > Hi!! > > I keep having this error and I don't know why: TypeError: 'float' object is not iterable. > > I have this piece of code, that imports to python some data from Excel and saves it in a list: > > " > t_amb = [] > > for i in range(sh2.nrows): > t_amb.append(sh2.cell(i,2).value) > > print t_amb > > " > Here is everything ok. > > But then, I need to pass the data again to exel, so I wrote this: > > " > a=8 > for b in range (len(t_amb)): > a=8 > for d in t_amb[b]: > a=a+1 > sheet.write(a,b+1,d) > " > > The error appear in "for d in t_amb[b]:" and I don't understand why. Can you help me? > t_amb is a list of float, so t_amb[b] is a float, but you can't iterate over a float. From clp2 at rebertia.com Thu Mar 14 06:50:39 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 14 Mar 2013 03:50:39 -0700 Subject: TypeError: 'float' object is not iterable In-Reply-To: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: On Thu, Mar 14, 2013 at 3:12 AM, Ana Dion?sio wrote: > Hi!! > > I keep having this error and I don't know why: TypeError: 'float' object is not iterable. In general, in the future, always include the full exception Traceback, not just the final error message. The extra details this provides can greatly aid debugging. > I have this piece of code, that imports to python some data from Excel and saves it in a list: > > " > t_amb = [] > > for i in range(sh2.nrows): > t_amb.append(sh2.cell(i,2).value) `t_amb` is a list, and you are apparently putting floats (i.e. real numbers) into it. `t_amb` is a list of floats. Therefore every item of `t_amb` (i.e. `t_amb[x]`, for any `x` that's within the bounds of the list's indices) will be a float. (Also, you may want to rewrite this as a list comprehension; http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions ) > print t_amb > > " > Here is everything ok. > > But then, I need to pass the data again to exel, so I wrote this: > > " > a=8 This duplicate assignment is pointless. > for b in range (len(t_amb)): > a=8 > for d in t_amb[b]: Given our earlier conclusion, we likewise know that `t_amb[b]` will be a float (we merely replaced the arbitrary `x` with `b`). A single float is a scalar, not a collection, so it's nonsensical to try and iterate over it like you are in "for d in t_amb[b]:"; a number is not a list. `t_amb[b]` is a lone number, and numbers contain no items/elements over which to iterate. Perhaps you want just "d = t_amb[b]" ? Remember that in a `for` loop, the expression after the `in` (i.e. `t_amb[b]`) is evaluated only once, at the beginning of the loop, and not repeatedly. In contrast, assuming this were a valid `for` loop, `d` would take on different values at each iteration of the loop. In any case, it's rarely necessary nowadays to manually iterate over the range of the length of a list; use `enumerate()` instead; http://docs.python.org/2/library/functions.html#enumerate > a=a+1 > sheet.write(a,b+1,d) > " > > The error appear in "for d in t_amb[b]:" and I don't understand why. Can you help me? I hope this explanation has been sufficiently clear. If you haven't already, you may wish to review the official Python tutorial at http://docs.python.org/2/tutorial/index.html . You may also find it helpful to run your program step-by-step in the interactive interpreter/shell, printing out the values of your variables along the way so as to understand what your program is doing. Regards, Chris From john_ladasky at sbcglobal.net Thu Mar 14 14:11:14 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 14 Mar 2013 11:11:14 -0700 (PDT) Subject: TypeError: 'float' object is not iterable In-Reply-To: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> References: <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> Message-ID: <5b49a5b4-dfaa-44fe-a60a-8e9aafde9f60@googlegroups.com> On Thursday, March 14, 2013 3:12:11 AM UTC-7, Ana Dion?sio wrote: > for b in range (len(t_amb)): > a=8 > for d in t_amb[b]: > a=a+1 > sheet.write(a,b+1,d) > > The error appear in "for d in t_amb[b]:" and I don't understand why. Can you help me? It looks to me like you know how to program in some other language, possibly C, and your other language's needs are affecting the way that you write Python. You are supplying an explicit variable, b to step through... something. I THINK that you want to step through t_amb, and not through the Bth element of t_amb. Python's "in" statement will do this for you automatically, without you having to keep track of an index variable. You didn't show your import statements, but I assume you are using the xlwt module. That's where I find the sheet.write() function. Now, exactly HOW did you want to write the data back to the Excel file? In a single column? A single row? Or in a diagonal? You have two nested loops. I'm confused by the fact that you are incrementing both the row and column indices for sheet.write(). Do you know about the enumerate() function? It's very handy. It yields a tuple, the first element of which is a number counting up from zero, and the second element of which is an element from the (iterable) variable that you provide. Does this code accomplish your task? for column, data in enumerate(t_amb): sheet.write(8, column+1, data) Or this? for row, data in enumerate(t_amb): sheet.write(row+8, 1, data) If you have any questions, feel free to ask. From olsr.kamal at gmail.com Thu Mar 14 08:16:05 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Thu, 14 Mar 2013 05:16:05 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? Message-ID: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> how to couper all the obejcts in a canvas in an auther canvas? From rantingrickjohnson at gmail.com Thu Mar 14 18:24:51 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 14 Mar 2013 15:24:51 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: <1e71d1b8-f187-42e2-a4c2-87f97860dfb9@googlegroups.com> On Thursday, March 14, 2013 7:16:05 AM UTC-5, olsr.... at gmail.com wrote: > how to couper all the obejcts in a canvas in an auther canvas? Hmm, well before i can even start solving your problem, i'll need to spend some time figuring out what the hell you're problem is. o_O. "Maybe" you meant to say this: > how to [copy] all the [canvas items] in [one] canvas [into another] canvas? "Ahhh, the sweet nectar of articulate communication!" Why would you want to do that exactly? Hopefully you have a good reason. There are quite a few "canvas items" to consider: * arc objects * bitmap objects * image objects * line objects * oval objects * polygon objects * rectangle objects * text objects * window objects There does not seem to be an easy way to do this via the Tkinter API (feel free to dig through the TCL/Tk docs if you like), however, if all you need to do is transfer a few simple primitives from one canvas to another, then the following (very general and admittedly quite naive) approach might get you there: for object in canvas1 # create newobject in canvas2 # configure newobject But there are quite a few (very important) details that that little sample leaves out, for instance: tags, stacking orders, tag bindings, etc. From wuwei23 at gmail.com Thu Mar 14 21:07:16 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 14 Mar 2013 18:07:16 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> <1e71d1b8-f187-42e2-a4c2-87f97860dfb9@googlegroups.com> Message-ID: On Mar 15, 8:24?am, Rick Johnson wrote: > Hmm, well before i can even start solving your problem, i'll need to > spend some time figuring out what the hell you're problem is. o_O. > "Maybe" you meant to say this: > > > how to [copy] all the [canvas items] in [one] canvas [into another] canvas? > > ?"Ahhh, the sweet nectar of articulate communication!" Mocking people for whom English is obviously not their first language just makes you look petty and racist. From rosuav at gmail.com Fri Mar 15 02:29:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Mar 2013 17:29:26 +1100 Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> <1e71d1b8-f187-42e2-a4c2-87f97860dfb9@googlegroups.com> Message-ID: On Fri, Mar 15, 2013 at 12:07 PM, alex23 wrote: > On Mar 15, 8:24 am, Rick Johnson wrote: >> Hmm, well before i can even start solving your problem, i'll need to >> spend some time figuring out what the hell you're problem is. o_O. >> "Maybe" you meant to say this: >> >> > how to [copy] all the [canvas items] in [one] canvas [into another] canvas? >> >> "Ahhh, the sweet nectar of articulate communication!" > > Mocking people for whom English is obviously not their first language > just makes you look petty and racist. Yes, but there is legitimate criticism for a post that clearly hasn't had much work put into it. I'm not 100% convinced that English isn't the OP's first language (it seems plausible, even likely, but far from certain), but I'm confident that the OP did not spend a few minutes polishing the post before hitting Send (or Expedier, or Versenden, or whatever the button says). Now, that doesn't mean it's polite or useful to *mock* the person for it, but it is at least a legit complaint. ChrisA From olsr.kamal at gmail.com Fri Mar 15 08:00:15 2013 From: olsr.kamal at gmail.com (olsr.kamal at gmail.com) Date: Fri, 15 Mar 2013 05:00:15 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: i maybe don't talk english very well but at least i am not a Rude,and you are not obligated to answering me much less Mocking me ,i assure you that i will not post anything anymore jackass thank you alex23 From stefan_ml at behnel.de Fri Mar 15 08:18:50 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 15 Mar 2013 13:18:50 +0100 Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: olsr.kamal at gmail.com, 15.03.2013 13:00: > i maybe don't talk english very well but at least i am not a Rude,and you are not obligated to answering me much less Mocking me ,i assure you that i will not post anything anymore jackass > thank you alex23 As Chris pointed out, the real problem was that you were not clear at all in your post about what your problem was. If you had taken a bit more time explaining it, maybe even showing a bit of code that makes it clear what you tried and what did not work about it, you would have made it much clearer that you are a person worth responding to. Basically, the question is, if you do not care enough yourself to pose an understandable question (and I mean the actual content, regardless of any language comprehension deficiencies etc.), why do you think we should care enough about it to try to understand it and even answer it? This might help you in asking better questions next time: http://catb.org/~esr/faqs/smart-questions.html Note that there is also a list of translations, a couple of which might be easier to read for you: http://catb.org/~esr/faqs/smart-questions.html#translations Stefan From davea at davea.name Fri Mar 15 08:42:49 2013 From: davea at davea.name (Dave Angel) Date: Fri, 15 Mar 2013 08:42:49 -0400 Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: <51431749.1050004@davea.name> On 03/15/2013 08:00 AM, olsr.kamal at gmail.com wrote: > i maybe don't talk english very well but at least i am not a Rude,and you are not obligated to answering me much less Mocking me ,i assure you that i will not post anything anymore jackass > thank you alex23 > Note also that you were insulted by a noted troll generator here (notice his pseudo-name, Ranting Rick), one that many of us have kill-filed to avoid reading his posts. Most newcomers to mailing lists will omit some details in their queries, and we try to help fill in the details. Sometimes what might help if you think you might be misunderstood is to pose the query in more than one way, or give some example code, or something so we can fill in the missing or misunderstood pieces. Start by specifying the environment you're using (python version, operating system, any 3rd party libraries). Then include enough code that we know exactly what you mean by canvas. -- DaveA From rantingrickjohnson at gmail.com Fri Mar 15 15:49:33 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 15 Mar 2013 12:49:33 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: On Friday, March 15, 2013 7:00:15 AM UTC-5, olsr.... at gmail.com wrote: > i maybe don't talk english very well but at least i am not > a Rude,and you are not obligated to answering me much > less Mocking me ,i assure you that i will not post > anything anymore jackass > > thank you alex23 Well *WELL*. What happened? Your English is so articulate now. Hmm, maybe you can only write clearly when you are angry, OR, maybe you ordered "Rosetta Stone" (you know, the cheesy language learning product from those late night TV infomercials, the one where users (oops i meant actors) of the product offer intelligent testimonials like this: Man: "...it was purdy guud!" Woman: "If you can click a mouse, then, your pretty set!" *FACEPALM*: Evolution has forsaken us all! However, i will place all my money on the fact that you are nothing more than an "agent provocateur" ...(psst: you should understand that word because it is French!)... hell bent on an insidious mission of reverse trolling; which is evident by your inability to distinguish "emotional troll posts" from "logical and informative replies" (whether acerbic or not). I'll allow the intelligent folks among us to come to their own conclusions as to your *real* intentions. However, if you are in-fact "real" (and i use that term quite loosely), then you sir are a fine example of what is wrong with people today. In any event, i wish you good luck with your "learning adventures". PS: If you don't like my replies then you need to exercise your freedom by ignoring them. You have a right to be offended, and i have a right not to give a DAMN! Cheers From rustompmody at gmail.com Fri Mar 15 10:09:41 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 07:09:41 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: I dont usually bother about spelling/grammar etc. And I think it silly to do so on a python list. However with this question: On Mar 14, 5:16 pm, olsr.ka... at gmail.com wrote: > how to couper all the obejcts in a canvas in an auther canvas? "obejcts" is clearly "objects" and "auther" is probably "other" But what the *^*& is couper? I first thought it was "couple" It could be "copy" as Rick understood By some stretch it could even be "cope" So yes grammar/spellings etc dont matter... as long as we are within the bounds of comprehension! From jeanmichel at sequans.com Fri Mar 15 10:52:11 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 15 Mar 2013 15:52:11 +0100 (CET) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: Message-ID: <115170410.5462401.1363359131743.JavaMail.root@sequans.com> ----- Original Message ----- > > I dont usually bother about spelling/grammar etc. And I think it > silly > to do so on a python list. > > However with this question: > > On Mar 14, 5:16 pm, olsr.ka... at gmail.com wrote: > > how to couper all the obejcts in a canvas in an auther canvas? > > "obejcts" is clearly "objects" > and "auther" is probably "other" > > But what the *^*& is couper? > I first thought it was "couple" > It could be "copy" as Rick understood > By some stretch it could even be "cope" > > So yes grammar/spellings etc dont matter... as long as we are within > the bounds of comprehension! couper is probably a french word, I've seen some of the OP's threads written in french. It means "cut". He probably wants to "cut" some objects in a canvas and "paste" them in another. 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 Fri Mar 15 10:56:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Mar 2013 01:56:50 +1100 Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: <115170410.5462401.1363359131743.JavaMail.root@sequans.com> References: <115170410.5462401.1363359131743.JavaMail.root@sequans.com> Message-ID: On Sat, Mar 16, 2013 at 1:52 AM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> >> I dont usually bother about spelling/grammar etc. And I think it >> silly >> to do so on a python list. >> >> However with this question: >> >> On Mar 14, 5:16 pm, olsr.ka... at gmail.com wrote: >> > how to couper all the obejcts in a canvas in an auther canvas? >> >> "obejcts" is clearly "objects" >> and "auther" is probably "other" >> >> But what the *^*& is couper? >> I first thought it was "couple" >> It could be "copy" as Rick understood >> By some stretch it could even be "cope" >> >> So yes grammar/spellings etc dont matter... as long as we are within >> the bounds of comprehension! > > couper is probably a french word, I've seen some of the OP's threads written in french. > > It means "cut". > > He probably wants to "cut" some objects in a canvas and "paste" them in another. Ah. Not having any real comprehension of French, I was thinking along the lines of "copy", which thus wouldn't be very far wrong. However, it still stands that the message would have been a lot more comprehensible with a bit more detail. ChrisA From jeanmichel at sequans.com Fri Mar 15 11:09:58 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 15 Mar 2013 16:09:58 +0100 (CET) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: Message-ID: <1601076822.5474044.1363360198431.JavaMail.root@sequans.com> ----- Original Message ----- > On Sat, Mar 16, 2013 at 1:52 AM, Jean-Michel Pichavant > > couper is probably a french word, I've seen some of the OP's > > threads written in french. > > > > It means "cut". > > > > He probably wants to "cut" some objects in a canvas and "paste" > > them in another. > > Ah. Not having any real comprehension of French, I was thinking along > the lines of "copy", which thus wouldn't be very far wrong. However, > it still stands that the message would have been a lot more > comprehensible with a bit more detail. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list See http://mail.python.org/pipermail/python-list/2013-March/642708.html I can tell that even in a correct French, the OP gives very few details anyway. He must have lost a bet, and now can only ask questions with 1 subject, 1 verb, no greeting. 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 rantingrickjohnson at gmail.com Fri Mar 15 16:46:05 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 15 Mar 2013 13:46:05 -0700 (PDT) Subject: how to couper contenier of a canvas in an outer canvas??? In-Reply-To: References: <638062bb-68a0-49d0-b896-23015f7aa421@googlegroups.com> Message-ID: how to couper all the obejcts in a canvas in an auther canvas? On Friday, March 15, 2013 9:09:41 AM UTC-5, rusi wrote: > I dont usually bother about spelling/grammar etc. And I > think it silly to do so on a python list. However with > this question: > > On Mar 14, 5:16 pm, olsr.ka... at gmail.com wrote: > > how to couper all the obejcts in a canvas in an auther > > canvas? > > "obejcts" is clearly "objects" > and "auther" is probably "other" > > But what the *^*& is couper? > I first thought it was "couple" Indeed. He could have meant to say: Quote = """\ How to couple all object in one canvas with corresponding objects in another canvas so that edits in one canvas are reflected in the objects of another canvas. """ It would be a strange request, but i have witnessed much stranger. But even *IF* we could interpret such cryptic words as "coupler" and "auther", we would still have no idea what the word "canvas" is referring to. I mean, we could postulate that it is probably a 2D or 3D graphics window, but even then, which GUI library (or gfx library) is he referring to? Maybe he's asking questions about WebGL? WHO KNOWS? A real person would think: "oops, i was far too ambiguous with my first question, better re-phrase my question now!". An agent provocateur would think: "Got him! Now pretend to be a "helpless little student" who's just been brow beaten by an "overbearing intellectual heavy weight" and cry loudly in the corner so everyone will feel sorry for me. *wah* *wah-wah* [peeks over shoulder with quivering lips to see if people are watching] passive voice: "ITS WORKING!!!" [quickly turns back to corner and ratchets up the emotion] *sobbing* *choking* *sniffling* What a PATHETIC display! From galois271 at gmail.com Thu Mar 14 11:38:11 2013 From: galois271 at gmail.com (Chuck) Date: Thu, 14 Mar 2013 08:38:11 -0700 (PDT) Subject: Generating Filenames from Feeds Message-ID: HI all, I am trying to write a podcast catcher for fun, and I am trying to come up with a way to generate a destination filename to use in the function urlretrieve(url, destination). I would like the destination filename to end in a .mp3 extension. My first attempts were parsing out the and stripping the whitespace characters, and joining with os.path.join. I haven't been able to make that work for some reason. Whenever I put the .mp3 in the os.path.join I get syntax errors. I am wondering if there is a better way? I was doing something like os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where pubdate has been parsed and stripped of whitespace. I keep getting an error around the .mp3. Any ideas? Thanks!! Chuck From joel.goldstick at gmail.com Thu Mar 14 12:05:05 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 14 Mar 2013 12:05:05 -0400 Subject: Generating Filenames from Feeds In-Reply-To: References: Message-ID: On Thu, Mar 14, 2013 at 11:38 AM, Chuck wrote: > HI all, > > I am trying to write a podcast catcher for fun, and I am trying to come up > with a way to generate a destination filename to use in the function > urlretrieve(url, destination). I would like the destination filename to > end in a .mp3 extension. > > My first attempts were parsing out the and stripping the > whitespace characters, and joining with os.path.join. I haven't been able > to make that work for some reason. The reason is apparently a syntax error. Whenever I put the .mp3 in the os.path.join I get syntax errors. I am > wondering if there is a better way? > Yes, don't write code with syntax errors! > > I was doing something like > os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where > pubdate has been parsed and stripped of whitespace. I keep getting an > error around the .mp3. > > Any ideas? > Seriously, if you don't post a minimal code example that shows the problem and with a full traceback you are asking strangers to do magic tricks for your pleasure. > > Thanks!! > Chuck > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Mar 14 12:07:43 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Mar 2013 16:07:43 +0000 Subject: Generating Filenames from Feeds In-Reply-To: References: Message-ID: <5141F5CF.3080806@mrabarnett.plus.com> On 14/03/2013 15:38, Chuck wrote: > HI all, > > I am trying to write a podcast catcher for fun, and I am trying to > come up with a way to generate a destination filename to use in the > function urlretrieve(url, destination). I would like the > destination filename to end in a .mp3 extension. > > My first attempts were parsing out the and stripping the > whitespace characters, and joining with os.path.join. I haven't been > able to make that work for some reason. Whenever I put the .mp3 in > the os.path.join I get syntax errors. I am wondering if there is a > better way? > > I was doing something like > os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where > pubdate has been parsed and stripped of whitespace. I keep getting > an error around the .mp3. > > Any ideas? > The filename referred to by pubdate is a string, and you want to append an extension, also a string, to it. Therefore: os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate + '.mp3') From galois271 at gmail.com Thu Mar 14 14:19:18 2013 From: galois271 at gmail.com (Chuck) Date: Thu, 14 Mar 2013 11:19:18 -0700 (PDT) Subject: Generating Filenames from Feeds In-Reply-To: References: Message-ID: > Seriously, if you don't post a minimal code example that shows the problem and with a full traceback you are asking strangers to do magic tricks for your pleasure. I'm asking more for a better way of generating destination filenames, not so much debugging questions. I only put my attempts there to show people that I was actually trying something, and not just relying on people to do my thinking for me. I'm trying to take a feed such as this http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU and parse some useful data out of it for a destination filename. The solution should be general, and not just for this particular feed. Thanks! From galois271 at gmail.com Thu Mar 14 14:19:18 2013 From: galois271 at gmail.com (Chuck) Date: Thu, 14 Mar 2013 11:19:18 -0700 (PDT) Subject: Generating Filenames from Feeds In-Reply-To: References: Message-ID: > Seriously, if you don't post a minimal code example that shows the problem and with a full traceback you are asking strangers to do magic tricks for your pleasure. I'm asking more for a better way of generating destination filenames, not so much debugging questions. I only put my attempts there to show people that I was actually trying something, and not just relying on people to do my thinking for me. I'm trying to take a feed such as this http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU and parse some useful data out of it for a destination filename. The solution should be general, and not just for this particular feed. Thanks! From steve+comp.lang.python at pearwood.info Thu Mar 14 18:58:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2013 22:58:25 GMT Subject: Generating Filenames from Feeds References: Message-ID: <51425610$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Mar 2013 11:19:18 -0700, Chuck wrote: >> Seriously, if you don't post a minimal code example that shows the >> problem and with a full traceback you are asking strangers to do magic >> tricks for your pleasure. > > I'm asking more for a better way of generating destination filenames, > not so much debugging questions. I only put my attempts there to show > people that I was actually trying something, and not just relying on > people to do my thinking for me. > > I'm trying to take a feed such as this > > http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU > > and parse some useful data out of it for a destination filename. The > solution should be general, and not just for this particular feed. There is no such general solution, because "some useful data" will depend on what you intend to do with it, what the feed is, and what *you* consider "useful". Your earlier approach is probably fine, once you fix the syntax error. -- Steven From affdfsdfdsfsd at b.com Thu Mar 14 14:09:04 2013 From: affdfsdfdsfsd at b.com (Tracubik) Date: Thu, 14 Mar 2013 19:09:04 +0100 Subject: editing a HTML file Message-ID: <51421253$0$26783$4fafbaef@reader2.news.tin.it> Hi all, I'would like to make a script that automatically change some text in a html file. I need to make some changes in the text of

    tags My question is: there is a way to just "update/substitute" the text in the html

    tags or do i have to make a new modified copy of the html file? To be clear, i'ld like to make something like this: open html file for every

    tags: if "foo" in text: change "foo" in "bar" close html file any sample would be really appreciated I'm really a beginner as you can see Thanks From jeanmichel at sequans.com Thu Mar 14 14:18:35 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 14 Mar 2013 19:18:35 +0100 (CET) Subject: editing a HTML file In-Reply-To: <51421253$0$26783$4fafbaef@reader2.news.tin.it> Message-ID: <469122535.4983498.1363285115796.JavaMail.root@sequans.com> ----- Original Message ----- > Hi all, > > I'would like to make a script that automatically change some text in > a > html file. > > I need to make some changes in the text of

    tags > > My question is: there is a way to just "update/substitute" the text > in > the html

    tags or do i have to make a new modified copy of the > html file? > > To be clear, i'ld like to make something like this: > > open html file > for every

    tags: > if "foo" in text: > change "foo" in "bar" > close html file > > any sample would be really appreciated > I'm really a beginner as you can see > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, You can use http://www.crummy.com/software/BeautifulSoup/bs4/doc/#modifying-the-tree Almost all functions have an example. Cheers, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From davea at davea.name Thu Mar 14 21:31:19 2013 From: davea at davea.name (Dave Angel) Date: Thu, 14 Mar 2013 21:31:19 -0400 Subject: editing a HTML file In-Reply-To: <51421253$0$26783$4fafbaef@reader2.news.tin.it> References: <51421253$0$26783$4fafbaef@reader2.news.tin.it> Message-ID: <514279E7.5070408@davea.name> On 03/14/2013 02:09 PM, Tracubik wrote: > Hi all, > > I'would like to make a script that automatically change some text in a > html file. > > I need to make some changes in the text of

    tags > > My question is: there is a way to just "update/substitute" the text in > the html

    tags or do i have to make a new modified copy of the html > file? > > To be clear, i'ld like to make something like this: > > open html file > for every

    tags: > if "foo" in text: > change "foo" in "bar" > close html file > > any sample would be really appreciated > I'm really a beginner as you can see > > Thanks As JM points out, you can use Beautiful Soup to parse html. Then you can make structural changes, and write it back out. Beautiful Soup is NOT part of the standard library. But if you haven't already written something that modifies regular text files, I'd do that long before I even started messing with html. You cannot in general update things in place, so you have to think about the mechanics of updating, and of minimizing or eliminating the likelihood of losing data. For example, suppose you have a text file (created with any text editor) that has just one occurrence of the string "Sammy". You want to replace that with the word "Gazelda". Notice the replacement string is longer than the original. Think about how you'd go about it, and write the simplest program that would accomplish it. Then think about what could go wrong. What about if somebody shuts the machine off just as you're starting to rewrite the file, or the program crashes just then, or whatever ? So plan to write the replacement file to a new name, and after written, do the appropriate renames and delete of the old one. Don't forget about closing each file, especially if you're going to manipulate it with other functions. -- DaveA From redstone-cold at 163.com Fri Mar 15 01:26:50 2013 From: redstone-cold at 163.com (iMath) Date: Thu, 14 Mar 2013 22:26:50 -0700 (PDT) Subject: =?windows-1252?Q?changes_on_windows_registry_doesn=92t_take_effect_im?= =?windows-1252?Q?mediately?= Message-ID: <8f25a1bd-208a-4521-b233-5e26d802ccac@googlegroups.com> changes on windows registry doesn?t take effect immediately I am trying to change IE?s proxy settings by the following 2 code snippets to enable the proxy by this code from winreg import * with OpenKey(HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Internet Settings" ,0, KEY_ALL_ACCESS) as key: SetValueEx(key,"ProxyServer",0, REG_SZ, "127.0.0.1:8087") SetValueEx(key,"ProxyEnable",0, REG_DWORD, 1) SetValueEx(key,"ProxyOverride",0, REG_SZ, "") FlushKey(key) to disable the proxy by this code from winreg import * with OpenKey(HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Internet Settings" ,0, KEY_ALL_ACCESS) as key: DeleteValue(key,"ProxyServer") SetValueEx(key,"ProxyEnable",0, REG_DWORD, 0) DeleteValue(key,"ProxyOverride") FlushKey(key) but the changes on windows registry doesn?t take effect immediately,so is there some way to change the windows registry and let the changes take effect immediately without restarting IE ? BTW ,I use the code on winxp ,and I am going to embed the 2 code snippets in my PyQt application . From steve+comp.lang.python at pearwood.info Fri Mar 15 01:56:39 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2013 05:56:39 GMT Subject: changes on windows registry =?iso-8859-7?q?doesn=A2t?= take effect immediately References: <8f25a1bd-208a-4521-b233-5e26d802ccac@googlegroups.com> Message-ID: <5142b817$0$29965$c3e8da3$5496439d@news.astraweb.com> On Thu, 14 Mar 2013 22:26:50 -0700, iMath wrote: > changes on windows registry doesn?t take effect immediately > > I am trying to change IE?s proxy settings by the following 2 code > snippets [...] > but the changes on windows registry doesn?t take effect immediately,so > is there some way to change the windows registry and let the changes > take effect immediately without restarting IE ? That's an IE question, not a Python question. You might be lucky and have somebody here happen to know the answer, but you'll probably have more luck asking on a group dedicated to Windows and IE. -- Steven From timr at probo.com Fri Mar 15 02:16:46 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 14 Mar 2013 23:16:46 -0700 Subject: changes on windows registry doesn’t take effect immediately References: <8f25a1bd-208a-4521-b233-5e26d802ccac@googlegroups.com> Message-ID: iMath wrote: > >changes on windows registry doesn?t take effect immediately Well, that's not exactly the issue. The registry is being changed immediately. The issue is that IE doesn't check for proxy settings continuously. >but the changes on windows registry doesn?t take effect immediately, so >is there some way to change the windows registry and let the changes >take effect immediately without restarting IE ? No. This is an IE issue, not a registry issue. Other browsers might behave differently. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From theller at ctypes.org Fri Mar 15 06:46:36 2013 From: theller at ctypes.org (Thomas Heller) Date: Fri, 15 Mar 2013 11:46:36 +0100 Subject: Unicode Message-ID: I thought I understand unicode (somewhat, at least), but this seems not to be the case. I expected the following code to print '?m' two times to the console: # -*- coding: cp850 -*- a = u"?m" b = u"\u03bcm" print(a) print(b) But what I get is this: ?m Traceback (most recent call last): File "x.py", line 7, in print(b) File "C:\Python33-64\lib\encodings\cp850.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u03bc' in position 0: character maps to Using (german) windows, command prompt, codepage 850. The same happens with Python 2.7. What am I doing wrong? Thanks, Thomas From steve+comp.lang.python at pearwood.info Fri Mar 15 06:58:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2013 10:58:19 GMT Subject: Unicode References: Message-ID: <5142feca$0$29965$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Mar 2013 11:46:36 +0100, Thomas Heller wrote: > I thought I understand unicode (somewhat, at least), but this seems not > to be the case. > > I expected the following code to print '?m' two times to the console: > > > # -*- coding: cp850 -*- > > a = u"?m" > b = u"\u03bcm" > > print(a) > print(b) > > > But what I get is this: > > > ?m > Traceback (most recent call last): > File "x.py", line 7, in > print(b) > File "C:\Python33-64\lib\encodings\cp850.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u03bc' in > position 0: character maps to > > Using (german) windows, command prompt, codepage 850. > > The same happens with Python 2.7. What am I doing wrong? That's because the two strings are not the same. You can isolate the error by noting that the second one only raises an exception when you try to print it. That suggests that the problem is that it contains a character which is not defined in your terminal's codepage. So let's inspect the strings more carefully: py> a = u"?m" py> b = u"\u03bcm" py> a == b False py> ord(a[0]), ord(b[0]) (181, 956) py> import unicodedata py> unicodedata.name(a[0]) 'MICRO SIGN' py> unicodedata.name(b[0]) 'GREEK SMALL LETTER MU' Does codepage 850 include Greek Small Letter Mu? The evidence suggests it does not. If you can, you should set the terminal's encoding to UTF-8. That will avoid this sort of problem. -- Steven From theller at ctypes.org Fri Mar 15 07:43:49 2013 From: theller at ctypes.org (Thomas Heller) Date: Fri, 15 Mar 2013 12:43:49 +0100 Subject: Unicode In-Reply-To: <5142feca$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <5142feca$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 15.03.2013 11:58, schrieb Steven D'Aprano: > On Fri, 15 Mar 2013 11:46:36 +0100, Thomas Heller wrote: [Windows: Problems with unicode output to console] > You can isolate the error by noting that the second one only raises an > exception when you try to print it. That suggests that the problem is > that it contains a character which is not defined in your terminal's > codepage. So let's inspect the strings more carefully: > > > py> a = u"?m" > py> b = u"\u03bcm" > py> a == b > False > py> ord(a[0]), ord(b[0]) > (181, 956) > py> import unicodedata > py> unicodedata.name(a[0]) > 'MICRO SIGN' > py> unicodedata.name(b[0]) > 'GREEK SMALL LETTER MU' > > Does codepage 850 include Greek Small Letter Mu? The evidence suggests it > does not. > > If you can, you should set the terminal's encoding to UTF-8. That will > avoid this sort of problem. Thanks for the clarification. For the archives: Setting the console codepage to 65001 and the font to lucida console helps. Thomas From duncan.booth at invalid.invalid Fri Mar 15 07:02:49 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Mar 2013 11:02:49 GMT Subject: Unicode References: Message-ID: Thomas Heller wrote: > > ?m > Traceback (most recent call last): > File "x.py", line 7, in > print(b) > File "C:\Python33-64\lib\encodings\cp850.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u03bc' in > position 0: character maps to > > > Using (german) windows, command prompt, codepage 850. > > The same happens with Python 2.7. What am I doing wrong? > They are different characters: >>> repr(a) "u'\\xb5m'" >>> repr(b) "u'\\u03bcm'" a contains unicode MICRO SIGN, b contains GREEK SMALL LETTER MU -- Duncan Booth http://kupuguy.blogspot.com From s.arun316 at gmail.com Fri Mar 15 07:33:05 2013 From: s.arun316 at gmail.com (s.arun316 at gmail.com) Date: Fri, 15 Mar 2013 04:33:05 -0700 (PDT) Subject: Im fetching data from excel using python code.. i could see some junk value also with it. Message-ID: <0fa3b412-b9e8-4312-8cb4-db3ba3b3b2ca@googlegroups.com> Hi im fetching data from excel using python code.. i could see some junk value also with it. like [text:u How to remove it.. below is the code from xlrd import open_workbook from win32com.client import Dispatch book = open_workbook('C:/Users/742123/Desktop/test.xls') sheet0 = book.sheet_by_index(0) #sheet1 = book.sheet_by_index(1) print sheet0.col(0) print sheet0.col(2) print sheet0.col(3) print sheet0.col(4) print sheet0.col(5) print sheet0.col(6) print sheet0.col(7) print sheet0.col(8) print sheet0.col(9) print sheet0.col(10) print sheet0.col(12) print sheet0.col(13) print sheet0.col(14) print sheet0.col(15) print sheet0.col(16) print sheet0.col(17) print sheet0.col(18) print sheet0.col(19) print sheet0.col(20) print sheet0.col(21) print sheet0.col(22) print sheet0.col(23) print sheet0.col(24) print sheet0.col(25) print sheet0.col(26) print sheet0.col(27) From dieter at handshake.de Sat Mar 16 02:50:34 2013 From: dieter at handshake.de (dieter) Date: Sat, 16 Mar 2013 07:50:34 +0100 Subject: Im fetching data from excel using python code.. i could see some junk value also with it. References: <0fa3b412-b9e8-4312-8cb4-db3ba3b3b2ca@googlegroups.com> Message-ID: <87boajaldx.fsf@handshake.de> s.arun316 at gmail.com writes: > Hi im fetching data from excel using python code.. i could see some junk value also with it. like [text:u > > How to remove it.. below is the code It is very difficult to extract data reliably from an undocumented binary format (such as "excel" files): things can change between versions, some "features" may be used only in particular situations difficult to get at by reverse engineering, lacking a complete documentation completeness is difficult to get. I see two options for you: * send a problem report with your data to the "xlrd" author He may know how to fix it. * Tell "excel" to export the file to "csv" and use Python's "csv" mode to read the values. From joel.goldstick at gmail.com Sat Mar 16 15:49:08 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 16 Mar 2013 15:49:08 -0400 Subject: Im fetching data from excel using python code.. i could see some junk value also with it. In-Reply-To: <87boajaldx.fsf@handshake.de> References: <0fa3b412-b9e8-4312-8cb4-db3ba3b3b2ca@googlegroups.com> <87boajaldx.fsf@handshake.de> Message-ID: On Sat, Mar 16, 2013 at 2:50 AM, dieter wrote: > s.arun316 at gmail.com writes: > > > Hi im fetching data from excel using python code.. i could see some junk > value also with it. like [text:u > I used the xlrd module some time back. I think if you google for tutorial on it you will find your answer > > > > How to remove it.. below is the code > > It is very difficult to extract data reliably from an undocumented binary > format (such as "excel" files): things can change between versions, > some "features" may be used only in particular situations > difficult to get at by reverse engineering, > lacking a complete documentation completeness is difficult to get. > This isn't true. The xlrd module takes care of this > > I see two options for you: > > * send a problem report with your data to the "xlrd" author > > He may know how to fix it. > > * Tell "excel" to export the file to "csv" and > use Python's "csv" mode to read the values. > I agree, that this is a simpler aproach > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tinnews at isbd.co.uk Fri Mar 15 07:50:08 2013 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Fri, 15 Mar 2013 11:50:08 +0000 Subject: wxgrid - is there an easy way to set alignment of a column? Message-ID: I'm using wxGrid and finding it fairly straightforward but I can't see an easy way to set the alignment (left, centre, right) for a whole column. There's SetDefaultCellAlignment() which sets the default for the whole grid and there's SetCellAlignment() which sets it for a specific cell but there seems to be no way to set the default alignment for a column. Am I missing something or do I need to do it for individual cells as I load the data? -- Chris Green From ian.g.kelly at gmail.com Fri Mar 15 11:50:41 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 15 Mar 2013 09:50:41 -0600 Subject: wxgrid - is there an easy way to set alignment of a column? In-Reply-To: References: Message-ID: On Fri, Mar 15, 2013 at 5:50 AM, wrote: > I'm using wxGrid and finding it fairly straightforward but I can't see > an easy way to set the alignment (left, centre, right) for a whole > column. > > There's SetDefaultCellAlignment() which sets the default for the whole > grid and there's SetCellAlignment() which sets it for a specific cell > but there seems to be no way to set the default alignment for a column. > > Am I missing something or do I need to do it for individual cells as I > load the data? You can use SetColAttr() to set attributes over a whole column. From tinnews at isbd.co.uk Fri Mar 15 14:29:08 2013 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Fri, 15 Mar 2013 18:29:08 +0000 Subject: wxgrid - is there an easy way to set alignment of a column? References: Message-ID: Ian Kelly wrote: > On Fri, Mar 15, 2013 at 5:50 AM, wrote: > > I'm using wxGrid and finding it fairly straightforward but I can't see > > an easy way to set the alignment (left, centre, right) for a whole > > column. > > > > There's SetDefaultCellAlignment() which sets the default for the whole > > grid and there's SetCellAlignment() which sets it for a specific cell > > but there seems to be no way to set the default alignment for a column. > > > > Am I missing something or do I need to do it for individual cells as I > > load the data? > > You can use SetColAttr() to set attributes over a whole column. Ah, yes, thank you. It's a bit of a long way round though and, in my case I think it's simpler just to use SetCellAlignment(). -- Chris Green From dmitrey15 at gmail.com Fri Mar 15 09:36:03 2013 From: dmitrey15 at gmail.com (dmitrey15 at gmail.com) Date: Fri, 15 Mar 2013 06:36:03 -0700 (PDT) Subject: OpenOpt Suite release 0.45 Message-ID: <9da71e96-66c3-4c28-a207-b18c20704355@googlegroups.com> Hi all, I'm glad to inform you about new OpenOpt Suite release 0.45 (2013-March-15): * Essential improvements for FuncDesigner interval analysis (thus affect solver interalg) * Temporary walkaround for a serious bug in FuncDesigner automatic differentiation kernel due to a bug in some versions of Python or NumPy, may affect optimization problems, including (MI)LP, (MI)NLP, TSP etc * Some other minor bugfixes and improvements --------------------------- Regards, D. http://openopt.org/Dmitrey From stefan_ml at behnel.de Fri Mar 15 10:11:30 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 15 Mar 2013 15:11:30 +0100 Subject: OpenOpt Suite release 0.45 In-Reply-To: <9da71e96-66c3-4c28-a207-b18c20704355@googlegroups.com> References: <9da71e96-66c3-4c28-a207-b18c20704355@googlegroups.com> Message-ID: dmitrey15 at gmail.com, 15.03.2013 14:36: > I'm glad to inform you about new OpenOpt Suite release 0.45 (2013-March-15): > * Essential improvements for FuncDesigner interval analysis (thus affect solver interalg) > * Temporary walkaround for a serious bug in FuncDesigner automatic differentiation kernel due to a bug in some versions of Python or NumPy, may affect optimization problems, including (MI)LP, (MI)NLP, TSP etc > * Some other minor bugfixes and improvements Hi, two comments: 1) You might want to send announcements to the dedicated python-announce mailing list instead of the general Python mailing list. 2) When you send a software release announcement to a mailing list with an audience as broad as python-list or python-announce, don't expect others to already know what you are talking about. It's a good idea (and a nice touch) to add a short and generally understandable (i.e. using no special purpose terminology) paragraph to your announcement that tells readers what the software does and why it would be interesting for them. Usually, that substantially increases the impact of your announcement, because most people will just ignore release announcements that they do not immediately understand, assuming (correctly or incorrectly) that the software is not meant to be used by them. Stefan From shivdhwaj at gmail.com Fri Mar 15 10:10:01 2013 From: shivdhwaj at gmail.com (SHIVDHWAJ PANDEY) Date: Fri, 15 Mar 2013 07:10:01 -0700 (PDT) Subject: About Starting PYTHON Message-ID: Hi, I am new to this and wanted to know how to start python? Which book,website, blog, etc. From rustompmody at gmail.com Fri Mar 15 10:14:18 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 15 Mar 2013 07:14:18 -0700 (PDT) Subject: About Starting PYTHON References: Message-ID: On Mar 15, 7:10?pm, SHIVDHWAJ PANDEY wrote: > Hi, > I am new to this and wanted to know how to start python? > Which book,website, blog, etc. http://docs.python.org/2/tutorial/ From fabiofz at gmail.com Fri Mar 15 12:16:10 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 15 Mar 2013 13:16:10 -0300 Subject: PyDev 2.7.2 Released / Help to keep PyDev alive Message-ID: Hi All, PyDev 2.7.2 has been released and needs help to be kept being developed. Release Highlights ---------------------------- * Updated icons in PyDev to match better a dark theme. * Improved minimap. * Fixed issue copying qualified name when editor is not in the PYTHONPATH. * Removed call home ping from PyDev. * Fixed issue on Ctrl+1 assist to ignore some warning. * Improved comment/uncomment to deal properly with pep8 formatting. Helping PyDev --------------------------- Currently, PyDev is raising funds so that it's development can be continued and a lightweight toolchain for editors inside Eclipse can complement it. Please help keeping PyDev alive! More details can be seen at: http://igg.me/at/liclipse What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ram.nyvasoft at gmail.com Fri Mar 15 12:53:24 2013 From: ram.nyvasoft at gmail.com (ram.nyvasoft at gmail.com) Date: Fri, 15 Mar 2013 09:53:24 -0700 (PDT) Subject: REG PYTHON developer Message-ID: <1f492053-d481-4a4d-9110-daea23995e00@googlegroups.com> urgently looking for python developer for contract opportunity for one our financial client. Location: NYC, NY Contract: 12 Months 4 to 8 years of Developer experience. Excellent coding and design skills. Software that works is reliable, testable and maintainable should be what you do by default. You enjoy writing software and take pride in what you build. SOL proficiency, particularly with PostgreSQL is a plus. Strong communications skills, both written and verbal. Thanks & Regards, Ram i3 Software 100 Wood Avenue South, Suite 105 Iselin, NJ, 08830 (O) 703 953 2828 Think Green: Please consider the environment before printing this e-mail. From brochure at getpython.info Fri Mar 15 13:57:40 2013 From: brochure at getpython.info (PSF Python Brochure Project Team) Date: Fri, 15 Mar 2013 18:57:40 +0100 Subject: PSF Python Brochure available as PDF preview. Last chance to order your ad! Message-ID: <51436114.1090809@getpython.info> The first full format pre-production issues were shown at several Python conferences throughout the last year and caused a lot of excitement among the attendees. The PSF Python Brochure Project has now finished getting all approvals from the content providers, so we can finally publish a PDF preview of the finished brochure for the whole Python community to see. Please visit our website for more information about the brochure project: http://brochure.getpython.info/ This newsletter is also available for online reading: http://brochure.getpython.info/news/newsletter-5-preview-available ======================================================================== Finally: After two years in the making, the Python brochure is now available as PDF preview! ======================================================================== Please download the PDF preview of the Python brochure and have a look: http://brochure.getpython.info/pdf-preview This is your last chance to place your ad in the brochure ========================================================= Your will benefit from reaching out to a fantastic audience, including Python developers, Python users and many people from around the world, who don't yet realize what they are missing. This is your chance as a company to be one of the first to get your name out to these new high potential future Python users. You can present your products and consulting services, or show case your company for recruiting purposes. With over 10,000 printed copies distributed world-wide this is an excellent way to reach out to new customers and developers. As additional benefit, you will also receive a box with high quality printed brochures to directly present to your customers or use for recruiting. Don't miss the opportunity to place your ad in this very first Python image brochure. * Ads ----- The brochure will have an addendum with 2 double pages for ads. You can buy a half page or a full page ad. After production, you will receive a box of around 120 free copies of the printed brochure. We have already sold 6 ads. There is still room for up to 2 half page ads. * Reference Entry ----------------- For Python service and consulting companies, we have added a more affordable option in form of a reference listing with fixed layout on the last two pages of the Python Brochure. Each entry will have a full color logo, space for a one line description of the service and contact details. There is room for 30-40 entries. We have already sold 5 reference entries. There is still room for up to 25-35 reference entries. * Pricing --------- * A half page ad costs EUR 2,650.00 (+ 19% German VAT, if applicable) * A full page ad costs EUR 5,300.00 (+ 19% German VAT, if applicable) * A reference entry can be purchased for EUR 500.00 (+ 19% German VAT, if applicable) * Ad Placement -------------- We follow "first pay, first serve" until all ad slots are booked. Subsequent orders will be placed on a waiting list for the next edition. Individual ad placement is not possible. Deadline for Data & Approval ============================ The deadline for data delivery is April 30 2013. You will receive a professional software proof PDF of your page prior to printing with 2 days left for approval and final corrections. For full technical details regarding data submission, formats and specifications for the ad content, please consult our Ad Guidelines. Ordering Procedure ================== For the order you will be redirected to the secure SSL encrypted site hosted by our production partner evenios publishing. The terms & conditions and data privacy statement for the order are published on encrypted.evenios.com . Please note that the payment is not processed by the PSF! You will receive an invoice issued by evenios publishing, the company producing and distributing the brochure. Order a half page ad -------------------- https://encrypted.evenios.com/en/mediadata/cart/order-forms/ad-sponsorship-order-form-1-2-page Order a full page ad -------------------- https://encrypted.evenios.com/en/mediadata/cart/order-forms/ad-sponsorship-order-form-1-1-page Order a reference entry sponsorship ----------------------------------- https://encrypted.evenios.com/en/mediadata/cart/order-forms/reference-sponsorship-entry-order-form Thanks, -- Marc-Andre Lemburg PSF Vice Chairman / PSF Python Brochure Team ___________________________________________________________________________ >>> Website: http://brochure.getpython.info/ >>> Twitter: https://twitter.com/pythonbrochure >>> EMail: brochure at getpython.info From ppotrebic at box.com Sat Mar 16 03:26:39 2013 From: ppotrebic at box.com (ppotrebic at box.com) Date: Sat, 16 Mar 2013 00:26:39 -0700 (PDT) Subject: sqlite3 - a create of table x fails after dropping table x (only on Windows) Message-ID: <721daa7e-11bf-4ce9-827c-348b0ab28936@googlegroups.com> Interested to understand this problem. It only happens in Windows, not MacOS. Running python 2.7.3. sqlite3 3.7.12. The following script: import sqlite3 table_name = 'table_name' conn = sqlite3.connect('data2.db') c = conn.cursor() sql = 'create table if not exists ' + table_name + ' (id integer)' c.execute(sql) sql = 'drop table ' + table_name c.execute(sql) sql = 'create table if not exists ' + table_name + ' (id integer)' c.execute(sql) sql = 'insert into ' + table_name + ' (id) values (%d)' % 97 c.execute(sql) conn.commit() Fails every other time it is executed. Here's the error: Traceback (most recent call last): File "C:/Users/potrebic/PycharmProjects/play/play.py", line 15, in c.execute(sql) sqlite3.OperationalError: no such table: table_name line 15 is the execute of the 'insert' stmt. If the "if not exists" is removed from line 11, then the scripts works every time. (Note - on MacOS it succeeds every time). From subhabangalore at gmail.com Sat Mar 16 07:42:41 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 16 Mar 2013 04:42:41 -0700 (PDT) Subject: Simple Plot in Python Message-ID: Dear Group, I have two sets of values in probability, like, x=[0.1,0.2,0.3,0.4] and y=[0.2,0.4,0.6,0.8] And I am trying to draw a simple graph with Python. I was trying to draw in Matplotlib but did not find much help. If any one in the room can kindly suggest. Thanking You in Advance, Regards, Subhabrata. From andipersti at gmail.com Sat Mar 16 08:02:33 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Sat, 16 Mar 2013 13:02:33 +0100 Subject: Simple Plot in Python In-Reply-To: References: Message-ID: <20130316130233.1c07eab273eb89744f1f0b01@gmail.com> subhabangalore at gmail.com wrote: >I was trying to draw in Matplotlib but did not find much help. Have you looked already at the homepape for "maptlotlib"?: http://matplotlib.org/index.html There you'll find a tutorial: http://matplotlib.org/users/pyplot_tutorial.html Bye, Andreas From subhabangalore at gmail.com Sat Mar 16 10:04:44 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 16 Mar 2013 07:04:44 -0700 (PDT) Subject: Simple Plot in Python In-Reply-To: References: Message-ID: <020aec7a-1d5a-4d00-8ded-8a1dfa2f3046@googlegroups.com> On Saturday, March 16, 2013 5:12:41 PM UTC+5:30, subhaba... at gmail.com wrote: > Dear Group, > > > > I have two sets of values in probability, like, > > > > x=[0.1,0.2,0.3,0.4] > > and > > y=[0.2,0.4,0.6,0.8] > > > > And I am trying to draw a simple graph with Python. > > > > I was trying to draw in Matplotlib but did not find much help. > > > > If any one in the room can kindly suggest. > > > > Thanking You in Advance, > > Regards, > > Subhabrata. Thanks. I don't know why it slipped my eyes. Regards, Subhabrata. From yoursurrogategod at gmail.com Sat Mar 16 10:53:25 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 07:53:25 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? Message-ID: Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to become more acquainted with the language. However, when I got to page 304 and did my first example: http://bin.cakephp.org/view/1107093008 And this is the error that I'm getting: http://bin.cakephp.org/view/399711843 This is the code that came with the book: http://bin.cakephp.org/view/514822432 What I don't understand is, why am I getting that error? I've done diff -w and the code looks for the most part the same. What am I doing wrong when I put the application together? From rosuav at gmail.com Sat Mar 16 11:08:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 02:08:24 +1100 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: On Sun, Mar 17, 2013 at 1:53 AM, Yves S. Garret wrote: > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > become more acquainted with the language. However, when I got to page 304 and > did my first example: > > http://bin.cakephp.org/view/1107093008 > > And this is the error that I'm getting: > > http://bin.cakephp.org/view/399711843 > > This is the code that came with the book: > > http://bin.cakephp.org/view/514822432 > > > What I don't understand is, why am I getting that error? I've done diff -w > and the code looks for the most part the same. What am I doing wrong when I > put the application together? self.secret_txt.delete(0.0, END) self.secret_txt.delete(0.0, message) Is the second one supposed to be adding text? I'm not familiar with tkinter but that's the line with the error, and it looks a little odd. ChrisA From msirenef at lightbird.net Sat Mar 16 11:10:07 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 16 Mar 2013 11:10:07 -0400 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: <51448B4F.2020503@lightbird.net> On 03/16/2013 10:53 AM, Yves S. Garret wrote: > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > become more acquainted with the language. However, when I got to page 304 and > did my first example: > > http://bin.cakephp.org/view/1107093008 > > And this is the error that I'm getting: > > http://bin.cakephp.org/view/399711843 > > This is the code that came with the book: > > http://bin.cakephp.org/view/514822432 > > > What I don't understand is, why am I getting that error? I've done diff -w > and the code looks for the most part the same. What am I doing wrong when I > put the application together? The error is that indexes are supposed to be integers, instead you have a text string: "That's not the correct password, so I can't s hare the secret with you." -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The existence of any evil anywhere at any time absolutely ruins a total optimism. George Santayana From yoursurrogategod at gmail.com Sat Mar 16 11:16:49 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:16:49 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> On Saturday, March 16, 2013 11:10:07 AM UTC-4, Mitya Sirenef wrote: > On 03/16/2013 10:53 AM, Yves S. Garret wrote: > > > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > > > become more acquainted with the language. However, when I got to page > > 304 and > > > did my first example: > > > > > > http://bin.cakephp.org/view/1107093008 > > > > > > And this is the error that I'm getting: > > > > > > http://bin.cakephp.org/view/399711843 > > > > > > This is the code that came with the book: > > > > > > http://bin.cakephp.org/view/514822432 > > > > > > > > > What I don't understand is, why am I getting that error? I've done > > diff -w > > > and the code looks for the most part the same. What am I doing wrong > > when I > > > put the application together? > > > > > > The error is that indexes are supposed to be integers, instead you have > > a text string: > > > > "That's not the correct password, so I can't s hare the secret with you." > > > > > > -m > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > The existence of any evil anywhere at any time absolutely ruins a total > > optimism. George Santayana *shrug* In the example that I have posted from the book it works just fine. I also used this batch file to help me along. longevity.py pause Hence the question mark over my head at the moment :) . From yoursurrogategod at gmail.com Sat Mar 16 11:16:49 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:16:49 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> On Saturday, March 16, 2013 11:10:07 AM UTC-4, Mitya Sirenef wrote: > On 03/16/2013 10:53 AM, Yves S. Garret wrote: > > > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > > > become more acquainted with the language. However, when I got to page > > 304 and > > > did my first example: > > > > > > http://bin.cakephp.org/view/1107093008 > > > > > > And this is the error that I'm getting: > > > > > > http://bin.cakephp.org/view/399711843 > > > > > > This is the code that came with the book: > > > > > > http://bin.cakephp.org/view/514822432 > > > > > > > > > What I don't understand is, why am I getting that error? I've done > > diff -w > > > and the code looks for the most part the same. What am I doing wrong > > when I > > > put the application together? > > > > > > The error is that indexes are supposed to be integers, instead you have > > a text string: > > > > "That's not the correct password, so I can't s hare the secret with you." > > > > > > -m > > > > > > -- > > Lark's Tongue Guide to Python: http://lightbird.net/larks/ > > > > The existence of any evil anywhere at any time absolutely ruins a total > > optimism. George Santayana *shrug* In the example that I have posted from the book it works just fine. I also used this batch file to help me along. longevity.py pause Hence the question mark over my head at the moment :) . From rosuav at gmail.com Sat Mar 16 11:23:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 02:23:07 +1100 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: On Sun, Mar 17, 2013 at 2:16 AM, Yves S. Garret wrote: > In the example that I have posted from the book it works just fine. Yep, I just checked the book's version again and the difference is clear. Check out the two lines I quoted in my previous post, and look at the corresponding two lines in the book's version. You should see the difference. :) By the way, I like the choice of secret. It lends itself well to a discussion of recursion - how do you live to 99? Live to 98, then be careful. Etcetera. You need just one special case: How do you live to 1? Be born, then be careful. And there you have it, a perfect problem for defining recursion vs iteration, as both can do the job! ChrisA From yoursurrogategod at gmail.com Sat Mar 16 11:34:07 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:34:07 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: On Saturday, March 16, 2013 11:23:07 AM UTC-4, Chris Angelico wrote: > On Sun, Mar 17, 2013 at 2:16 AM, Yves S. Garret > > wrote: > > > In the example that I have posted from the book it works just fine. > > > > Yep, I just checked the book's version again and the difference is > > clear. Check out the two lines I quoted in my previous post, and look > > at the corresponding two lines in the book's version. You should see > > the difference. :) > > > > By the way, I like the choice of secret. It lends itself well to a > > discussion of recursion - how do you live to 99? Live to 98, then be > > careful. Etcetera. You need just one special case: How do you live to > > 1? Be born, then be careful. And there you have it, a perfect problem > > for defining recursion vs iteration, as both can do the job! > > > > ChrisA *facepalm* Yep, I see it :) . Thanks for your help. From yoursurrogategod at gmail.com Sat Mar 16 11:34:07 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:34:07 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: On Saturday, March 16, 2013 11:23:07 AM UTC-4, Chris Angelico wrote: > On Sun, Mar 17, 2013 at 2:16 AM, Yves S. Garret > > wrote: > > > In the example that I have posted from the book it works just fine. > > > > Yep, I just checked the book's version again and the difference is > > clear. Check out the two lines I quoted in my previous post, and look > > at the corresponding two lines in the book's version. You should see > > the difference. :) > > > > By the way, I like the choice of secret. It lends itself well to a > > discussion of recursion - how do you live to 99? Live to 98, then be > > careful. Etcetera. You need just one special case: How do you live to > > 1? Be born, then be careful. And there you have it, a perfect problem > > for defining recursion vs iteration, as both can do the job! > > > > ChrisA *facepalm* Yep, I see it :) . Thanks for your help. From rosuav at gmail.com Sat Mar 16 11:44:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 02:44:10 +1100 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: On Sun, Mar 17, 2013 at 2:34 AM, Yves S. Garret wrote: > *facepalm* > > Yep, I see it :) . Thanks for your help. Glad to be of service. Welcome to a life of programming, where the palm meets the face on a regular basis... more frequently if you use Microsoft Windows, tar, non-eight-bit-clean transmission methods, or Adobe products, and extremely common as soon as you take over someone else's code [1], but inevitable even without these stimuli. :) Have fun! [1] http://www.dilbert.com/strips/comic/2013-02-24/ ChrisA From neilc at norwich.edu Tue Mar 19 10:11:12 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2013 14:11:12 GMT Subject: What am I doing wrong in this simple tkinter example? References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: On 2013-03-16, Chris Angelico wrote: > On Sun, Mar 17, 2013 at 2:34 AM, Yves S. Garret > wrote: >> *facepalm* >> >> Yep, I see it :) . Thanks for your help. > > Glad to be of service. Welcome to a life of programming, where > the palm meets the face on a regular basis... more frequently > if you use Microsoft Windows, tar, non-eight-bit-clean > transmission methods, or Adobe products, and extremely common > as soon as you take over someone else's code [1], but > inevitable even without these stimuli. :) A pretty funny example of this is depicted in the fine film Office Space. -- Neil Cerutti From msirenef at lightbird.net Sat Mar 16 11:48:41 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sat, 16 Mar 2013 11:48:41 -0400 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> References: <1e8ab690-c0e8-464a-ab13-cd109fc15327@googlegroups.com> Message-ID: <51449459.3020807@lightbird.net> On 03/16/2013 11:16 AM, Yves S. Garret wrote: > On Saturday, March 16, 2013 11:10:07 AM UTC-4, Mitya Sirenef wrote: >> On 03/16/2013 10:53 AM, Yves S. Garret wrote: >> >>> Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to >> > become more acquainted with the language. However, when I got to page >> >> 304 and >> >> > did my first example: >> >> > >> >> > http://bin.cakephp.org/view/1107093008 >> >> > >> >> > And this is the error that I'm getting: >> >> > >> >> > http://bin.cakephp.org/view/399711843 >> >> > >> >> > This is the code that came with the book: >> >> > >> >> > http://bin.cakephp.org/view/514822432 >> >> > >> >> > >> >> > What I don't understand is, why am I getting that error? I've done >> >> diff -w >> >> > and the code looks for the most part the same. What am I doing wrong >> >> when I >> >> > put the application together? >> >> >> >> >> >> The error is that indexes are supposed to be integers, instead you have >> >> a text string: >> >> >> >> "That's not the correct password, so I can't s hare the secret with you." >> >> >> >> >> >> -m >> >> >> >> >> >> -- >> >> Lark's Tongue Guide to Python: http://lightbird.net/larks/ >> >> >> >> The existence of any evil anywhere at any time absolutely ruins a total >> >> optimism. George Santayana > *shrug* > > In the example that I have posted from the book it works just fine. I also used > this batch file to help me along. > > longevity.py > pause > > Hence the question mark over my head at the moment :) . You are giving a message to the delete call, but delete call needs an integer to work. In the book, it's not a delete call but an insert call that's why it works there. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From yoursurrogategod at gmail.com Sat Mar 16 11:14:46 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:14:46 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: <1f7985ac-67a7-40ac-bcba-5ee81e832fd7@googlegroups.com> On Saturday, March 16, 2013 11:08:24 AM UTC-4, Chris Angelico wrote: > On Sun, Mar 17, 2013 at 1:53 AM, Yves S. Garret > > wrote: > > > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > > > become more acquainted with the language. However, when I got to page 304 and > > > did my first example: > > > > > > http://bin.cakephp.org/view/1107093008 > > > > > > And this is the error that I'm getting: > > > > > > http://bin.cakephp.org/view/399711843 > > > > > > This is the code that came with the book: > > > > > > http://bin.cakephp.org/view/514822432 > > > > > > > > > What I don't understand is, why am I getting that error? I've done diff -w > > > and the code looks for the most part the same. What am I doing wrong when I > > > put the application together? > > > > self.secret_txt.delete(0.0, END) > > self.secret_txt.delete(0.0, message) > > > > Is the second one supposed to be adding text? I'm not familiar with > > tkinter but that's the line with the error, and it looks a little odd. > > > > ChrisA Yes, the second line is supposed to add the text. From auriocus at gmx.de Sat Mar 16 11:31:20 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 16 Mar 2013 16:31:20 +0100 Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: <1f7985ac-67a7-40ac-bcba-5ee81e832fd7@googlegroups.com> References: <1f7985ac-67a7-40ac-bcba-5ee81e832fd7@googlegroups.com> Message-ID: Am 16.03.13 16:14, schrieb Yves S. Garret: > On Saturday, March 16, 2013 11:08:24 AM UTC-4, Chris Angelico wrote: >> >> self.secret_txt.delete(0.0, END) >> self.secret_txt.delete(0.0, message) >> >> Is the second one supposed to be adding text? I'm not familiar with >> tkinter but that's the line with the error, and it looks a little odd. >> > Yes, the second line is supposed to add the text. > Think about it. "delete" is not going to add text. You want "insert" instead. Christian From yoursurrogategod at gmail.com Sat Mar 16 11:14:46 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 08:14:46 -0700 (PDT) Subject: What am I doing wrong in this simple tkinter example? In-Reply-To: References: Message-ID: <1f7985ac-67a7-40ac-bcba-5ee81e832fd7@googlegroups.com> On Saturday, March 16, 2013 11:08:24 AM UTC-4, Chris Angelico wrote: > On Sun, Mar 17, 2013 at 1:53 AM, Yves S. Garret > > wrote: > > > Hi all, I'm well into "Python Programming for the Absolute Beginner" in order to > > > become more acquainted with the language. However, when I got to page 304 and > > > did my first example: > > > > > > http://bin.cakephp.org/view/1107093008 > > > > > > And this is the error that I'm getting: > > > > > > http://bin.cakephp.org/view/399711843 > > > > > > This is the code that came with the book: > > > > > > http://bin.cakephp.org/view/514822432 > > > > > > > > > What I don't understand is, why am I getting that error? I've done diff -w > > > and the code looks for the most part the same. What am I doing wrong when I > > > put the application together? > > > > self.secret_txt.delete(0.0, END) > > self.secret_txt.delete(0.0, message) > > > > Is the second one supposed to be adding text? I'm not familiar with > > tkinter but that's the line with the error, and it looks a little odd. > > > > ChrisA Yes, the second line is supposed to add the text. From astrojohnr at gmail.com Sat Mar 16 11:28:46 2013 From: astrojohnr at gmail.com (John Rowland) Date: Sat, 16 Mar 2013 08:28:46 -0700 (PDT) Subject: New Python book, "Learn Python Quickly" Message-ID: Hi All, You may be interested in my latest book "Learn Python Quickly". It's a Kindle book but is specifically designed to be used with any of the free-to-download Kindle Reading Apps. What's special about the book is its comprehensive glossary and the numerous in-text internal hyperlinks to topics in the glossary, allowing the reader to quickly jump to glossary topics to clarify the terms used in the text. The book can be followed by those with zero prior knowledge of the language and very little general language experience, but leads the reader in easy stages to quite sophisticated coding skills including classes and Graphical User Interface (GUI) programming. There are numerous graded exercises, all with sample answers at the end of the book. There is also a companion web site from which those programs can be freely copied and used immediately in Python's IDLE interface. (This overcomes the copying restriction imposed on Kindle books.) The programs and lots of Information about the book (including sample chapters and an extract from the glossary) can be found on www.learnpythonquickly.com and the book itself is available from Amazon, from where you can download the reading apps and then download a further sample of the book onto those apps. I do hope you find this of interest. Kind regards, John Rowland From rantingrickjohnson at gmail.com Sat Mar 16 14:27:47 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 16 Mar 2013 11:27:47 -0700 (PDT) Subject: PyWart: NameError trackbacks are superfluous Message-ID: Sometimes many levels of trace messages can be helpful when detecting bugs, however, in the case of NameErrors, these "nuggets" ejected from deep within the bowls of the Python interpreter are nothing more than steaming piles of incomprehensible crap! We don't need multiple layers of traces for NameErrors. Python does not have *real* global variables; and thank Guido for that! All we need to know is which module the error occurred in AND which line of that module contains the offensive lookup of a name that does not exist. ============================================================ Here is a fine example ============================================================ ------------------------------ Contents of mod1.py ------------------------------ print symbolNonExistant ------------------------------ Contents of mod2.py ------------------------------ import mod1 ------------------------------ Contents of mod3.py ------------------------------ import mod2 ============================================================ Results of executing mod3.py ============================================================ Traceback (most recent call last): File "C:/a/b/c/mod3.py", line 2, in import mod2 File "C:/a/b/c/mod2.py", line 1, in import mod1 File "C:/a/b/c/mod1.py", line 2, in print symbolNonExistant NameError: name 'symbolNonExistant' is not defined Why did i need to see all that junk when all i really need to see was this: Traceback (most recent call last): File "C:/a/b/c/mod1.py", line 2, in print symbolNonExistant NameError: name 'symbolNonExistant' is not defined Or event better: NameError: name 'symbolNonExistant' is not defined File "C:/a/b/c/mod1.py", line 2, in print symbolNonExistant From oscar.j.benjamin at gmail.com Sat Mar 16 17:19:34 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 16 Mar 2013 21:19:34 +0000 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: On 16 March 2013 18:27, Rick Johnson wrote: > > Sometimes many levels of trace messages can be helpful when detecting bugs, however, in the case of NameErrors, these "nuggets" ejected from deep within the bowls of the Python interpreter are nothing more than steaming piles of incomprehensible crap! > > We don't need multiple layers of traces for NameErrors. Python does not have *real* global variables; and thank Guido for that! All we need to know is which module the error occurred in AND which line of that module contains the offensive lookup of a name that does not exist. [SNIP] NameErrors can occur conditionally depending on e.g. the arguments to a function. Consider the following script: # tmp.py def broken(x): if x > 2: print(x) else: print(undefined_name) broken(1) When run it gives a NameError with a traceback: $ python tmp.py Traceback (most recent call last): File "tmp3.py", line 8, in broken(1) File "tmp3.py", line 6, in broken print(undefined_name) NameError: global name 'undefined_name' is not defined The traceback shows the arguments passed to the broken function that caused the NameError to be generated. Different arguments would not have generated the NameError. This information can be useful if the logic of the function in question is complicated. It also hints at why you were calling the function and what your code is trying to do. Oscar From rantingrickjohnson at gmail.com Sat Mar 16 18:39:35 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 16 Mar 2013 15:39:35 -0700 (PDT) Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: On Saturday, March 16, 2013 4:19:34 PM UTC-5, Oscar Benjamin wrote: > > NameErrors can occur conditionally depending on e.g. the > arguments to a function. Consider the following script: > > # tmp.py > def broken(x): > if x > 2: > print(x) > else: > print(undefined_name) > > broken(1) Why would anyone write code like that? That's like arming your toilet paper holder with a bomb set to explode if the RPMs of the spinning roll exceed a small threshold. Sure, you could do it, but why the hell would you? The only way your code could be any worse is by picking a random RPM threshold every morning! import random from home.bathroom import ToiletPaperHolder RPMS = range(100) def maybeGoBoom(event): maxRpm = random.choice(RPMS) if event.RPM > maxRpm: roll.explode() tph = ToiletPaperHolder() if not tph.has_roll(): tph.load_roll() roll = tph.get_active_roll() roll.bind("", maybeGoBoom) > The traceback shows the arguments passed to the broken > function that caused the NameError to be generated. > Different arguments would not have generated the > NameError. This information can be useful if the logic of > the function in question is complicated. It also hints at > why you were calling the function and what your code is > trying to do. If you want to observe your code "in action" there are much better ways than eyeball-parsing lines and lines of trackbacks. The code you posted is nonsense, maybe you can provide a better example that will convince me, but that one failed miserably. From oscar.j.benjamin at gmail.com Sat Mar 16 19:29:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 16 Mar 2013 23:29:52 +0000 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: On 16 March 2013 22:39, Rick Johnson wrote: > On Saturday, March 16, 2013 4:19:34 PM UTC-5, Oscar Benjamin wrote: > >> The traceback shows the arguments passed to the broken >> function that caused the NameError to be generated. >> Different arguments would not have generated the >> NameError. This information can be useful if the logic of >> the function in question is complicated. It also hints at >> why you were calling the function and what your code is >> trying to do. > > If you want to observe your code "in action" there are much better ways than eyeball-parsing lines and lines of trackbacks. The code you posted is nonsense, maybe you can provide a better example that will convince me, but that one failed miserably. I wasn't looking to convince *you*, just to set the record straight that this behaviour is sometimes useful. In any case, even when the traceback information is not helpful, printing it is really not a problem and hardly a "wart". Oscar From python.list at tim.thechases.com Sat Mar 16 19:36:15 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Mar 2013 18:36:15 -0500 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: <20130316183615.7d72b3c2@bigbox.christie.dr> On 2013-03-16 15:39, Rick Johnson wrote: > On Saturday, March 16, 2013 4:19:34 PM UTC-5, Oscar Benjamin wrote: > > # tmp.py > > def broken(x): > > if x > 2: > > print(x) > > else: > > print(undefined_name) > > > > broken(1) > > Why would anyone write code like that? Because, in the real world, that example looks something like def broken(intelligence_level): if intelligence_level < 100: return dumb_down(intellegence_level) else: return make_harder(intelligence_level) broken(op.iq) Pylint, pyflakes or some other such linter should catch it, but this happens ALL THE TIME in actual development, occasionally leaking into production. -tkc From rosuav at gmail.com Sat Mar 16 19:48:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 10:48:23 +1100 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <20130316183615.7d72b3c2@bigbox.christie.dr> References: <20130316183615.7d72b3c2@bigbox.christie.dr> Message-ID: On Sun, Mar 17, 2013 at 10:36 AM, Tim Chase wrote: > Because, in the real world, that example looks something like > > def broken(intelligence_level): > if intelligence_level < 100: > return dumb_down(intellegence_level) > else: > return make_harder(intelligence_level) > broken(op.iq) > > Pylint, pyflakes or some other such linter should catch it, but this > happens ALL THE TIME in actual development, occasionally leaking into > production. That's actually an argument in favour of declared variables. NameError becomes a parse-time failure :) ChrisA From rantingrickjohnson at gmail.com Sat Mar 16 19:50:00 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 16 Mar 2013 16:50:00 -0700 (PDT) Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: <509678b5-d3a8-4043-96b6-8e70690e353b@googlegroups.com> On Saturday, March 16, 2013 6:29:52 PM UTC-5, Oscar Benjamin wrote: > I wasn't looking to convince *you*, just to set the record > straight that this behaviour is sometimes useful. And you claim to "set the record strait" by posting code that *purposely* raises a NameError when some function parameter is not within a predefined range? That's ludicrous! Look, i don't want you to think that i am arguing with you, i just want you to show us an example that proves your argument to be true; but you cannot prove the argument by doing foolish things. Imagine the following scenario: * CarMakerA claims their new automobile is safest on the road. * CarMakerB purposely drives the car into a ditch and then claims the car is unsafe and CarMakerA is a liar. That's what your example just did! Please provide a "real world" example that proves your argument. I am open to changing my mind *IF* someone can provide proof. > In any case, even when the traceback information is not > helpful, printing it is really not a problem and hardly a > "wart". * Warts are ugly * Superfluous trackbacks are not only ugly, they damage productivity. Therefore this *IS* a wart. From rosuav at gmail.com Sat Mar 16 20:00:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 11:00:10 +1100 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <509678b5-d3a8-4043-96b6-8e70690e353b@googlegroups.com> References: <509678b5-d3a8-4043-96b6-8e70690e353b@googlegroups.com> Message-ID: On Sun, Mar 17, 2013 at 10:50 AM, Rick Johnson wrote: > * Superfluous trackbacks are not only ugly, they damage > productivity. Extraordinary claims require extraordinary evidence. Start evidencing. ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 16 19:48:01 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2013 23:48:01 GMT Subject: PyWart: NameError trackbacks are superfluous References: Message-ID: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Mar 2013 21:19:34 +0000, Oscar Benjamin wrote: > On 16 March 2013 18:27, Rick Johnson > wrote: >> >> Sometimes many levels of trace messages can be helpful when detecting >> bugs, however, in the case of NameErrors, these "nuggets" ejected from >> deep within the bowls of the Python interpreter are nothing more than >> steaming piles of incomprehensible crap! >> >> We don't need multiple layers of traces for NameErrors. Python does not >> have *real* global variables; and thank Guido for that! All we need to >> know is which module the error occurred in AND which line of that >> module contains the offensive lookup of a name that does not exist. > [SNIP] /head-desk Is Rick still pushing these stupid "PyWart" ideas? > NameErrors can occur conditionally depending on e.g. the arguments to a > function. Consider the following script: [...] Correct, although in your example, simply pointing at the relevant line of code is enough to establish the error. But that's an easy case. Tracebacks aren't printed because you need them to fix the easy bugs. Tracebacks are printed so you have a hope of fixing the hard bugs. NameError is no different in this than any other exception, and the Zen applies: Special cases aren't special enough to break the rules. NameErrors are exceptions like any other. They aren't special enough to suppress the full traceback when a NameError occurs. In the easy cases, you can just ignore the full traceback, and no harm is done. In the hard cases, you will need it. Since name bindings ("variables") in Python are dynamic, not static, whether or not a name exists at any time can depend *when* and *how* you call a line of code, not just which line of code. That is, whether or not a line of code will raise NameError can depend on which lines of code are called before it, and that depends on the function call chain shown by the traceback. Here's a truly trivial case where code will succeed or fail depending on the order of function calls. def display(): print("spam = %d" % spam) def start(): global spam spam = 23 def stop(): global spam del spam def run(): print("*** Succeeds ***") start() display() stop() def fail(): print("*** Fails ***") start() stop() display() run() fail() It's not enough to know that the print line in display() fails, because that's merely the side-effect. The actual problem occurs in the caller, fail(). If NameError suppressed the traceback, that would be more difficult to solve. -- Steven From rosuav at gmail.com Sat Mar 16 19:59:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 10:59:17 +1100 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 17, 2013 at 10:48 AM, Steven D'Aprano wrote: > Here's a truly trivial case where code will succeed or fail depending on > the order of function calls. > (chop code) > It's not enough to know that the print line in display() fails, because > that's merely the side-effect. The actual problem occurs in the caller, > fail(). If NameError suppressed the traceback, that would be more > difficult to solve. A good example. It would be logically equivalent to set spam=None in stop(), and nobody would expect the TypeError to omit the traceback, so why should delling the name be any different? ChrisA From rantingrickjohnson at gmail.com Sat Mar 16 20:11:48 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 16 Mar 2013 17:11:48 -0700 (PDT) Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> On Saturday, March 16, 2013 6:48:01 PM UTC-5, Steven D'Aprano wrote: > On Sat, 16 Mar 2013 21:19:34 +0000, Oscar Benjamin wrote: > > [...] > > NameErrors can occur conditionally depending on e.g. the > > arguments to a function. Consider the following script: > [...] > > Correct, although in your example, simply pointing at the > relevant line of code is enough to establish the error. EXACTLY! > [...] > Here's a truly trivial case where code will succeed or > fail depending on the order of function calls. > > def display(): > print("spam = %d" % spam) > > def start(): > global spam > spam = 23 > > def stop(): > global spam > del spam > > def run(): > print("*** Succeeds ***") > start() > display() > stop() > > def fail(): > print("*** Fails ***") > start() > stop() > display() > > run() > > fail() > > It's not enough to know that the print line in display() > fails, because that's merely the side-effect. The actual > problem occurs in the caller, fail(). No, the "ACTUAL PROBLEM" is in the author. Who would be stupid enough to write code that depends on globals that *may* or *may not* exist, and then go an add insult to injury by not testing for the name before executing the code? Your example is a fine example of why using globals is foolish. Congratulations Steven, you drove the car into the ditch -- even a noob can do that! From torriem at gmail.com Sat Mar 16 21:58:41 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 16 Mar 2013 19:58:41 -0600 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> Message-ID: <51452351.9060704@gmail.com> On 03/16/2013 06:11 PM, Rick Johnson wrote: > No, the "ACTUAL PROBLEM" is in the author. Surely any NameException can also be blamed on the author then, by your logic? From steve+comp.lang.python at pearwood.info Sat Mar 16 23:14:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2013 03:14:20 GMT Subject: PyWart: NameError trackbacks are superfluous References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> Message-ID: <5145350b$0$29965$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Mar 2013 19:58:41 -0600, Michael Torrie wrote: > On 03/16/2013 06:11 PM, Rick Johnson wrote: >> No, the "ACTUAL PROBLEM" is in the author. > > Surely any NameException can also be blamed on the author then, by your > logic? Any exception at all is obviously the author's fault. I propose that Python stops wasting our time with debugging information and tracebacks, and on any error, simply prints the following message then dump core: PEBKACError: Programmer is an idiot. You did something wrong, you moron, turn your computer off, you're obviously too stupid to program. That will certainly improve productivity. -- Steven From rosuav at gmail.com Sat Mar 16 23:19:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Mar 2013 14:19:27 +1100 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <5145350b$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> <5145350b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 17, 2013 at 2:14 PM, Steven D'Aprano wrote: > On Sat, 16 Mar 2013 19:58:41 -0600, Michael Torrie wrote: > >> On 03/16/2013 06:11 PM, Rick Johnson wrote: >>> No, the "ACTUAL PROBLEM" is in the author. >> >> Surely any NameException can also be blamed on the author then, by your >> logic? > > Any exception at all is obviously the author's fault. I propose that > Python stops wasting our time with debugging information and tracebacks, > and on any error, simply prints the following message then dump core: > > > PEBKACError: Programmer is an idiot. You did something wrong, you moron, > turn your computer off, you're obviously too stupid to program. > > > That will certainly improve productivity. Why dump core? That seems far too useful to fit with the rest of your proposal. Just exit 0 - after all, it wasn't Python's fault, so it obviously succeeded. ChrisA From benjamin.kaplan at case.edu Sun Mar 17 00:13:51 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 16 Mar 2013 21:13:51 -0700 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: <5145350b$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <514504b1$0$29965$c3e8da3$5496439d@news.astraweb.com> <8d5de6ba-5f7b-44ea-8525-cb20a88344eb@googlegroups.com> <5145350b$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 16, 2013 at 8:14 PM, Steven D'Aprano wrote: > On Sat, 16 Mar 2013 19:58:41 -0600, Michael Torrie wrote: > >> On 03/16/2013 06:11 PM, Rick Johnson wrote: >>> No, the "ACTUAL PROBLEM" is in the author. >> >> Surely any NameException can also be blamed on the author then, by your >> logic? > > Any exception at all is obviously the author's fault. I propose that > Python stops wasting our time with debugging information and tracebacks, > and on any error, simply prints the following message then dump core: > > > PEBKACError: Programmer is an idiot. You did something wrong, you moron, > turn your computer off, you're obviously too stupid to program. > > > That will certainly improve productivity. > > -- > Steven Don't have it dump core. Have it print a pink slip to the default printer. From jason.swails at gmail.com Sun Mar 17 17:22:39 2013 From: jason.swails at gmail.com (Jason Swails) Date: Sun, 17 Mar 2013 17:22:39 -0400 Subject: PyWart: NameError trackbacks are superfluous In-Reply-To: References: Message-ID: On Sat, Mar 16, 2013 at 2:27 PM, Rick Johnson wrote: > > [snip junk] > We don't need multiple layers of traces for NameErrors. Python does not > have *real* global variables; and thank Guido for that! All we need to know > is which module the error occurred in AND which line of that module > contains the offensive lookup of a name that does not exist. > [snip more junk] 2 comments here. 1) Where's the consistency?? NameError is an exception. All other exceptions get full tracebacks. A NameError is not special enough to deserve special treatment (zen of Python? PEP 8? I don't remember). If you like the full traceback (like I do), it's there. If you just want the error, look at the last frame only. ==== Example where you want a full traceback ==== Pyflakes doesn't catch all NameErrors. If you don't set all of an object's possible attributes inside its constructor, but some are applied later-on (i.e., when they are needed, like in some sort of specialized setup routine that you only call in certain circumstances), then you can benefit from a full traceback even for a NameError. Consider the DataSet class below: import numpy as np from scipy.stats.kde import gaussian_kde as kde class DataSet(object): def __init__(self, data): self._dataset = np.asarray(data) def setup_kde(self): "Set up KDE. Do not do by default since it is expensive for large data sets" self.kde = kde(self._dataset) def resampled(self): return DataSet(self.kde.resample()) In this case generating the KDE can become time- and RAM-consuming for large data sets, so it's worthwhile to only generate the KDE if you actually plan on doing something with that requires it. If you call resampled before setup_kde, you get a NameError, and it would be helpful to have the full traceback when debugging. Yes, you can get around having the 'non-trivial' NameError, but having the full traceback if someone _did_ write code like this makes your job a hell of a lot easier to debug if you don't have to go stack tracing yourself. And for a large project with multiple coders that is built in stages and has functionality added as it's needed, this type of situation is not at all unusual. While one approach is to take to the (email) streets and proclaim how incompetent all coders that came before you truly were and that such a project is not worth modifying in view of their ineptitude, the approach that does _not_ lead to your firing would benefit from a full NameError traceback. Go ahead and fire away about how stupid I am for the suggestion anyway, though. 2) Fine. You don't like long tracebacks for NameErrors, write a 8-line module that you import at the top of every program (like division from __future__ if you work with Python 2 like I have to): --- file ricksstupididea.py --- import sys, traceback def excepthook(exctype, value, tb): if exctype is NameError: print 'Traceback (only printing last frame):' print ' File "%s", line %d, in %s\n %s' % traceback.extract_tb(tb).pop() print 'NameError: %s' % value else: sys.__excepthook__(exctype, value, tb) sys.excepthook = excepthook --- end ricksstupididea.py --- Once you do this, you get your special behavior for NameErrors like you want. Observe, padawan: -- begin nameerror.py -- import ricksstupididea def func1(x): return func2(x) def func2(x): return func3(x) def func3(x): return func4(x) def func4(x): return noname func1(1) $ python noname.py Traceback (only printing last frame): File "noname.py", line 12, in func4 return noname NameError: global name 'noname' is not defined -- begin divzero.py -- import ricksstupididea def func1(x): return func2(x) def func2(x): return func3(x) def func3(x): return func4(x) def func4(x): return x / 0 func1(1) $ python divzero.py Traceback (most recent call last): File "divzero.py", line 14, in func1(1) File "divzero.py", line 3, in func1 return func2(x) File "divzero.py", line 6, in func2 return func3(x) File "divzero.py", line 9, in func3 return func4(x) File "divzero.py", line 12, in func4 return x / 0 ZeroDivisionError: integer division or modulo by zero GvR's time machine strikes again. The only bad thing about this approach is that you have to actually write that extra 8 lines of code, and I get to keep the behavior I like rather than being forced into the (inconsistent) behavior you would prefer I use instead. But since the 8 lines has been provided to you here free of charge, the only real cost for you is how I like my NameErrors given to me. I hereby leave you enlightened. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoursurrogategod at gmail.com Sat Mar 16 18:11:36 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sat, 16 Mar 2013 15:11:36 -0700 (PDT) Subject: Having a hard time installing pygame on Win7. Message-ID: Hi all, got a small problem. As I'm going through "Python Programming for the Absolute Beginner", I got to chapter 11 and as I'm working through it, I can't seem to get pygame/livewires installed... I don't even know how to go about installing it (the book is skimpy on details). I'm using Python 3.3.0 for the job. Has anyone else had the same problems? From missive at hotmail.com Sat Mar 16 20:12:59 2013 From: missive at hotmail.com (Lee Harr) Date: Sun, 17 Mar 2013 04:42:59 +0430 Subject: [ANNC] pynguin-0.13 python turtle graphics application now uses python 3 Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release ports Pynguin to Python 3. Pynguin is tested with Python 3.2.3 and PyQt 4.9.3 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.13: ??? Now uses (requires) Python 3 ??????? - Tested with Python 3.2.3 ??? Important fixes ??????? - New approach for threading of user code ??????????? - should provide safer, more reliable, termination of user code ??????????? - can now reliably stop code like ... while 1: pass ??????? - Preserves fill state and color when changing avatar ??? Other fixes ??????? - Preserves name label when changing avatar ??????? - Tries harder to go as fast as possible for "instant" setting ??????????? - throttles back on CPU when not running user code ??? Pynguin API ??????? - Logo-mode coordinates and angles now available ??????????? - Switch mode using Pynguin -> Mode -> Logo ??????????? - or create new instance with mlogo=ModeLogo() ??????? - Python turtle-mode coordinates and angles now available ??????????? - Switch mode using Pynguin -> Mode -> Turtle ??????????? - or create new instance with mturtle=ModeTurtle() ??????? - xy(x, y) re-uses goto(x, y) code ??????? - xyh() uses xy() and h() to retrieve values ??????? - color() takes an optional alpha channel value for transparency ??????????? - color('ralpha') chooses a random color with random alpha ??????? - Each pynguin's speed can now be set individually ??? Canvas ??????? - Added a dialog for pen, background, and fill default colors ??????????? - sets these colors on program startup ??????????? - uses these colors for reset() ??????????? - also used when adding new pynguins ??????? - Can now track any pynguin ??????? - Can zoom to fit entire drawing ??? UI ??????? - Added new Pynguin menu for avatar and mode selection ??????? - Added alpha value selector to pen and fill color dialogs ??? Integrated Editor ??? Integrated Console ??? Examples ??????? - All ported to Python 3 ??????? - Added examples using colors with alpha channel values ??????? - Added finish line to horserace From pengyu.ut at gmail.com Sun Mar 17 00:52:42 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Sat, 16 Mar 2013 23:52:42 -0500 Subject: How to automatically get the indent level from code? Message-ID: Hi, I want to get the indent level within the code. For example, I want to print 1 within the while loop as the line is indented 1 level. Is it possible to get it within python? while 1: #print the level of indent, which is 1 here. -- Regards, Peng From rodrick.brown at gmail.com Sun Mar 17 01:34:05 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sun, 17 Mar 2013 01:34:05 -0400 Subject: How to automatically get the indent level from code? In-Reply-To: References: Message-ID: No On Sun, Mar 17, 2013 at 12:52 AM, Peng Yu wrote: > Hi, > > I want to get the indent level within the code. For example, I want to > print 1 within the while loop as the line is indented 1 level. Is it > possible to get it within python? > > while 1: > #print the level of indent, which is 1 here. > > -- > Regards, > Peng > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mshroyer at awaredigital.com Sun Mar 17 02:23:31 2013 From: mshroyer at awaredigital.com (Mark Shroyer) Date: Sun, 17 Mar 2013 02:23:31 -0400 Subject: How to automatically get the indent level from code? In-Reply-To: References: Message-ID: <777767EA52AB47418B1C3D05502A87C622B16C283D@awareexchange1> I realize this isn't yet precisely what you're asking for, but look at the inspect and ast modules: import ast, inspect def indent_level(): lineno = inspect.currentframe().f_back.f_lineno with open(__file__) as source_file: tree = ast.parse(source_file.read(), filename=__file__) for node in ast.walk(tree): if hasattr(node, 'lineno') and node.lineno == lineno: return node.col_offset def example_usage(): print("first indent_level() = {0}".format(indent_level())) if True: print("second indent_level() = {0}".format(indent_level())) if __name__ == '__main__': example_usage() The indent_level function above returns the textual column offset rather than the logical block level you're asking for, e.g.: first indent_level() = 4 second indent_level() = 8 But hopefully it's a start. Mark -----Original Message----- From: Python-list [mailto:python-list-bounces+mshroyer=awaredigital.com at python.org] On Behalf Of Peng Yu Sent: Sunday, March 17, 2013 12:53 AM To: python-list at python.org Subject: How to automatically get the indent level from code? Hi, I want to get the indent level within the code. For example, I want to print 1 within the while loop as the line is indented 1 level. Is it possible to get it within python? while 1: #print the level of indent, which is 1 here. -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list From pengyu.ut at gmail.com Mon Mar 18 10:47:02 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 18 Mar 2013 09:47:02 -0500 Subject: How to automatically get the indent level from code? In-Reply-To: <777767EA52AB47418B1C3D05502A87C622B16C283D@awareexchange1> References: <777767EA52AB47418B1C3D05502A87C622B16C283D@awareexchange1> Message-ID: On Sun, Mar 17, 2013 at 1:23 AM, Mark Shroyer wrote: > I realize this isn't yet precisely what you're asking for, but look at the inspect and ast modules: > > import ast, inspect > > def indent_level(): > lineno = inspect.currentframe().f_back.f_lineno > > with open(__file__) as source_file: > tree = ast.parse(source_file.read(), filename=__file__) > > for node in ast.walk(tree): > if hasattr(node, 'lineno') and node.lineno == lineno: > return node.col_offset > > def example_usage(): > print("first indent_level() = {0}".format(indent_level())) > if True: > print("second indent_level() = {0}".format(indent_level())) > > if __name__ == '__main__': > example_usage() > > The indent_level function above returns the textual column offset rather than the logical block level you're asking for, e.g.: > > first indent_level() = 4 > second indent_level() = 8 > > But hopefully it's a start. Thanks. I try to run it from stdin. Obviously, it does not work. The problem is the stdin can not be read again. Is there a way to extend the code that indentation can be computed even the code is from stdin? ~/linux/test/python/tricks/indent_level$ python - < main.py Traceback (most recent call last): File "", line 23, in File "", line 16, in example_usage File "", line 8, in indent_level IOError: [Errno 2] No such file or directory: '' ~/linux/test/python/tricks/indent_level$ cat main.py #!/usr/bin/env python import ast, inspect def indent_level(): lineno = inspect.currentframe().f_back.f_lineno with open(__file__) as source_file: tree = ast.parse(source_file.read(), filename=__file__) for node in ast.walk(tree): if hasattr(node, 'lineno') and node.lineno == lineno: return node.col_offset def example_usage(): print indent_level() #print("first indent_level() = {0}".format(indent_level())) if True: print indent_level() #print("second indent_level() = {0}".format(indent_level())) if __name__ == '__main__': example_usage() -- Regards, Peng From rustompmody at gmail.com Sun Mar 17 04:54:37 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 17 Mar 2013 01:54:37 -0700 (PDT) Subject: pynguin-0.13 python turtle graphics application now uses python 3 References: Message-ID: On Mar 17, 5:12?am, Lee Harr wrote: > Pynguin is a python-based turtle graphics application. > ??? It combines an editor, interactive interpreter, and > ??? graphics display area. What does pynguin have that the builting python turtle does not? http://docs.python.org/2/library/turtle.html From missive at hotmail.com Sun Mar 17 18:28:11 2013 From: missive at hotmail.com (Lee Harr) Date: Mon, 18 Mar 2013 02:58:11 +0430 Subject: pynguin-0.13 python turtle graphics application now uses python 3 Message-ID: >> Pynguin is a python-based turtle graphics application. >> ? ? It combines an editor, interactive interpreter, and >> ? ? graphics display area. > > > What does pynguin have that the builtin python turtle does not? It is meant to be easier to get started with. You start the application and it is all ready to go with the basic turtle-style commands pulled in to the local namespace. It also has some nice added features: Many commands are available from menus. The equivalent ? ? python is copied to the interpreter to help students discover ? ? and learn how to write the code. The canvas can be panned and zoomed with the mouse. I just posted a quick hack on edu-sig for exporting the canvas as svg. All colors (except the background) can have alpha channels. If you are a fan of turtle.py please give pynguin a try and let me know what you think! From rustompmody at gmail.com Mon Mar 18 00:18:45 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 17 Mar 2013 21:18:45 -0700 (PDT) Subject: pynguin-0.13 python turtle graphics application now uses python 3 References: Message-ID: On Mar 18, 3:28?am, Lee Harr wrote: > If you are a fan of turtle.py please give pynguin a try and let me > know what you think! Not a 'fan' per se -- just a teacher who has occasionally tried turtle to introduce programming. (which was not completely smooth; Ive forgotten all the hiccups) http://mail.python.org/pipermail/python-list/2011-May/604698.html From vonpupp at gmail.com Sun Mar 17 09:18:16 2013 From: vonpupp at gmail.com (Albert Vonpupp) Date: Sun, 17 Mar 2013 06:18:16 -0700 (PDT) Subject: Top 10 python features Message-ID: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> Hello pythonistas, I'm new to python and so far I'm really enjoying learning it. I would like to know what are the top 10 most important features (on your opinion) in python. I have to prepare a presentation on that and this is a very good chance to learn something new to me as well. Thanks a lot! From miki.tebeka at gmail.com Sun Mar 17 10:00:26 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 17 Mar 2013 07:00:26 -0700 (PDT) Subject: Top 10 python features In-Reply-To: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> Message-ID: <443069b7-2657-48ae-8f37-6c692a9dd508@googlegroups.com> > I would like to know what are the top 10 most important features (on your opinion) in python. You're in luck :) Raymond Hettinger just gave "Python is Awesome" keynote at PyCon. You can view the slides at https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome, video will follow - not sure when. From tjreedy at udel.edu Sun Mar 17 20:26:42 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Mar 2013 20:26:42 -0400 Subject: Top 10 python features In-Reply-To: <443069b7-2657-48ae-8f37-6c692a9dd508@googlegroups.com> References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> <443069b7-2657-48ae-8f37-6c692a9dd508@googlegroups.com> Message-ID: On 3/17/2013 10:00 AM, Miki Tebeka wrote: >> I would like to know what are the top 10 most important features >> (on your opinion) in python. > You're in luck :) Raymond Hettinger just gave "Python is Awesome" > keynote at PyCon. You can view the slides at > https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome, > video will follow - not sure when. The full url works better ;-). https://speakerdeck.com/pyconslides/pycon-keynote-python-is-awesome-by-raymond-hettinger I am part way through and recommend it. -- Terry Jan Reedy From __peter__ at web.de Sun Mar 17 10:09:29 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Mar 2013 15:09:29 +0100 Subject: Top 10 python features References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> Message-ID: Albert Vonpupp wrote: > Hello pythonistas, > > I'm new to python and so far I'm really enjoying learning it. > > I would like to know what are the top 10 most important features (on your > opinion) in python. > > I have to prepare a presentation on that and this is a very good chance to > learn something new to me as well. Amongst our weapons are - Generators - Duck-Typing - The Interactive Interpreter and an almost fanatical devotion to the Zen. Wait, I forgot dictionaries; it's dictionaries all the way down... From rosuav at gmail.com Sun Mar 17 10:21:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Mar 2013 01:21:45 +1100 Subject: Top 10 python features In-Reply-To: References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> Message-ID: On Mon, Mar 18, 2013 at 1:09 AM, Peter Otten <__peter__ at web.de> wrote: > Albert Vonpupp wrote: > >> I would like to know what are the top 10 most important features (on your >> opinion) in python. > > Amongst our weapons are > > - Generators > - Duck-Typing > - The Interactive Interpreter > > and an almost fanatical devotion to the Zen. > > Wait, I forgot dictionaries; it's dictionaries all the way down... That's five. Here's five more: * No variable declarations - keep your code simple * An *extensive* standard library * comp.lang.python / python-list, Python help 24/7! * Active development and constant improvements * Strong OS/platform support (many Linuxes have at least some version of Python either already installed or in the standard repository; Windows and Mac OS have ready-to-go binaries available on python.org; there are Pythons for various mobile platforms; even relative obscurities like OS/2 have their ports) Hmm. Side point regarding OS/2: I notice that http://www.python.org/getit/other/ points to a port of 2.4.4, but Paul Smedley has a port of 2.7.2: http://smedley.id.au/os2ports_new/index.php?page=python - what's the appropriate way to get that mentioned? ChrisA From joeclark77 at hotmail.com Sun Mar 17 13:49:27 2013 From: joeclark77 at hotmail.com (Joseph Clark) Date: Sun, 17 Mar 2013 10:49:27 -0700 Subject: Top 10 python features In-Reply-To: References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com>, , Message-ID: I'm a Python newbie and already found a few things that I love about the language. Among them: - list/set comprehensions - dictionaries and sets - pickle/shelve // joseph w. clark , phd , visiting research associate \\ university of nebraska at omaha - college of IS&T ---------------------------------------- > Date: Mon, 18 Mar 2013 01:21:45 +1100 > Subject: Re: Top 10 python features > From: rosuav at gmail.com > To: python-list at python.org > > On Mon, Mar 18, 2013 at 1:09 AM, Peter Otten <__peter__ at web.de> wrote: > > Albert Vonpupp wrote: > > > >> I would like to know what are the top 10 most important features (on your > >> opinion) in python. > > > > Amongst our weapons are > > > > - Generators > > - Duck-Typing > > - The Interactive Interpreter > > > > and an almost fanatical devotion to the Zen. > > > > Wait, I forgot dictionaries; it's dictionaries all the way down... > > That's five. Here's five more: > > * No variable declarations - keep your code simple > * An *extensive* standard library > * comp.lang.python / python-list, Python help 24/7! > * Active development and constant improvements > * Strong OS/platform support (many Linuxes have at least some version > of Python either already installed or in the standard repository; > Windows and Mac OS have ready-to-go binaries available on python.org; > there are Pythons for various mobile platforms; even relative > obscurities like OS/2 have their ports) > > Hmm. Side point regarding OS/2: I notice that > http://www.python.org/getit/other/ points to a port of 2.4.4, but Paul > Smedley has a port of 2.7.2: > http://smedley.id.au/os2ports_new/index.php?page=python - what's the > appropriate way to get that mentioned? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list From vonpupp at gmail.com Wed Mar 20 18:55:07 2013 From: vonpupp at gmail.com (Albert Vonpupp) Date: Wed, 20 Mar 2013 15:55:07 -0700 (PDT) Subject: Top 10 python features In-Reply-To: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> Message-ID: <720fd948-0243-441c-9350-780ce2217446@googlegroups.com> On Sunday, March 17, 2013 10:18:16 AM UTC-3, Albert Vonpupp wrote: > Hello pythonistas, > > > > I'm new to python and so far I'm really enjoying learning it. > > > > I would like to know what are the top 10 most important features (on your opinion) in python. > > > > I have to prepare a presentation on that and this is a very good chance to learn something new to me as well. > > > > Thanks a lot! I want to thank you all for your responses! Regards! From breamoreboy at yahoo.co.uk Wed Mar 20 19:48:07 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 20 Mar 2013 23:48:07 +0000 Subject: Top 10 python features In-Reply-To: <720fd948-0243-441c-9350-780ce2217446@googlegroups.com> References: <35e9c045-f835-487c-a9a1-9171151ada75@googlegroups.com> <720fd948-0243-441c-9350-780ce2217446@googlegroups.com> Message-ID: On 20/03/2013 22:55, Albert Vonpupp wrote: > On Sunday, March 17, 2013 10:18:16 AM UTC-3, Albert Vonpupp wrote: >> Hello pythonistas, >> >> >> >> I'm new to python and so far I'm really enjoying learning it. >> >> >> >> I would like to know what are the top 10 most important features (on your opinion) in python. >> >> >> >> I have to prepare a presentation on that and this is a very good chance to learn something new to me as well. >> >> >> >> Thanks a lot! > > I want to thank you all for your responses! > > Regards! > Thanks for the thanks. If you wish to participate further would you be kind enough to read this http://wiki.python.org/moin/GoogleGroupsPython -- Cheers. Mark Lawrence From nicktwain at gmail.com Sun Mar 17 10:04:18 2013 From: nicktwain at gmail.com (Nic) Date: Sun, 17 Mar 2013 07:04:18 -0700 (PDT) Subject: How to make a Python script to audio read a text file on phone ? Message-ID: <287a6f55-279f-4ddf-9020-c61bca585262@googlegroups.com> I've installed Python on my Nokia E71 (Symbian S60 3rd FP1) and found a script example which can read out text, see example below. I want to make the script to asks me for a text file instead and then reads out the content. I guess it works with a .txt file, dont know if other formats work. Regards! [Quote] # Copyright (c) 2006 Jurgen Scheible # This script performs a query with a single-field dialog (text input field) # and lets the phone speak out the text (text to speech) that the users have typed in # NOTE: this script runs only with Python S60 version 3.1.14 or above # NOTE: this script doesn't work on all S60 phones neccessarily. Check your phone model if it has text to speech capability at all import appuifw import audio text = appuifw.query(u"Type a word:", "text") audio.say(text) [End Quote] From dey.sumit.kr at gmail.com Sun Mar 17 17:48:31 2013 From: dey.sumit.kr at gmail.com (dey.sumit.kr at gmail.com) Date: Sun, 17 Mar 2013 14:48:31 -0700 (PDT) Subject: How to make a Python script to audio read a text file on phone ? In-Reply-To: <287a6f55-279f-4ddf-9020-c61bca585262@googlegroups.com> References: <287a6f55-279f-4ddf-9020-c61bca585262@googlegroups.com> Message-ID: On Sunday, March 17, 2013 7:34:18 PM UTC+5:30, Nic wrote: > I've installed Python on my Nokia E71 (Symbian S60 3rd FP1) and found a script example which can read out text, see example below. > > I want to make the script to asks me for a text file instead and then reads out the content. I guess it works with a .txt file, dont know if other formats work. Regards! > > > > > > [Quote] > > > > # Copyright (c) 2006 Jurgen Scheible > > # This script performs a query with a single-field dialog (text input field) > > # and lets the phone speak out the text (text to speech) that the users have typed in > > # NOTE: this script runs only with Python S60 version 3.1.14 or above > > # NOTE: this script doesn't work on all S60 phones neccessarily. Check your phone model if it has text to speech capability at all > > > > import appuifw > > import audio > > > > text = appuifw.query(u"Type a word:", "text") > > audio.say(text) > > > > [End Quote] Here is a code that works fine for PC. Hope it'll work for you.. def op(): global TXT, L filepath = tkFileDialog.askopenfilename(filetypes=[("Text Files","*.txt")]) if(len(filepath) == 0): return 0 F = open(filepath,'r') TXT = F.read() F.close() filename = filepath.split("/") filename = filename[-1] L.config(text=filename+": "+filepath) def play(): global TXT audio.say(TXT) ##Used as mentioned print "said" from Tkinter import * import Tkconstants, tkFileDialog import audio ##used as mentioned TXT = "" root = Tk() root.title("Read that Out!!") L = Label(text="No File Selected!",width="35",fg="black",bg="white") L.grid(row=1,column=1) F = Frame(root) F.grid(row=2,column=1) Button(F,text="Open File",command=op).grid(row=1,column=1) Button(F,text="Read File",command=play).grid(row=1,column=2) root.mainloop() From ofenerci at hotmail.com Sun Mar 17 12:15:26 2013 From: ofenerci at hotmail.com (ofenerci at hotmail.com) Date: Sun, 17 Mar 2013 09:15:26 -0700 (PDT) Subject: Error about " module object has no attribute 'QStringList' " Message-ID: Dear List, I have been working on restructured text(rest) documents and found a nice application which makes viewing the rest documents easy. It is a web browser especially suited for Sphinx documents. When I run the code, I get error which says that : ----------------->----------------------- Traceback (most recent call last): File "/usr/local/bin/doc-watch", line 73, in self.wb.urlChanged.connect(lambda: self.url.setCompleter(QtGui.QCompleter(QtCore.QStringList([QtCore.QString(i.url().toString()) for i in self.wb.history().items()]), caseSensitivity = QtCore.Qt.CaseInsensitive))) AttributeError: 'module' object has no attribute 'QStringList' --------------------<-------------------- I am running python2.7 on Debian Testing. I appreciate any help to shed any light on this error. The code is following: Best Regards, Ozhan Fenerci #!/usr/bin/env python # # Copyright (C) 2012 Vinay Sajip. Licensed under the MIT license. # # Based on Roberto Alsina's 128-line web browser, see # # http://lateral.netmanagers.com.ar/weblog/posts/BB948.html # import json import os import subprocess import sys import tempfile from urllib import pathname2url import sip sip.setapi("QString", 2) sip.setapi("QVariant", 2) from PyQt4 import QtGui, QtCore, QtWebKit, QtNetwork settings = QtCore.QSettings("Vinay Sajip", "DocWatch") class Watcher(QtCore.QThread): """ A watcher which looks for source file changes, builds the documentation, and notifies the browser to refresh its contents """ def run(self): self._stop = False watch_command = 'inotifywait -rq -e close_write --exclude \'"*.html"\' .'.split() make_command = 'make html'.split() while not self._stop: # Perhaps should put notifier access in a mutex - not bothering yet self.notifier = subprocess.Popen(watch_command) self.notifier.wait() if self._stop: break subprocess.call(make_command) # Refresh the UI ... self.parent().changed.emit() def stop(self): self._stop = True # Perhaps should put notifier access in a mutex - not bothering for now if self.notifier.poll() is None: # not yet terminated ... self.notifier.terminate() class MainWindow(QtGui.QMainWindow): """ A browser intended for viewing HTML documentation generated by Sphinx. """ changed = QtCore.pyqtSignal() def __init__(self, url): QtGui.QMainWindow.__init__(self) self.sb=self.statusBar() self.pbar = QtGui.QProgressBar() self.pbar.setMaximumWidth(120) self.wb=QtWebKit.QWebView(loadProgress = self.pbar.setValue, loadFinished = self.pbar.hide, loadStarted = self.pbar.show, titleChanged = self.setWindowTitle) self.setCentralWidget(self.wb) self.tb=self.addToolBar("Main Toolbar") for a in (QtWebKit.QWebPage.Back, QtWebKit.QWebPage.Forward, QtWebKit.QWebPage.Reload): self.tb.addAction(self.wb.pageAction(a)) self.url = QtGui.QLineEdit(returnPressed = lambda:self.wb.setUrl(QtCore.QUrl.fromUserInput(self.url.text()))) self.tb.addWidget(self.url) self.wb.urlChanged.connect(lambda u: self.url.setText(u.toString())) self.wb.urlChanged.connect(lambda: self.url.setCompleter(QtGui.QCompleter(QtCore.QStringList([QtCore.QString(i.url().toString()) for i in self.wb.history().items()]), caseSensitivity = QtCore.Qt.CaseInsensitive))) self.wb.statusBarMessage.connect(self.sb.showMessage) self.wb.page().linkHovered.connect(lambda l: self.sb.showMessage(l, 3000)) self.search = QtGui.QLineEdit(returnPressed = lambda: self.wb.findText(self.search.text())) self.search.hide() self.showSearch = QtGui.QShortcut("Ctrl+F", self, activated = lambda: (self.search.show() , self.search.setFocus())) self.hideSearch = QtGui.QShortcut("Esc", self, activated = lambda: (self.search.hide(), self.wb.setFocus())) self.quit = QtGui.QShortcut("Ctrl+Q", self, activated = self.close) self.zoomIn = QtGui.QShortcut("Ctrl++", self, activated = lambda: self.wb.setZoomFactor(self.wb.zoomFactor()+.2)) self.zoomOut = QtGui.QShortcut("Ctrl+-", self, activated = lambda: self.wb.setZoomFactor(self.wb.zoomFactor()-.2)) self.zoomOne = QtGui.QShortcut("Ctrl+=", self, activated = lambda: self.wb.setZoomFactor(1)) self.wb.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True) self.sb.addPermanentWidget(self.search) self.sb.addPermanentWidget(self.pbar) self.load_settings() self.wb.load(url) self.watcher = Watcher(self) self.changed.connect(self.wb.reload) self.watcher.start() def load_settings(self): settings.beginGroup('mainwindow') pos = settings.value('pos') size = settings.value('size') if isinstance(pos, QtCore.QPoint): self.move(pos) if isinstance(size, QtCore.QSize): self.resize(size) settings.endGroup() def save_settings(self): settings.beginGroup('mainwindow') settings.setValue('pos', self.pos()) settings.setValue('size', self.size()) settings.endGroup() def closeEvent(self, event): self.save_settings() self.watcher.stop() if __name__ == "__main__": if not os.path.isdir('build'): # very simplistic sanity check. Works for me, as I generally use # sphinx-quickstart defaults print('You must run this application from a Sphinx directory containing build') rc = 1 else: app=QtGui.QApplication(sys.argv) path = os.path.join('build', 'html', 'index.html') url = 'file:///' + pathname2url(os.path.abspath(path)) url = QtCore.QUrl(url) wb=MainWindow(url) wb.show() rc = app.exec_() sys.exit(rc) From vincent.vandevyvre at swing.be Sun Mar 17 12:53:27 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 17 Mar 2013 17:53:27 +0100 Subject: Error about " module object has no attribute 'QStringList' " In-Reply-To: References: Message-ID: <5145F507.9070700@swing.be> Le 17/03/13 17:15, ofenerci at hotmail.com a ?crit : > Dear List, > > I have been working on restructured text(rest) documents and found a nice application which makes viewing the rest documents easy. It is a web browser especially suited for Sphinx documents. > > ..... Forget the reference: http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html -- Vincent V.V. Oqapy . Qarte . PaQager From vincent.vandevyvre at swing.be Sun Mar 17 13:00:43 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 17 Mar 2013 18:00:43 +0100 Subject: Error about " module object has no attribute 'QStringList' " In-Reply-To: <5145F507.9070700@swing.be> References: <5145F507.9070700@swing.be> Message-ID: <5145F6BB.6080705@swing.be> Le 17/03/13 17:53, Vincent Vande Vyvre a ?crit : > Le 17/03/13 17:15, ofenerci at hotmail.com a ?crit : >> Dear List, >> >> I have been working on restructured text(rest) documents and found a nice application which makes viewing the rest documents easy. It is a web browser especially suited for Sphinx documents. >> >> > ..... > > Forget the reference: > http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html It seems my first mail was lost. Remove the line: sip.setapi("QString", 2) See here: http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html From vincent.vandevyvre at swing.be Sun Mar 17 12:51:18 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 17 Mar 2013 17:51:18 +0100 Subject: Error about " module object has no attribute 'QStringList' " In-Reply-To: References: Message-ID: <5145F486.8060202@swing.be> Le 17/03/13 17:15, ofenerci at hotmail.com a ?crit : > sip.setapi("QString", 2) Remove the line: sip.setapi("QString", 2) and try it. -- Vincent V.V. Oqapy . Qarte . PaQager From ofenerci at hotmail.com Sun Mar 17 13:17:08 2013 From: ofenerci at hotmail.com (ofenerci at hotmail.com) Date: Sun, 17 Mar 2013 10:17:08 -0700 (PDT) Subject: Error about " module object has no attribute 'QStringList' " In-Reply-To: References: Message-ID: <806afc7a-6fa1-443e-9301-bdd694004209@googlegroups.com> Thank you Vincent and to All, It has worked like a charm. From pengyu.ut at gmail.com Sun Mar 17 13:45:26 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 17 Mar 2013 12:45:26 -0500 Subject: pprint defaultdict one record per line Message-ID: Hi, pprint can not print defaultdict one record per line. Is there some other convenient way in python to print one record per line? ~/linux/test/python/man/library/pprint/function/pprint$ ./main.py {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]} {'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]} defaultdict(, {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}) ~/linux/test/python/man/library/pprint/function/pprint$ cat main.py #!/usr/bin/env python import pprint d=dict(one=range(10), two=range(15)) print d pprint.pprint(d) from collections import defaultdict d=defaultdict(list) d['one']=range(10) d['two']=range(15) pprint.pprint(d) -- Regards, Peng From breamoreboy at yahoo.co.uk Sun Mar 17 14:09:45 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 17 Mar 2013 18:09:45 +0000 Subject: pprint defaultdict one record per line In-Reply-To: References: Message-ID: On 17/03/2013 17:45, Peng Yu wrote: > Hi, > > pprint can not print defaultdict one record per line. Is there some > other convenient way in python to print one record per line? > > ~/linux/test/python/man/library/pprint/function/pprint$ ./main.py > {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0, > 1, 2, 3, 4, 5, 6, 7, 8, 9]} > {'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], > 'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]} > defaultdict(, {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, > 11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}) > ~/linux/test/python/man/library/pprint/function/pprint$ cat main.py > #!/usr/bin/env python > > import pprint > > d=dict(one=range(10), two=range(15)) > print d > pprint.pprint(d) > > from collections import defaultdict > d=defaultdict(list) > d['one']=range(10) > d['two']=range(15) > pprint.pprint(d) > Try writing a for loop that prints one record per line. -- Cheers. Mark Lawrence From tjreedy at udel.edu Mon Mar 18 00:06:40 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2013 00:06:40 -0400 Subject: pprint defaultdict one record per line In-Reply-To: References: Message-ID: On 3/17/2013 1:45 PM, Peng Yu wrote: > pprint can not print defaultdict one record per line Known issue, no progress for 2+ years. Patch not updated for default branch (3.4). Not clear what best way forward is. -- Terry Jan Reedy From cshekhar.dhone at gmail.com Sun Mar 17 15:30:17 2013 From: cshekhar.dhone at gmail.com (Dreamer) Date: Sun, 17 Mar 2013 12:30:17 -0700 (PDT) Subject: Help me with Event handlers please Message-ID: Hi can anybody share some expertise on event handlers...i need to use em to update user activity in my web app....thanks in advance Cheers From marduk at python.net Sun Mar 17 16:19:22 2013 From: marduk at python.net (marduk at python.net) Date: Sun, 17 Mar 2013 16:19:22 -0400 Subject: Help me with Event handlers please In-Reply-To: References: Message-ID: <1363551562.5881.140661205541077.6E220C2D@webmail.messagingengine.com> On Sun, Mar 17, 2013, at 03:30 PM, Dreamer wrote: > Hi can anybody share some expertise on event handlers...i need to use em > to update user activity in my web app....thanks in advance > Cheers You're proably going to need to be more specific about what help you need. Just a generic "give me a hand with X" is probably not going to get you very far. -a From bartolome.sintes at gmail.com Sun Mar 17 15:43:40 2013 From: bartolome.sintes at gmail.com (bartolome.sintes at gmail.com) Date: Sun, 17 Mar 2013 12:43:40 -0700 (PDT) Subject: tuple of ids of integers or lists Message-ID: <8e66719c-5e90-4776-bba9-a11c29fba2f1@googlegroups.com> In Python 3.3 for Windows, every list gets a different id when it is created: >>> id([3]) 46555784 >>> id([3]) 47920192 >>> id([4]) 46532048 But if I write a tuple asking for the ids of two lists, each list seems to get the same id: >>> id([3]), id([4]) (43079000, 43079000) I was expecting a tuple with two different ids. What is the reason for this behaviour? Thanking you in advance, From roy at panix.com Sun Mar 17 15:59:17 2013 From: roy at panix.com (Roy Smith) Date: Sun, 17 Mar 2013 15:59:17 -0400 Subject: tuple of ids of integers or lists References: <8e66719c-5e90-4776-bba9-a11c29fba2f1@googlegroups.com> Message-ID: In article <8e66719c-5e90-4776-bba9-a11c29fba2f1 at googlegroups.com>, bartolome.sintes at gmail.com wrote: > In Python 3.3 for Windows, every list gets a different id when it is created: > > >>> id([3]) > 46555784 > >>> id([3]) > 47920192 > >>> id([4]) > 46532048 > > But if I write a tuple asking for the ids of two lists, each list seems to > get the same id: > > >>> id([3]), id([4]) > (43079000, 43079000) > > I was expecting a tuple with two different ids. What is the reason for this > behaviour? This is a classic little gotcha. Object ids are guaranteed to be unique, but only for the lifetime of an object. Or, to put it another way, it is guaranteed that no two objects that exist at the same time can have the same id. What's happening when you do: >>> id([3]), id([4]) Is that a list, [3], is created, its id is taken, and then the list is destroyed. In this particular implementation, object ids happen to be the address of the object in memory. Then, a new list, [4], is created. It just so happens that it gets created using the same memory block that was just freed by the destruction of the other list, so it ends up in the same place in memory. So it gets the same id! Kind of neat, huh? PS -- this makes a nice interview question to see if somebody really understands what's happening beneath the surface. From bartolome.sintes at gmail.com Sun Mar 17 16:23:16 2013 From: bartolome.sintes at gmail.com (bartolome.sintes at gmail.com) Date: Sun, 17 Mar 2013 13:23:16 -0700 (PDT) Subject: tuple of ids of integers or lists In-Reply-To: References: <8e66719c-5e90-4776-bba9-a11c29fba2f1@googlegroups.com> Message-ID: <51a8f122-82a2-4eb0-9b8f-50d011591ae1@googlegroups.com> OK. Now I understand it. I was confused because when two list are created in two different lines, Python gives them different ids, but when the two lists are created in the same line (in a tuple) Python gives them the same id. It doesn't really matter as these lists are just created and destroyed, as you have said. Thank you very much for your fast answer. From rosuav at gmail.com Sun Mar 17 16:34:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Mar 2013 07:34:51 +1100 Subject: tuple of ids of integers or lists In-Reply-To: <51a8f122-82a2-4eb0-9b8f-50d011591ae1@googlegroups.com> References: <8e66719c-5e90-4776-bba9-a11c29fba2f1@googlegroups.com> <51a8f122-82a2-4eb0-9b8f-50d011591ae1@googlegroups.com> Message-ID: On Mon, Mar 18, 2013 at 7:23 AM, wrote: > OK. Now I understand it. > > I was confused because when two list are created in two different lines, Python gives them different ids, but when the two lists are created in the same line (in a tuple) Python gives them the same id. It doesn't really matter as these lists are just created and destroyed, as you have said. > > Thank you very much for your fast answer. Here's something that'll either help you understand another aspect of Python, or totally do your head in. >>> print(id([3])) 14485504 >>> print(id([3])) 14485504 If you print it to stdout, the id can be reused! How is this? Here's what's going on. In interactive mode, the result of the last expression is made available under the name _ (a single underscore): >>> id([3]) 15597160 >>> _ 15597160 Integers are objects, like everything else. (Some of them are pre-made, but big numbers like this aren't - at least, not in this Python. But that's implementation-dependent too.) The retention of this integer object can in some circumstances change where the next object is stored. So you may find that some things behave differently in interactive mode than in a script; or perhaps printing something out instead of letting the interpreter display it will change what happens. You're looking into some extremely unspecified behaviour, here, so anything is allowed to affect it. Which means you might be able to learn all sorts of things about Python's internals! :) ChrisA From steve+comp.lang.python at pearwood.info Sun Mar 17 19:34:28 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2013 23:34:28 GMT Subject: Escaping a Python sandbox Message-ID: <51465303$0$6599$c3e8da3$5496439d@news.astraweb.com> An example of how to hack your way out of a Python sandbox: [quote] Now that we can build any function we want, what can we do? We can?t directly access the non restricted builtins: the functions we craft are still executed in the restricted environment. We can get a non sandboxed function to call us: the auth function call the __len__ method of the object that we pass as a parameter. This is however not enough to get out of the sandbox: our globals are still the same and we can?t for example import a module. I tried to look at all the classes we could access via the __subclasses__ trick to see if we could get a reference to a useful module through there, but no dice. Even getting Twisted to call one of our crafted functions via the reactor was not enough. We could try to get a traceback object and use it to browse the stack frames of our callers, but the only trivial ways to get a traceback object are via the inspect or the sys modules which we can?t import. After being blocked on that problem, I went to work on other problems, slept a lot, and woke up to the solution I needed! http://blog.delroth.net/2013/03/escaping-a-python-sandbox-ndh-2013-quals-writeup/ -- Steven From yoursurrogategod at gmail.com Sun Mar 17 20:58:19 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 17:58:19 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? Message-ID: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> N00b question. But here is the code: http://bin.cakephp.org/view/709201806 In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what happens in the second example? Does the loop after "in" get run only once or multiple number of times? From bahamutzero8825 at gmail.com Sun Mar 17 21:24:30 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 17 Mar 2013 20:24:30 -0500 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <51466CCE.1040307@gmail.com> On 2013.03.17 19:58, Yves S. Garret wrote: > N00b question. But here is the code: > > http://bin.cakephp.org/view/709201806 > > In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what > happens in the second example? Does the loop after "in" get run only once or multiple number of times? > In the first example, sorted() returns a list, which is assigned to the name tricky (Python doesn't have variables - names simply point to objects in memory), and then the for loop iterates over tricky, which points to a list. In the second example, the for loop iterates over the list that sorted() returns. The only difference between the two is that the list that sorted() returns is assigned to a name in the first example. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From gary.herron at islandtraining.com Sun Mar 17 21:18:12 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 17 Mar 2013 18:18:12 -0700 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <51466B54.3070109@islandtraining.com> On 03/17/2013 05:58 PM, Yves S. Garret wrote: > N00b question. But here is the code: > > http://bin.cakephp.org/view/709201806 > > In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what > happens in the second example? Does the loop after "in" get run only once or multiple number of times? Just once. The sorted fn is called just once, and the resulting list is iterated through. In your first case, the list is bound to (assigned to) a name so it is accessible afterwards. In the second case, it is available for garbage collection immediately after the loop finishes. Gary Herron From roy at panix.com Sun Mar 17 21:28:56 2013 From: roy at panix.com (Roy Smith) Date: Sun, 17 Mar 2013 21:28:56 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: In article <485a3093-8c07-4d1a-b49e-af32f84f8198 at googlegroups.com>, "Yves S. Garret" wrote: > N00b question. But here is the code: > > http://bin.cakephp.org/view/709201806 > > In the first example, the first for-loop is run and then the list is assigned > to the tricky variable. But, what > happens in the second example? Does the loop after "in" get run only once or > multiple number of times? It's a little hard to answer your question because you're not using the right terminology. When you say, 'the loop after "in"', I assume you mean: [w for w in set(text2) if 'cie' in w or 'cei' in w] yes? That's not what most people would call "a loop". It's a list comprehension. For sure, there's an implied looping over the elements of set(text2) in there, but that's not the way people refer to it. Anyway, here's what happens. Working from the inside out... First, set(text2) is evaluated. I assume text2 is something like a list of strings, or at least iterable which yields strings. This results in a set object being created. Let's call that set S. Next, the list comprehension gets evaluated: [w for w in s if 'cie' in w or 'cei' in w] This iterates over the the elements of s and forms a list out of those elements which pass the condition in the 'if' clause. This results in a list object being created. Let's call that L1 Next, sorted(L1) is evaluated. This returns another list (call it L2). Finally, we get to: for word in L2: print word, This iterates over all the elements in L2, assigning each one, in turn to word, and executing the body of the for statement. Does that answer your question? I'm sure other people will point out that this is not the most efficient way to do this (your way is not wrong, it's just not the most efficient way). There's a way to write this which avoids creating L1. That could be important if there's a large amount of data involved. But, make sure you fully understand what's happing in the example you gave before you move on to the next step. From yoursurrogategod at gmail.com Sun Mar 17 22:01:50 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 19:01:50 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <7f3b4dde-fbd7-44ca-96bc-31a6b2894200@googlegroups.com> On Sunday, March 17, 2013 9:28:56 PM UTC-4, Roy Smith wrote: > In article <485a3093... at googlegroups.com>, > > "Yves S. Garret" wrote: > > > > > N00b question. But here is the code: > > > > > > http://bin.cakephp.org/view/709201806 > > > > > > In the first example, the first for-loop is run and then the list is assigned > > > to the tricky variable. But, what > > > happens in the second example? Does the loop after "in" get run only once or > > > multiple number of times? > > > > It's a little hard to answer your question because you're not using the > > right terminology. When you say, 'the loop after "in"', I assume you > > mean: > > > > [w for w in set(text2) if 'cie' in w or 'cei' in w] > > > > yes? That's not what most people would call "a loop". It's a list > > comprehension. For sure, there's an implied looping over the elements > > of set(text2) in there, but that's not the way people refer to it. > > > > Anyway, here's what happens. Working from the inside out... > > > > First, set(text2) is evaluated. I assume text2 is something like a list > > of strings, or at least iterable which yields strings. This results in > > a set object being created. Let's call that set S. > > > > Next, the list comprehension gets evaluated: > > > > [w for w in s if 'cie' in w or 'cei' in w] > > > > This iterates over the the elements of s and forms a list out of those > > elements which pass the condition in the 'if' clause. This results in a > > list object being created. Let's call that L1 > > > > Next, sorted(L1) is evaluated. This returns another list (call it L2). > > > > Finally, we get to: > > > > for word in L2: > > print word, > > > > This iterates over all the elements in L2, assigning each one, in turn > > to word, and executing the body of the for statement. > > > > Does that answer your question? I'm sure other people will point out > > that this is not the most efficient way to do this (your way is not > > wrong, it's just not the most efficient way). There's a way to write > > this which avoids creating L1. That could be important if there's a > > large amount of data involved. > > > > But, make sure you fully understand what's happing in the example you > > gave before you move on to the next step. Hi, thanks for the detailed explanation. And yes, you've answered my question. I'm trying to better understand what's going on behind the scenes and I appreciate your thorough input. What I don't understand is, how would you avoid creating L1? From roy at panix.com Sun Mar 17 22:28:32 2013 From: roy at panix.com (Roy Smith) Date: Sun, 17 Mar 2013 22:28:32 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> <7f3b4dde-fbd7-44ca-96bc-31a6b2894200@googlegroups.com> Message-ID: In article <7f3b4dde-fbd7-44ca-96bc-31a6b2894200 at googlegroups.com>, "Yves S. Garret" wrote: > I'm trying to better understand what's going on behind the scenes and I > appreciate your thorough input. What I don't understand is, how would you > avoid creating L1? Leave out the square brackets in: sorted([w for w in set(text2) if 'cie' in w or 'cei' in w]) If you re-write that as: sorted(w for w in set(text2) if 'cie' in w or 'cei' in w) Now you've got what's called a generator expression. This iterates over the same values as the list comprehension would, but it generates them one at a time, so it doesn't have to store them all somewhere. It essentially a really neat syntax for writing coroutines. As usual, Stack Overflow does a pretty good job explaining this: http://stackoverflow.com/questions/47789/ From yoursurrogategod at gmail.com Sun Mar 17 21:59:53 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 18:59:53 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: On Sunday, March 17, 2013 9:18:12 PM UTC-4, Gary Herron wrote: > On 03/17/2013 05:58 PM, Yves S. Garret wrote: > > > N00b question. But here is the code: > > > > > > http://bin.cakephp.org/view/709201806 > > > > > > In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what > > > happens in the second example? Does the loop after "in" get run only once or multiple number of times? > > > > Just once. The sorted fn is called just once, and the resulting list is > > iterated through. In your first case, the list is bound to (assigned > > to) a name so it is accessible afterwards. In the second case, it is > > available for garbage collection immediately after the loop finishes. > > > > Gary Herron Gotcha, thanks. From yoursurrogategod at gmail.com Sun Mar 17 21:59:53 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 18:59:53 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: On Sunday, March 17, 2013 9:18:12 PM UTC-4, Gary Herron wrote: > On 03/17/2013 05:58 PM, Yves S. Garret wrote: > > > N00b question. But here is the code: > > > > > > http://bin.cakephp.org/view/709201806 > > > > > > In the first example, the first for-loop is run and then the list is assigned to the tricky variable. But, what > > > happens in the second example? Does the loop after "in" get run only once or multiple number of times? > > > > Just once. The sorted fn is called just once, and the resulting list is > > iterated through. In your first case, the list is bound to (assigned > > to) a name so it is accessible afterwards. In the second case, it is > > available for garbage collection immediately after the loop finishes. > > > > Gary Herron Gotcha, thanks. From yoursurrogategod at gmail.com Sun Mar 17 22:14:49 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 19:14:49 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <6ca68c8c-2567-4656-8e9b-dfa9409a997f@googlegroups.com> I don't get why it's posting what I said twice... From yoursurrogategod at gmail.com Sun Mar 17 22:14:49 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Sun, 17 Mar 2013 19:14:49 -0700 (PDT) Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <6ca68c8c-2567-4656-8e9b-dfa9409a997f@googlegroups.com> I don't get why it's posting what I said twice... From davea at davea.name Mon Mar 18 07:38:20 2013 From: davea at davea.name (Dave Angel) Date: Mon, 18 Mar 2013 07:38:20 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: <6ca68c8c-2567-4656-8e9b-dfa9409a997f@googlegroups.com> References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> <6ca68c8c-2567-4656-8e9b-dfa9409a997f@googlegroups.com> Message-ID: <5146FCAC.3090902@davea.name> On 03/17/2013 10:14 PM, Yves S. Garret wrote: > I don't get why it's posting what I said twice... > Because you're using googlegroups, and haven't unchecked some poorly defined default setting. You're posting both to python-list and to comp.lang.python, each of which is mirrored to the other. That's one of at least two problems with posting via googlegroups. The other is the stupid double-spacing of quotes, which is very annoying to others. See: http://wiki.python.org/moin/GoogleGroupsPython -- DaveA From roy at panix.com Sun Mar 17 22:33:00 2013 From: roy at panix.com (Roy Smith) Date: Sun, 17 Mar 2013 22:33:00 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: In article , "Yves S. Garret" wrote: > I don't get why it's posting what I said twice... Because you're posting using the Google Groups web interface, right? Google Groups is just plain busted and double-posts everything (at least to this group). Not your fault, but something to be aware of. You'd do better to subscribe to the real email list, or use a traditional NNTP newsreader. Google's motto may be "don't be evil", but they get to define what evil is. Apparently working and playing well with mailing list technology which has worked just fine for literally decades isn't part of the definition. From wuwei23 at gmail.com Mon Mar 18 21:08:10 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 18 Mar 2013 18:08:10 -0700 (PDT) Subject: What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <1b06c18e-9a1e-411a-96e2-b318fd6417f3@i5g2000pbj.googlegroups.com> On Mar 18, 12:33?pm, Roy Smith wrote: > Google's motto may be "don't be evil", but they get to define what evil > is. ?Apparently working and playing well with mailing list technology > which has worked just fine for literally decades isn't part of the > definition. Their decision to scrap Reader while ploughing forward with this godawful new UI for Groups has pushed them into the "evil" basket for me :( From steve+comp.lang.python at pearwood.info Sun Mar 17 22:44:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 02:44:00 GMT Subject: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: <51467f6f$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Mar 2013 19:14:49 -0700, Yves S. Garret wrote: > I don't get why it's posting what I said twice... Because you are emailing to the list, and CCing the list. In your email, you have: To: comp.lang.python at googlegroups.com Cc: python-list at python.org Unfortunately, they are the same thing. Or rather, when Google Groups receives its copy of the email, it then "helpfully" sends another copy to python-list at python.org even though you have already CCed it. In defence of Google Groups, it's not *quite* as stupid as it appears, because it's not actually forwarding directly to the same email address. It is actually forwarding to the newsgroup comp.lang.python, which is an alias to python-list at python.org. Confused? Don't be. It is very simple: there are at least three ways to post to this group: 1) Email to python-list at python.org 2) Post to the news group comp.lang.python on Usenet 3) Email to comp.lang.python at googlegroups.com There are others as well. Think of them as all aliases to the same discussion forum. Whichever you choose, choose ONE ONLY. You are using two, hence there are two copies of your message. I recommend that you choose 1) or 2) rather than Google Groups, if possible. There are two problems with Google Groups: - it is not very smart, and often mangles messages so that every line is separated by a blank line (although I see you have avoided that, at least so far!); - also, we get a lot of spam and junk advertising coming from Google Groups, and so in self-defence many people here have an automatic filter that junks anything from Google Groups unread. If you are unable or unwilling to avoid Google Groups, we will still answer your questions, but keep in mind that many of the regulars here will not directly see your posts, but only replies to them. -- Steven From roy at panix.com Sun Mar 17 22:51:26 2013 From: roy at panix.com (Roy Smith) Date: Sun, 17 Mar 2013 22:51:26 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> <51467f6f$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51467f6f$0$6599$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > there are at least three ways to > post to this group: > > 1) Email to python-list at python.org > > 2) Post to the news group comp.lang.python on Usenet > > 3) Email to comp.lang.python at googlegroups.com Amongst the ways, there are.... From tjreedy at udel.edu Mon Mar 18 00:37:50 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2013 00:37:50 -0400 Subject: [Python 2.7.3] What's the difference between these two uses of "for"? In-Reply-To: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> References: <485a3093-8c07-4d1a-b49e-af32f84f8198@googlegroups.com> Message-ID: On 3/17/2013 8:58 PM, Yves S. Garret wrote: > N00b question. But here is the code: > > http://bin.cakephp.org/view/709201806 Short code like this should be included in your message. tricky = sorted([w for w in set(text2) if 'cie' in w or 'cei' in w]) for word in tricky: print word, for word in sorted([w for w in set(text2) if 'cie' in w or 'cei' in w]): print word, -- Terry Jan Reedy From dreamingforward at gmail.com Sun Mar 17 23:53:17 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 17 Mar 2013 20:53:17 -0700 Subject: Message passing syntax for objects Message-ID: Hello, I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb) and wanted to engage the python community on the subject. Alan Kay's idea of message-passing in Smalltalk are interesting, and like the questioner says, never took off. My answer was that Alan Kay's abstraction of "Everything is an object" fails because you can't have message-passing, an I/O task, working in the same space as your objects -- they are two very different functionalities and they have to be preserved **for the programmer**. This functional separation made me think that Python could benefit from a syntactical, language-given separation between Classes and the messages between them, to encourage loosely-coupled, modular OOP. Something that OOP has always promised but never delivered. I think we should co-opt C++'s poorly used >> and << I/O operators (for files) and re-purpose them for objects/classes. One could then have within interpreter space, the ability to pass in a message to an object. >>> 42 >> MyObject #sends 42 as a message into MyObject The Object definition would then have special methods __in__ to receive data and a special way of outputing data that can be caught __str__(?). I'm hoping the community can comment on the matter.... Thanks, Mark Tacoma, Washington From dreamingforward at gmail.com Mon Mar 18 00:26:41 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 17 Mar 2013 21:26:41 -0700 Subject: Message passing syntax for objects In-Reply-To: References: Message-ID: Continuing on this thread, there would be a new bunch of behaviors to be defined. Since "everything is an object", there can now be a standard way to define the *next* common abstraction of "every object interacts with other objects". And going with my suggestion of defining >> and << operators, I'm going to explore the concept further.... >>> 42 >> MyNumberType #would add the integer to your integer type >>> 42 >> MyCollectionType #would add the object into your collection: *poof*: no more random syntaxiis for putting things in collections.\ >>> MyObject >> # queries the object to output its state. >>> "http://www.cnn.com" >> MyInternetObject #outputs the HTML text from CNN's home page. Each object has to figure out how it will receive things from outside of it. Things it can't handle (a string sent to an int) just have to be dropped to some other space, much like stderr does within the O.S. There are probably many other very interesting examples, but the key idea I'm working on (as noted in other messages), is a sort-of universal language for the internet, a WebOS to be applied to a universal data model. Mark From dreamingforward at gmail.com Mon Mar 18 00:46:26 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 17 Mar 2013 21:46:26 -0700 Subject: Message passing syntax for objects In-Reply-To: References: Message-ID: On Sun, Mar 17, 2013 at 9:26 PM, Mark Janssen wrote: > Continuing on this thread, there would be a new bunch of behaviors to > be defined. Since "everything is an object", there can now be a > standard way to define the *next* common abstraction of "every object > interacts with other objects". And going with my suggestion of > defining >> and << operators, I'm going to explore the concept > further.... > Each object has to figure out how it will receive things from outside > of it. Things it can't handle (a string sent to an int) just have to > be dropped to some other space, much like stderr does within the O.S. I guess here's the idea I'm getting at. As a programming language paradigm, OOP has to evolve -- it still has too much dependency on number-crunching and the mathematical operators still dominate. But a better abstraction to wrap the OOP paradigm around is *message-passing* rather than *arithmetic*. And having in/out operators on objects is just *way cool*. mark From dreamingforward at gmail.com Mon Mar 18 16:24:49 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 18 Mar 2013 13:24:49 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: Message-ID: On Mon, Mar 18, 2013 at 12:06 PM, Georg Brandl wrote: > Am 18.03.2013 05:26, schrieb Mark Janssen: >> Continuing on this thread, there would be a new bunch of behaviors to >> be defined. Since "everything is an object", there can now be a >> standard way to define the *next* common abstraction of "every object >> interacts with other objects". > > The problem is that for most objects there isn't *the* interaction. Sure, > you could split up complicated objects into small pieces with a smaller > functionality, but at some point you have to stop. Yes. But that is the point, if you look at the quora post -- to invert the object model and create mashups of simple modular data types and working *upwards*. > Let's see how this > concept fares with simple types such as integers or collections... > >>>>> 42 >> MyNumberType #would add the integer to your integer type > > That's just random. Why not multiply? Why not exponentiate? Well, as I noted in another post, that while these can be broken down into their simpler component (addition and negative numbers), numbers should probably be treated separately. >>>>> 42 >> MyCollectionType #would add the object into your collection: >> *poof*: no more random syntaxiis for putting things in collections.\ > > So you've replaced one method of a collections API by your magical operator, > for all collections. Yes -- for all collections. That's a pretty big gain right? > What about the other methods that are just as important, > such as deleting items, indexing, and querying? The "syntaxitis" would stay > just the same, except if you introduce more operators, which means new syntax > again. > > Also, how would this work for dictionaries or deques? Well, now you get into the Work: a unified data model. Deques, trees, lists, etc were all preliminary evolutionary explorations on this giant computer science journey of knowledge (and data types) which will have to be, can be, pruned and dropped. >>>>> MyObject >> # queries the object to output its state. > > What is "its state"? A readable representation? A serialized representation? > A memory dump? That's still for us to decide. We're mastering the OOP paradigm here: What is the ideal object and what is "in common" across all objects? We are Zen, we want to master the notion of object. What is the simplest object model possible without sacrificing critical functionality... >>>>> "http://www.cnn.com" >> MyInternetObject #outputs the HTML text from CNN's home page. >> >> Each object has to figure out how it will receive things from outside >> of it. Things it can't handle (a string sent to an int) just have to >> be dropped to some other space, much like stderr does within the O.S. >> >> There are probably many other very interesting examples, but the key >> idea I'm working on (as noted in other messages), is a sort-of >> universal language for the internet, a WebOS to be applied to a >> universal data model. > > It seems that you are reinventing pipes (such as UNIX shell pipes). That is a very interesting comparison. That is something like what I'm trying to do. In tandem with the Internet, I do see a kind of synthesis of Web + O.S. integration -- ultimately, creating a "data ecosystem". mark From benjamin.kaplan at case.edu Mon Mar 18 16:34:01 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 18 Mar 2013 13:34:01 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: Message-ID: On Mon, Mar 18, 2013 at 1:24 PM, Mark Janssen wrote: > On Mon, Mar 18, 2013 at 12:06 PM, Georg Brandl wrote: >> Am 18.03.2013 05:26, schrieb Mark Janssen: >>> Continuing on this thread, there would be a new bunch of behaviors to >>> be defined. Since "everything is an object", there can now be a >>> standard way to define the *next* common abstraction of "every object >>> interacts with other objects". >> >> The problem is that for most objects there isn't *the* interaction. Sure, >> you could split up complicated objects into small pieces with a smaller >> functionality, but at some point you have to stop. > > Yes. But that is the point, if you look at the quora post -- to > invert the object model and create mashups of simple modular data > types and working *upwards*. > >> Let's see how this >> concept fares with simple types such as integers or collections... >> >>>>>> 42 >> MyNumberType #would add the integer to your integer type >> >> That's just random. Why not multiply? Why not exponentiate? > > Well, as I noted in another post, that while these can be broken down > into their simpler component (addition and negative numbers), numbers > should probably be treated separately. > >>>>>> 42 >> MyCollectionType #would add the object into your collection: >>> *poof*: no more random syntaxiis for putting things in collections.\ >> >> So you've replaced one method of a collections API by your magical operator, >> for all collections. > > Yes -- for all collections. That's a pretty big gain right? > Nope. No gain at all. Instead of learning the add() method, you learn the >> operator. You have not simplified anything. >> It seems that you are reinventing pipes (such as UNIX shell pipes). > > That is a very interesting comparison. That is something like what > I'm trying to do. In tandem with the Internet, I do see a kind of > synthesis of Web + O.S. integration -- ultimately, creating a "data > ecosystem". > > mark Yes, having the whole program run by chaining functions together is a neat idea. And it works great in functional languages- if you want that as a feature, use OCaml or Haskell. It works less well in imperative languages where you are manipulating data, not just passing it around. > -- > http://mail.python.org/mailman/listinfo/python-list From usernet at ilthio.net Mon Mar 18 03:06:26 2013 From: usernet at ilthio.net (Tim Harig) Date: Mon, 18 Mar 2013 07:06:26 +0000 (UTC) Subject: Message passing syntax for objects References: Message-ID: On 2013-03-18, Mark Janssen wrote: > Alan Kay's idea of message-passing in Smalltalk are interesting, and > like the questioner says, never took off. My answer was that Alan > Kay's abstraction of "Everything is an object" fails because you can't > have message-passing, an I/O task, working in the same space as your > objects -- they are two very different functionalities and they have > to be preserved **for the programmer**. Without concurrency, message passing and interacting through functions are semantically similar. You have operating for sending and receiving messages. Python does this through methods which potentially have inputs and outputs. Function syntax does have two slight advantages over pure message passing. 1. A command is sent with the message as opposed to requiring requests to be parsed from the message separately from the data. 2. Functions constrain what actions are available and what inputs they can legal accept. This is doubly true With concurrency, CSP has shown us that message passing is valuable for syncronization. Most CSP languages retain the idea of passing messages. This need not be the case. The same semantics could be acheived through function call syntax, although it would likely be less intuitive. If you want to pursue your ideas further, and you have not already, I suggest that you investigate Erlang and its CSP based "concurrent oriented programming." Alan Kay, himself, commented that he felt it matched his ideas of message based OOP. When you return, there is a "Candygram" package providing similar constructs (last I knew, it did not yet impliment light weight processes) for Python. You might also look at using Go which has CSP based channel and coroutine semantics. It has many things in common with Python. From shane at umbrellacode.com Mon Mar 18 04:51:38 2013 From: shane at umbrellacode.com (Shane Green) Date: Mon, 18 Mar 2013 01:51:38 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: Message-ID: <15B9E29B-BD7A-4437-9115-EFA863AE3D87@umbrellacode.com> So, by introducing this collaboration mechanism with a syntax that defines it as sending and receiving things that are *not* arbitrary objects, the language would naturally reinforce a more thoroughly decoupled architecture? Sent from my iPad On Mar 17, 2013, at 8:53 PM, Mark Janssen wrote: > Hello, > > I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb) > and wanted to engage the python community on the subject. > > Alan Kay's idea of message-passing in Smalltalk are interesting, and > like the questioner says, never took off. My answer was that Alan > Kay's abstraction of "Everything is an object" fails because you can't > have message-passing, an I/O task, working in the same space as your > objects -- they are two very different functionalities and they have > to be preserved **for the programmer**. > > This functional separation made me think that Python could benefit > from a syntactical, language-given separation between Classes and the > messages between them, to encourage loosely-coupled, modular OOP. > Something that OOP has always promised but never delivered. > > I think we should co-opt C++'s poorly used >> and << I/O operators > (for files) and re-purpose them for objects/classes. One could then > have within interpreter space, the ability to pass in a message to an > object. > >>>> 42 >> MyObject #sends 42 as a message into MyObject > > The Object definition would then have special methods __in__ to > receive data and a special way of outputing data that can be caught > __str__(?). > > I'm hoping the community can comment on the matter.... > > Thanks, > > Mark > Tacoma, Washington > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas From dreamingforward at gmail.com Mon Mar 18 13:04:36 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 18 Mar 2013 10:04:36 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146B848.3040509@pearwood.info> Message-ID: On Sun, Mar 17, 2013 at 11:46 PM, Steven D'Aprano wrote: > I am very interested in this as a concept, although I must admit I'm not > entirely sure what you mean by it. I've read your comment on the link above, > and subsequent emails in this thread, and I'm afraid I don't understand what > you mean here. I feel you are assuming that your readers are already experts > on message-passing languages (Smalltalk?). I know what *I* mean by message > passing, but that's not necessarily what you mean by it. I'm sorry, I haven't been very clear. I'm not even an expert on message-passing languages, but I see that it's a profound concept that hasn't been adequately integrated into the OOP model. In any case, I will try to do better. And I apologize to everyone on the list for the prior mail spam. A part of me is a bit giddy with the idea. By message passing, I mean all the ways we communicate to objects in the OOP environment. Usually we "communicate" to them through method-invokation. But this is the wrong way, I argue, to look at the problem. With function or method syntax, you're telling the computer to "execute something", but that is not the right concepts for OOP. You want the objects to interact with each other and in a high-level language, the syntax should assist with that. > By building it into the language, it would *enforce* a modular object > style, rather than the current, very specialized and very programmer > specific way there is now. In fact, most people never really think in > that paradigm, yet if the language supported/proposed such a syntax, > programmers would start to re-arrange the whole object hierarchy in a > new, more modular and universal way. > [end quote] > > I don't understand this. In what way would message passing enforce a modular > object style? In what way does Python not already have a modular object > style? Hopefully my paragraph clarifies that a bit. But the key conceptual shift is that by enforcing a syntax that moves away from invoking methods and move to message passing between objects, you're automatically enforcing a more modular approach. Mark From dreamingforward at gmail.com Mon Mar 18 19:41:41 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 18 Mar 2013 16:41:41 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> References: <5146B848.3040509@pearwood.info> <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> Message-ID: On Mon, Mar 18, 2013 at 2:51 PM, Andrew Barnert wrote: > Have you even looked at a message-passing language? > > A Smalltalk "message" is a selector and a sequence of arguments. That's what you send around. Newer dynamic-typed message-passing OO and actor languages are basically the same as Smalltalk. Yes, but you have to understand that Alan Kays came with strange ideas of some future computer-human symbiosis. So his language design and other similar attempts (like php) is rather skewed from that premise And also, despite name-dropping, I'm not trying to create anything like that idea of message-passing. I'm talking about something very simple, a basic and universal way for objects to communicate. >> With function or method syntax, you're telling the computer to >> "execute something", but that is not the right concepts for OOP. You >> want the objects to interact with each other and in a high-level >> language, the syntax should assist with that. > > And you have to tell the object _how_ to interact with each other. This is a different paradigm that what I'm talking about. In the OOP of my world, Objects already embody the intelligence of how they are going to interact with the outside world, because I put them there. > Even with reasonably intelligent animals, you don't just tell two animals to interact, except in the rare case where you don't care whether they become friends or dinner. You're model of computer programming is very alien to me. So I don't think it will be productive to try to convince you of what I'm suggesting, but feel free to continue... Mark From abarnert at yahoo.com Mon Mar 18 23:31:31 2013 From: abarnert at yahoo.com (Andrew Barnert) Date: Mon, 18 Mar 2013 20:31:31 -0700 (PDT) Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146B848.3040509@pearwood.info> <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> Message-ID: <1363663891.8351.YahooMailNeo@web184701.mail.ne1.yahoo.com> From: Mark Janssen Sent: Monday, March 18, 2013 4:41 PM > On Mon, Mar 18, 2013 at 2:51 PM, Andrew Barnert > wrote: >> Have you even looked at a message-passing language? >> >> A Smalltalk "message" is a selector and a sequence of arguments. > That's what you send around. Newer dynamic-typed message-passing OO and > actor languages are basically the same as Smalltalk. > > Yes, but you have to understand that Alan Kays came with strange ideas > of some future computer-human symbiosis.? So his language design and > other similar attempts (like php) is rather skewed from that premise The idea that message passing is fundamentally different from method calling also turned out to be one of those strange ideas, since it only took a couple years to prove that they are theoretically completely isomorphic?and, for that matter, they're both isomorphic to closures. > And also, despite name-dropping, I'm not trying to create anything > like that idea of message-passing.? I'm talking about something very > simple, a basic and universal way for objects to communicate. Message passing is a simple, basic, and universal way for objects to communicate. Everything from dot-syntax method calls to JSON RPC protocols can be modeled as passing messages.?But what you're talking about isn't message passing. The idea that messages have names, and reference objects as arguments, is fundamental, and by leaving that out, you're talking about something different.? In effect, your "objects" are just single-parameter functions, and your "messages" are the call operator. >>> With function or method syntax, you're telling the computer to >>> "execute something", but that is not the right concepts for > OOP.? You >>> want the objects to interact with each other and in a high-level >>> language, the syntax should assist with that. >>? >> And you have to tell the object _how_ to interact with each other. > > This is a different paradigm that what I'm talking about.? In the OOP > of my world, Objects already embody the intelligence of how they are > going to interact with the outside world, because I put them there. The paradigm you're talking about is useless. You have lists that know how to append, but don't know how to get/search/iterate. Almost every useful object needs the intelligence to interact with the world in two or more ways. >> Even with reasonably intelligent animals, you don't just tell two > animals to interact, except in the rare case where you don't care whether > they become friends or dinner. > > You're model of computer programming is very alien to me.? So I don't > think it will be productive to try to convince you of what I'm > suggesting, but feel free to continue... My model of (object-oriented) computer programming is that programming objects model objects which?have a variety of behaviors, each of which is triggered by sending a different message.?This is pretty much the central definition that everyone who programs or theorizes about programming uses. If you read any textbook, wiki page, journal article, or tutorial, they're all talking about that, or something directly isomorphic to it. If that's alien to you, then object-oriented programming is alien to you. From tjreedy at udel.edu Tue Mar 19 16:09:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Mar 2013 16:09:44 -0400 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: <1363663891.8351.YahooMailNeo@web184701.mail.ne1.yahoo.com> References: <5146B848.3040509@pearwood.info> <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> <1363663891.8351.YahooMailNeo@web184701.mail.ne1.yahoo.com> Message-ID: On 3/18/2013 11:31 PM, Andrew Barnert wrote: > The idea that message passing is fundamentally different from method > calling also turned out to be one of those strange ideas, since it > only took a couple years to prove that they are theoretically > completely isomorphic?and, Since the isomorphism is so obvious, I somehow missed that Kay actually thought that they were different. I suppose one could have different (but isomorphic) mental image models. For me, the problem with message passing, as usually though of, or method calls in their usual syntax, is the breaking of symmetries such as the commutivity of number addition. I think of 'a + b' as a message to the interpreter, as supervisor of Python objects, to add a and b together and give me the result. It turns out that a Python interpreter does that by calling *either* a.__add__(b) or b.__add__(a) or possibly both. The advantage of passing messages through a supervisor is that it can 'supervise' the process. The behavior with binary operators is one example. The behavior of len(c) is another. If c.__len__ does not exist, (the programmers fault for calling len(c)), it raises one message. If c.__len__ does not return a non-negative int, it raises another. > for that matter, they're both isomorphic to closures. Translating into Python, does this refer to the fact that bound methods are closures? > In effect, your "objects" are just single-parameter functions, and > your "messages" are the call operator. The proposal seems to be that every object should have a single-parameter call method that in turn calls a preferred, default single-parameter named method. For lists: def __call__(self, ob): self.append(ob) For ints: def __call__(self, other): return self.__add__(other) That seems useless as a general pattern. -- Terry Jan Reedy From dreamingforward at gmail.com Wed Mar 20 00:24:48 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 19 Mar 2013 21:24:48 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146B848.3040509@pearwood.info> <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> <1363663891.8351.YahooMailNeo@web184701.mail.ne1.yahoo.com> Message-ID: On Tue, Mar 19, 2013 at 1:09 PM, Terry Reedy wrote: > On 3/18/2013 11:31 PM, Andrew Barnert wrote: > >> The idea that message passing is fundamentally different from method >> calling also turned out to be one of those strange ideas, since it >> only took a couple years to prove that they are theoretically >> completely isomorphic?and, > > Since the isomorphism is so obvious, I somehow missed that Kay actually > thought that they were different. I suppose one could have different (but > isomorphic) mental image models. Yes, that's the point I'm making, and it's significant because other programmers can't see other's mental models. mark From wuwei23 at gmail.com Thu Mar 21 01:50:53 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 20 Mar 2013 22:50:53 -0700 (PDT) Subject: Message passing syntax for objects References: <5146B848.3040509@pearwood.info> <1363643500.25746.YahooMailNeo@web184701.mail.ne1.yahoo.com> <1363663891.8351.YahooMailNeo@web184701.mail.ne1.yahoo.com> Message-ID: On Mar 20, 2:24?pm, Mark Janssen wrote: > Yes, that's the point I'm making, and it's significant because other > programmers can't see other's mental models. How does having API-less magic objects make this any better? I pass a string message to your RSS object: does it create XML from it? does it parse it as RSS XML and return a mapping? Or do I have to read its code and/or documentation - like I currently do with the classes other developers create - and gain an understanding from that? How about backing up some of your claims of this brave new programming future with actual examples and evidence? Or would you prefer we listen to your gut feeling and ignore concrete research, as you recently recommended to Jane McGonigal? If that's the case, I believe there's a Python4K project which would benefit greatly from your "radical" ideas. From dihedral88888 at googlemail.com Mon Mar 18 14:24:52 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 18 Mar 2013 11:24:52 -0700 (PDT) Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146B848.3040509@pearwood.info> Message-ID: <892700c8-4b6a-489b-96a5-8f96310bf028@googlegroups.com> zipher? 2013?3?19????UTC+8??1?04?36???? > On Sun, Mar 17, 2013 at 11:46 PM, Steven D'Aprano wrote: > > > I am very interested in this as a concept, although I must admit I'm not > > > entirely sure what you mean by it. I've read your comment on the link above, > > > and subsequent emails in this thread, and I'm afraid I don't understand what > > > you mean here. I feel you are assuming that your readers are already experts > > > on message-passing languages (Smalltalk?). I know what *I* mean by message > > > passing, but that's not necessarily what you mean by it. > > > > I'm sorry, I haven't been very clear. I'm not even an expert on > > message-passing languages, but I see that it's a profound concept that > > hasn't been adequately integrated into the OOP model. In any case, I > > will try to do better. And I apologize to everyone on the list for > > the prior mail spam. A part of me is a bit giddy with the idea. > > > > By message passing, I mean all the ways we communicate to objects in > > the OOP environment. Usually we "communicate" to them through > > method-invokation. But this is the wrong way, I argue, to look at the > > problem. > > > > With function or method syntax, you're telling the computer to > > "execute something", but that is not the right concepts for OOP. You > > want the objects to interact with each other and in a high-level > > language, the syntax should assist with that. > > > > > By building it into the language, it would *enforce* a modular object > > > style, rather than the current, very specialized and very programmer > > > specific way there is now. In fact, most people never really think in > > > that paradigm, yet if the language supported/proposed such a syntax, > > > programmers would start to re-arrange the whole object hierarchy in a > > > new, more modular and universal way. > > > [end quote] > > > > > > I don't understand this. In what way would message passing enforce a modular > > > object style? In what way does Python not already have a modular object > > > style? > > > > Hopefully my paragraph clarifies that a bit. But the key conceptual > > shift is that by enforcing a syntax that moves away from invoking > > methods and move to message passing between objects, you're > > automatically enforcing a more modular approach. > > > > Mark Please check object pascal and objective c and erlang for the message-action director model of what you want. C is too low level to be suitable for everything. From lele at metapensiero.it Mon Mar 18 15:16:31 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Mon, 18 Mar 2013 20:16:31 +0100 Subject: [Python-ideas] Message passing syntax for objects References: <5146B848.3040509@pearwood.info> <892700c8-4b6a-489b-96a5-8f96310bf028@googlegroups.com> Message-ID: <87620oplgw.fsf@nautilus.nautilus> 88888 Dihedral writes: > zipher? 2013?3?19????UTC+8??1?04?36???? >> the key conceptual shift is that by enforcing a syntax that moves >> away from invoking methods and move to message passing between >> objects, you're automatically enforcing a more modular approach. > > Please check object pascal and objective c and erlang for > the message-action director model of what you want. I fail to see how syntax differences would change the modularity of your product. The fact that (say) ObjC use the name "message" while Python calls the same a "method" isn't actually changing the concrete fact that both are executing some sort of function that accepts an "instance" object as one of the arguments (in Python, the first parameter, usually called self, in ObjC, and implicit "self"). In other words, the following ObjC [someObj getItemAt: i] is perfectly equivalent to the following Python someObj.getItemAt(i) and to the following Smalltalk someObj getItemAt: i How is the former syntax, where "getItemAt:" is called a "message", more modular from the second, where "getItemAt()" is called a method? 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 dihedral88888 at googlemail.com Mon Mar 18 14:24:52 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 18 Mar 2013 11:24:52 -0700 (PDT) Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146B848.3040509@pearwood.info> Message-ID: <892700c8-4b6a-489b-96a5-8f96310bf028@googlegroups.com> zipher? 2013?3?19????UTC+8??1?04?36???? > On Sun, Mar 17, 2013 at 11:46 PM, Steven D'Aprano wrote: > > > I am very interested in this as a concept, although I must admit I'm not > > > entirely sure what you mean by it. I've read your comment on the link above, > > > and subsequent emails in this thread, and I'm afraid I don't understand what > > > you mean here. I feel you are assuming that your readers are already experts > > > on message-passing languages (Smalltalk?). I know what *I* mean by message > > > passing, but that's not necessarily what you mean by it. > > > > I'm sorry, I haven't been very clear. I'm not even an expert on > > message-passing languages, but I see that it's a profound concept that > > hasn't been adequately integrated into the OOP model. In any case, I > > will try to do better. And I apologize to everyone on the list for > > the prior mail spam. A part of me is a bit giddy with the idea. > > > > By message passing, I mean all the ways we communicate to objects in > > the OOP environment. Usually we "communicate" to them through > > method-invokation. But this is the wrong way, I argue, to look at the > > problem. > > > > With function or method syntax, you're telling the computer to > > "execute something", but that is not the right concepts for OOP. You > > want the objects to interact with each other and in a high-level > > language, the syntax should assist with that. > > > > > By building it into the language, it would *enforce* a modular object > > > style, rather than the current, very specialized and very programmer > > > specific way there is now. In fact, most people never really think in > > > that paradigm, yet if the language supported/proposed such a syntax, > > > programmers would start to re-arrange the whole object hierarchy in a > > > new, more modular and universal way. > > > [end quote] > > > > > > I don't understand this. In what way would message passing enforce a modular > > > object style? In what way does Python not already have a modular object > > > style? > > > > Hopefully my paragraph clarifies that a bit. But the key conceptual > > shift is that by enforcing a syntax that moves away from invoking > > methods and move to message passing between objects, you're > > automatically enforcing a more modular approach. > > > > Mark Please check object pascal and objective c and erlang for the message-action director model of what you want. C is too low level to be suitable for everything. From dreamingforward at gmail.com Mon Mar 18 13:18:53 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 18 Mar 2013 10:18:53 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146A76D.1020205@canterbury.ac.nz> Message-ID: > Ian Cordasco wrote: >> >> On Sun, Mar 17, 2013 at 11:53 PM, Mark Janssen >> wrote: >> >>> Hello, >>> >>> I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb) >>> and wanted to engage the python community on the subject. > > > My answer to that question would be that it *did* > catch on, it's just that we changed the terminology. > Instead of message passing, we talk about calling > methods. Yes, but this is where it breaks the OOP abstraction by 90 degrees. By using function calls, you're telling the machine to do something. But when you want to pass something to an object there should be a natural way to do this for every object. By using methods you pollute the concept space with all sorts of semi-random (i.e. personal) names, like append, add, enqueue, etc. This proposal would not only make a consistent syntax across all objects, but train the programmer to *think* modularly in the sense of having a community of re-usable object. I.e. "What should I do if another object passes me something?". No one thinks this now, because the programmer expects new developers to learn *their* interface! Mark From benjamin.kaplan at case.edu Mon Mar 18 14:04:25 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 18 Mar 2013 11:04:25 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146A76D.1020205@canterbury.ac.nz> Message-ID: On Mon, Mar 18, 2013 at 10:18 AM, Mark Janssen wrote: >> Ian Cordasco wrote: >>> >>> On Sun, Mar 17, 2013 at 11:53 PM, Mark Janssen >>> wrote: >>> >>>> Hello, >>>> >>>> I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb) >>>> and wanted to engage the python community on the subject. >> >> >> My answer to that question would be that it *did* >> catch on, it's just that we changed the terminology. >> Instead of message passing, we talk about calling >> methods. > > Yes, but this is where it breaks the OOP abstraction by 90 degrees. > By using function calls, you're telling the machine to do something. > But when you want to pass something to an object there should be a > natural way to do this for every object. By using methods you pollute > the concept space with all sorts of semi-random (i.e. personal) names, > like append, add, enqueue, etc. > > This proposal would not only make a consistent syntax across all > objects, but train the programmer to *think* modularly in the sense of > having a community of re-usable object. I.e. "What should I do if > another object passes me something?". No one thinks this now, because > the programmer expects new developers to learn *their* interface! > > Mark > -- You're dreaming of a utopia where computers just read our minds and know what we're thinking. So what if I can pass 42 into an object. What do I intend to happen with that 42? Do I want to add the element to a list? Access the 42nd element? Delete the 42nd element? Let the object pick a behavior at random? Clearly there must be some sort of behavior defined for passing a message into an object. And now we're back to learning the interface that the programmer designed. Only now, instead of having different types of behavior grouped together into classes, we have to use a different object for each operation. So what's the benefit of that over having the object implement the __call__ method? Also, why would we re-use the bit shift operators for message passing? Just because C++ decided to overload the existing operators to mean reading into and writing out of a stream doesn't mean it's a good idea. From dreamingforward at gmail.com Mon Mar 18 14:29:00 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 18 Mar 2013 11:29:00 -0700 Subject: [Python-ideas] Message passing syntax for objects In-Reply-To: References: <5146A76D.1020205@canterbury.ac.nz> Message-ID: > You're dreaming of a utopia where computers just read our minds and > know what we're thinking. So what if I can pass 42 into an object. > What do I intend to happen with that 42? Do I want to add the element > to a list? Access the 42nd element? Delete the 42nd element? Let the > object pick a behavior at random? Huh?, No the programmer has to think of how data interacts with his/her objects. It's just that *now* the language is wise enough to teach them to think about it. > So > what's the benefit of that over having the object implement the > __call__ method? You bring up an interesting subject. I think you could get rid of the __call__ special method on objects. I think this is the wrong view into the object universe or *data ecosystem*. > Also, why would we re-use the bit shift operators for message passing? > Just because C++ decided to overload the existing operators to mean > reading into and writing out of a stream doesn't mean it's a good > idea. You're right, perhaps there's a better set of symbols that suggest "moving data". Mark From pengyu.ut at gmail.com Sun Mar 17 23:56:07 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 17 Mar 2013 22:56:07 -0500 Subject: How to add the current dir to sys.path when calling a python file? Message-ID: Hi, man python says "If a script argument is given, the directory containing the script is inserted in the path in front of $PYTHONPATH. The search path can be manipulated from within a Python program as the variable sys.path." Instead I want to have the current directory inserted to the front of $PYTHONPATH without changing anything the script. Is there a way to do so? -- Regards, Peng From steve+comp.lang.python at pearwood.info Mon Mar 18 02:54:03 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 06:54:03 GMT Subject: How to add the current dir to sys.path when calling a python file? References: Message-ID: <5146ba0b$0$6599$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote: > Hi, > > man python says "If a script argument is given, the directory > containing the script is inserted in the path in front of $PYTHONPATH. > The search path can be manipulated from within a Python program as the > variable sys.path." Instead I want to have the current directory > inserted to the front of $PYTHONPATH without changing anything the > script. Is there a way to do so? No. If you want to manipulate the path, you have to write code to do so, and put it in your script. That's very simple: import os, sys sys.path.insert(0, os.getcwd()) -- Steven From pengyu.ut at gmail.com Mon Mar 18 09:52:05 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 18 Mar 2013 08:52:05 -0500 Subject: How to add the current dir to sys.path when calling a python file? In-Reply-To: <5146ba0b$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5146ba0b$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 18, 2013 at 1:54 AM, Steven D'Aprano wrote: > On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote: > >> Hi, >> >> man python says "If a script argument is given, the directory >> containing the script is inserted in the path in front of $PYTHONPATH. >> The search path can be manipulated from within a Python program as the >> variable sys.path." Instead I want to have the current directory >> inserted to the front of $PYTHONPATH without changing anything the >> script. Is there a way to do so? > > No. If you want to manipulate the path, you have to write code to do so, > and put it in your script. That's very simple: > > import os, sys > sys.path.insert(0, os.getcwd()) Actually, it is quite simple. Just use stdin to take the python file. ~/linux/test/python/man/library/sys/path$ cat.sh main.py subdir/main.py ==> main.py <== #!/usr/bin/env python import sys print sys.path ==> subdir/main.py <== #!/usr/bin/env python import sys print sys.path ~/linux/test/python/man/library/sys/path$ diff <(python - < main.py) <(python - < subdir/main.py) -- Regards, Peng From rustompmody at gmail.com Mon Mar 18 03:35:39 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 18 Mar 2013 00:35:39 -0700 (PDT) Subject: How to add the current dir to sys.path when calling a python file? References: Message-ID: <0e47a0da-572c-4ee9-ba25-9ea9a36e3046@mc2g2000pbb.googlegroups.com> On Mar 18, 8:56?am, Peng Yu wrote: > Hi, > > man python says "If a script ?argument ?is ?given, ?the directory > containing the script is inserted in the path in front of $PYTHONPATH. > The search path can be manipulated from ?within a Python program as > the variable sys.path." Instead I want to have the current directory > inserted to the front of $PYTHONPATH without changing anything the > script. Is there a way to do so? > > -- > Regards, > Peng Have you seen http://docs.python.org/2/library/site.html ? From davea at davea.name Mon Mar 18 07:32:28 2013 From: davea at davea.name (Dave Angel) Date: Mon, 18 Mar 2013 07:32:28 -0400 Subject: How to add the current dir to sys.path when calling a python file? In-Reply-To: References: Message-ID: <5146FB4C.5020109@davea.name> On 03/17/2013 11:56 PM, Peng Yu wrote: > Hi, > > man python says "If a script argument is given, the directory > containing the script is inserted in the path in front of $PYTHONPATH. > The search path can be manipulated from within a Python program as > the variable sys.path." Instead I want to have the current directory > inserted to the front of $PYTHONPATH without changing anything the > script. Is there a way to do so? > if the script you're running is in the current directory, it'll just already do what you seem to be asking. cd /home/davea/temppython cat peng.;py import sys print "sys.path is", sys.path python peng.py sys.path is ['/home/davea/temppython', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/l ..... The text you quoted is trying to say that there are 3 different ways you can modify the search path. The script name's location, the $PYTHONPATH environment variable, and the sys.path Python variable. -- DaveA From dreamingforward at gmail.com Mon Mar 18 00:40:12 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 17 Mar 2013 21:40:12 -0700 Subject: Message passing for objects Message-ID: Just the thing I'm talking about. So I'm not the only one trying out these ideas..... :) (via the p2p-foundation mailing list) ---------- Forwarded message ---------- From: ProjectParadigm-ICT-Program Date: Sat, Mar 16, 2013 at 3:12 PM Subject: Re: A Distributed Economy -- A blog involving Linked Data To: Brent Shambaugh , Michel Bauwens Cc: Samuel Rose , "public-lod at w3.org" , Paul Cockshott Dear Brent, Thanks for bringing up this issue again, and let me rephrase. When considering resilience there are three networked systems to consider: humans, things and ideas/data/information. All three somehow now mesh and interact through the Internet and the Internet of Things. The conceptual model for the Semantic Web incorporates all three. Now if we want to complete this model we must incorporate the (Global) Ecosystems of Planet Earth. Thus we are able to create economic models that incorporate security, resilience, reliability and sustainability. As we speak thousands and thousands of engineers and scientists are already tackling the fundamental task of coming up with new all-encompassing paradigms and the 7th IEEE International Conference on Digital Ecosystems and Technologies will deal with quite a few of these issues. I will soon be setting up a blog which will deal with resilience, more specifically resilient grids and resilient grid technologies. The theme of resilience whether it relates to cyber space, natural ecosystems and resources management as part of sustainable economic development, human society or economic assets vis a vis natural disasters or conflict is proving to be be one of the hottest new themes in funded research, and one main central theme in Horizon 2020, the new European Union 71 billion euro research fund. Milton Ponson GSM: +297 747 8280 PO Box 1154, Oranjestad Aruba, Dutch Caribbean Project Paradigm: A structured approach to bringing the tools for sustainable development to all stakeholders worldwide by creating ICT tools for NGOs worldwide and: providing online access to web sites and repositories of data and information for sustainable development 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 the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. ________________________________ From: Brent Shambaugh To: Michel Bauwens Cc: ProjectParadigm-ICT-Program ; Samuel Rose ; "public-lod at w3.org" ; Paul Cockshott Sent: Thursday, March 14, 2013 7:12 PM Subject: Re: A Distributed Economy -- A blog involving Linked Data In an attempt to understand the conversation we had, I was sent in a flurry of confusion. I started checking out books, and one was Resilience by Andrew Zolli and Ann Marie Healy. I found a few quotes that seem exciting to me: "Adhocracies thrive on data. And by the stroke of fantastic luck, we're currently witnessing the global birth of an adhocracy of data -- a global revolution that, for the first time, empowers orgranizations with the capacity to collect and correlate widely distributed real-time information about the way many critical systems are performing. This kind of open data will play a central role in resilience strategies for years to come." pg. 266, Resilience, Andrew Zolli and Ann Marie Healy "And for organizations of all types there is a powerful lesson here: Resilience benefits accrue to organizations that prioritize the collection, presentation, and sharing of data." pg. 269, Resilience, Andrew Zolli and Ann Marie Healy "A related theme in the resilience discussion is the importance of networks, which provide a universal, abstract reference system for describing how information, resources, and behaviours flow GSM: +297 747 8280 PO Box 1154, Oranjestad Aruba, Dutch Caribbean Project Paradigm: A structured approach to bringing the tools for sustainable development to all stakeholders worldwide by creating ICT tools for NGOs worldwide and: providing online access to web sites and repositories of data and information for sustainable development 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 the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. ________________________________ From: Brent Shambaugh To: Michel Bauwens Cc: ProjectParadigm-ICT-Program ; Samuel Rose ; "public-lod at w3.org" ; Paul Cockshott Sent: Thursday, March 14, 2013 7:12 PM Subject: Re: A Distributed Economy -- A blog involving Linked Data In an attempt to understand the conversation we had, I was sent in a flurry of confusion. I started checking out books, and one was Resilience by Andrew Zolli and Ann Marie Healy. I found a few quotes that seem exciting to me: "Adhocracies thrive on data. And by the stroke of fantastic luck, we're currently witnessing the global birth of an adhocracy of data -- a global revolution that, for the first time, empowers orgranizations with the capacity to collect and correlate widely distributed real-time information about the way many critical systems are performing. This kind of open data will play a central role in resilience strategies for years to come." pg. 266, Resilience, Andrew Zolli and Ann Marie Healy "And for organizations of all types there is a powerful lesson here: Resilience benefits accrue to organizations that prioritize the collection, presentation, and sharing of data." pg. 269, Resilience, Andrew Zolli and Ann Marie Healy "A related theme in the resilience discussion is the importance of networks, which provide a universal, abstract reference system for describing how information, resources, and behaviours flow through many complex systems. Having a common means to describe biological, economic, and ecological systems, for example, allows researchers to make comparisons between the ways these very different kinds of entities approach similar problems, such as stopping a contagion - whether an actual virus, a financial panic, an unwanted behavior, or an environmental contaminant - when it begins to spread. Having a shared frame of reference allows us to consider how successful tactics in one domain might be applied to another - as we'll see in newly emerging fields like ecological finance." pg 19, Resilience, Andrew Zolli and Ann Marie Healy "Rather the resilience frame suggests a different, complementary effort to mitigation: to redesign our institutions, embolden our communities, encourage innovation and experimentation, and support our people in ways that will help them be prepared and cope with surprises and distruptions, even as we work to fend them off." pg 23, Resilience, Andrew Zolli and Ann Marie Healy It is interesting that Buckminster Fuller wrote about similar ideas over 30 years ago: "The inefficiency of automobiles' reciprocating engines - and their traffic-system-wasted fuel - and the energy inefficiency of today's buildings, are only two of hundreds of thousands of instances that can be cited of the design-avoidable energy wastage. But the technical raison d'etre for either the energy-effectiveness gains or losses is all completely invisible to human eyes. Thus, the significance of their omni-integratable potentialities is uncomprehended by either the world's leaders or the led. Neither the great political and financial power structures of the world, nor the specialization-blinded professionals, nor the population in general realize the sum-totally the omni-engineering-integratable, invisible revolution in metallurgical, chemical, and electronic arts now makes it possible to do so much more with ever fewer pounds and volumes of material, ergs of energy, and seconds of time per given technological function that it is now highly feasible to take care of everybody on Earth at a "higher standard of living than any have ever known.", pg. xxv, Critical Path, R. Buckminster Fuller "World Game will become increasingly effective in its prognoses and programming when the world-around, satellite-interrelayed computer system and its omni-Universe-operative (time-energy) accounting system are established. This system will identify the kilowatt-hour-expressed world inventory of foods, raw and recirculating resources, and all the world's unique mechanical and structural capabilities and their operating capacities as well as the respective kilowatt-hours of available energy-income-derived operating power with which to put their facilities to work. All the foregoing information will become available in respect to all the world-around technology's environment-controlling, life-sustaining, travel- and communication-accomidating structures and machines.", pg. 219, Critical Path, R. Buckminster Fuller I'm happy that Milton Ponson pointed out Resilience. I had never thought about resilience before. Looking into it was very gratifying. It gave me some confidence that I was perhaps doing some things right, but at the same time startled me by how much there is to learn to somehow survive the free fall. Doing a search for Linked Data and Resilience gave me a result from rkbexpolorer (http://www.rkbexplorer.com/explorer/#display=project-{http%3A//wiki.rkbexplorer.com/id/resist}) which is from the ReSIST (Resilience for Survivability) project in Europe (http://www.resist-noe.org/). They also have some links to some free course material at . I believe my blog evolved to explore a peer-to-peer economy. Michael Bauwens desribes such economies as distributed networks, "As political, economic, and social systems transform themselves into distributed networks, a new human dynamic is emerging: peer to peer (P2P). As P2P gives rise to the emergence of a third mode of production, a third mode of governence, and a third mode of property, it is poised to overhaul our political economy in unprecendented ways." (www.ctheory.net/articles.aspx?id=499) This suggests something broader. As a result of our conversation, I also looked at some people with socialist views such as Roberto Verzola, W. Paul Cockshott and Allin Cottrell, Raoul Viktor, and Heinz Dieterich. Roberto Verzola describes an economy of abundance, which may indeed be linked to P2P technologies. "An economy of abundance seeks to dismantle or reform these scarcity-generating institutions in such a way as to affirm our freedom to live life as art (self-expression to others), social equity (so that everything can live life as art), and sustainability (so that all life can thrive into the future). Among other things, this implies a much greater role for various forms of shared property, individual an community-level self-reliance, and participatory decision making." (http://www.shareable.net/blog/event-the-economics-of-abundance) He also argues that for innovation to proceed, everyone seeking knowledge should have access to it. "the most important means to ensure that innovation can proceed is to ensure that everyone seeking knowledge has access to it. ... Knowledge that helps empower people depends on openness, while knowledge that is used to coerce, to exert power over the disempowered, thrives on secrecy" p. 150, The Economics of Abunance: A Political Economy of Freedom, Equity and Sustainability, Roberto Verzola This seems to align well with my present feelings. I feel that engineering is so saturated with IP, that it is hard to feel like you're not going to be doing that. At the same time I want to develop my skills and thrive. How do become a Professional Engineer and not feel like you're going to be doing that? What if you don't like the lawyer saturated culture where people are suing other people over some idea you or someone else produced? I can sense that a lot of people, especially in the hacker and maker community, want to be able to support themselves and work on cool new things but don't want to deny other people to work on the same cool things. Why do ideas have to take on a life of their own and become part of something you might be employed by, but have no control beyond that? Sorry about the extreme language, but why do I imagine it as making deal with the devil? Betraying your friends so you can enjoy life and eat? In this, there is an underlying assumption that there are institutions that do not want to share or partner, or make it very difficult. If it is easier, I feel that could be better. Buckminster Fuller also wrote about such things: "2. Grandmother taught us the Golden Rule: "Love thy neighbor as thy self--do unto others as you would they should do unto you. 3. As we became older and more experienced, out uncles began to caution us to get over our sensitivity. "Life is hard," they explained. 'There is nowhere nearly enough life support for everybody on our planet, let alone enough for a comfortable life support. If you want to raise a family and have a comfortable life for them, you are going to have to deprive many others of the opportunity to survive and the sooner, the better. Your grandmother's Golden Rule is beautiful, but it doesn't work.'" p. 123. Critical Path, R. Buckminster Fuller Is it possible to have a win-win between people an business? Are there any financial barriers to entry and/or partnership? Sometimes I fear that I will never be paid enough to implement my ideas, or if I do then it will be too late to enter the market. Either I can't afford to do the work, or someone who developed and patented something that matches at least some of my idea decides not to involve me. Thus I would question spending the time developing my idea. I'm assuming I can develop my idea for my own personal use (possibly not?). However, I am more certain I may have trouble sharing and selling things developed from my ideas. I imagine that this favors those who already have money. People like Eric von Hippel and Michael Bauwens both speak about a lot of innovation goinf on outside the firm. For example Michel Bauwen's states: "The French-Italian school of 'cognitive capitalism' stresses the value creation today is no longer confined to the enterprise, but beholden to the mass intellectuality of knowledge workers, who through their lifelong learning/experiencing and systematic connectivity, constantly innovate within and without the enterprise. This is an important argument, since it would justify what we see as the only solution for the expansion of the P2P sphere into a society at large: the universal basic income. Only the independence of work and the salary structure can guarantee the peer producers can continue to create this sphere of highly productive use value." The Political Economy of Peer Production (www.ctheory.net/articles.aspx?id=499) Eric von Hippel also speaks about his book. (http://commons.wikimedia.org/wiki/File:20060123-Eric.von.Hippel-Democratizing.Innovation.ogg) However, giving people money for doing nothing makes me feel uncomfortable. Of course, as Heinz Dietrich suggests, if you already have money, things work just fine: "The first step, in fact, would be to establish a new cybernetic principle; you need something that coordinates billions of economic transactions everyday. And, so far, the market has been a relatively well-functioning system under two conditions: If the market is not monopolistic and you have the buying power for the merchandise you produce and for the services, then the market coordinates quite well."-- The Socialism of the 21st Century (http://eipcp.net/transversal/0805/dieterich/en) Paul Cockshott, and Allin Cottrell suggest a payment system determined democratically, "The payment system outlined in chapter 2 depends on the idea that the total labour content of each product or service can be calculated." p. 8, Towards a New Socialism If this is by the state, then I am moved to say I do not trust the government to do much right at all. Certainly, this is what I feel if I spend any length of time watching the news. But I would like to look into it. If this develops into something, the state should be involved at some level. I feel bad about this. I'll have to read more. However, I agree that with more democracy things would be better. "The principal bases for a post-Soviet socialism must be radical democracy and efficient planning. The democratic element, it is now clear, is not a luxury, or something that can be postponed until conditions are especially favourable. Without democracy, as we have argued above, the leaders of a socialist society will be driven to coercion in order to ensure the production of a surplus product, and if coercion slackens the system will tend to stagnate." p. 7, Towards a New Socialism I definately think there needs to be some way to accomplish things that makes it fair to people. In terms of me, I believe this underlies a larger problem than me being connected with the right job or being afraid of debt going back to school. It is the problem of connecting people with the right jobs, utilizing the skills they already have so they don't have to fear paying to learn what they already know, and raising awareness that the jobs are there. I dream about linked data being able to illuminate relationships between present skills and related skills to job seekers and employers. I also dream about linked data allowing people to market themselves with clarity as a basket of skills that represents who they really are rather than a basket of skills that was set by a well-meaning college, trade-school, or university. I honestly believe that people who do something they have a passion for, will be more effective employees or entrepreneurs. But how to pay for it? If you take out debt you need to find a way to pay it off. If you can't find something that reflects your values you may feel like you're enslaved to something else while trying to pay it off. It can be a pressing struggle as Paul Grignon's Money as Debt video on Youtube describes (https://www.youtube.com/watch?v=0K5_JE_gOys). Paul Grigon and others say that our present monetary system leads to infinite growth. "We need to become politically sensitive to the invisible architectures of power. In distributed systems, where there is no overt hierarchy, power is a function of design. One such system, perhaps the most important of all, is the monetary system, whose interest-bearing design requires the market to be linked to a system of infinite growth, and this link needs to be broken. A global reform of the monetary system, or the spread of new means of direct social production of money, are the necessary conditions for such a break." (http://p2pfoundation.net/About_The_Foundation) I'd imagine this would create no problems for people as long as there is the will and resources to grow infinitely. However, Paul Grigon points out an exception: those with the money to lend at interest will eventually wind up with all of the money, and due to forclosure the property too. My site explores distributed funding. (http://adistributedeconomy.blogspot.com/2012/03/distributed-funding.html). I am still not sure how exactly to accomplish it. I think it may involve something like Ripple (https://classic.ripplepay.com/) and PaySwarm (http://payswarm.com/). A friend of mine pointed out that it did not seem that Ripple allows to keep track of what you owe who, whereas PaySwarm appears to do so. I may need to develop something on my own (http://lists.w3.org/Archives/Public/public-webpayments/2013Feb/0034.html) that involes donations, and whatever models are needed. Embarrasingly, I'm still learning JavaScript. Thankfully, my friends are also encouraging me to focus on some small project. A few other thoughts: As I was reading, I noticed some mention of rival and non-rival goods. Rival goods could be seen as raw materials or products, and non-rival goods could exist in an infinite amount. In the maker world I see things such as CAD files as non-rival and raw materials and end products as rival. I question whether people would still pay for rival goods, and perhaps donate for non-rival goods if there was an open source economy? What if things such as PaySwarm made it easy to do so? The Rep Rap and Ardrino are open source hardware, and all products by Makerbot used to be (http://josefprusa.cz/open-hardware-meaning/, http://www.hoektronics.com/2012/09/21/makerbot-and-open-source-a-founder-perspective/). People can share their designs, but would people share their profits with those who contributed to their idea? It wouldn't have to be much, as small amounts still add up. Would this be bad? Even if people don't have to pay, things might still vary as does the amount you might get by selling a book? Concieveably if you have a lot of open source hardware, then you could have as much flexibility in the physical world as you do in the software world. In an extreme case, maybe you could have open source spaceships. They are after all lots of little parts, much like a GNU/Linux distro. If things could be freely copied and not exclusively owned as in the GPL, would you still have brand loyalty? While not going into the fine details, the Ultimaker and the Makerbot Thing-O-Matic look very similar. Why would I want one over the other? If whatever you chose was linked to previous innovations, and people let their donations flow to those authors, how much would it matter? Would the crowd maintain accountability so people would not collect money for doing nothing? The maker community seems to be supportive of things that they are free to contribute to. How far could this go, especially with support from arguments made by Don Tapscott and Anthony D. Williams in the book Wikinomics? For the legality, things like the JOBs act seem exciting. However, this seems to be for equity-based crowdfunding and not just donations (https://en.wikipedia.org/wiki/JOBS_Act). I'd imagine that it would be both even if some of the things were as described above. What if you were retired, and you had money, but nothing you contributed was being used? Could you grow your money to support yourself? The potential of digital technologies seems huge. I read about the Industrial Internet, as pointed out by Milton Poson. The GE report titled, "Industrial Internet. Pushing the Boundaries of Minds and Machines", by Peter C. Evans and Marco Annunziata has the following quote: "The combination of physics- based approaches, deep sector specific domain expertise, more automation of information flows, and predictive capabilities can join with the existing suite of ?big data? tools. The result is the Industrial Internet encompasses traditional approaches with newer hybrid approaches that can leverage the power of both historic and real-time data with industry specific advanced analytics." Of course, this makes me want to go down the path of Density Functional Theory and Molecular Dynamics. I had a brief exposure to these concepts in graduate school, and it reminds me of the layout algorithms in Gephi (at least MD, I know a little less about DFT). Yes! I just learned about DBSCAN (http://en.wikipedia.org/wiki/DBSCAN) in R (http://www.cl.cam.ac.uk/~dq209/others/Rdatamining.pdf) and ELKI (http://en.wikipedia.org/wiki/ELKI). And here you have it, the original DBSCAN paper (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.121.9220). In addition, they speak about Enterprise Management Software in terms of the Industrial Internet: "At the other end of the spectrum, enterprise management software and solutions have been widely adopted to drive organizational efficiencies at the firm level. The benefits of these efforts include better tracking and coordination of labor, supply chain, quality, compliance, and sales and distribution across broad geographies and product lines. However, these efforts have sometimes fallen short because while they can passively track asset operations at the product level, the ability to impact asset performance is limited. Optimizing the system to maximize asset and enterprise performance is what the Industrial Internet offers." This reminds me of a presentation given by Dr. Manoj Dharwadkar of Bentley Systems Inc. titled, "Using Sematic Web Technologies in Open Applications" (http://www.w3.org/2008/12/ogws-slides/Bentley.pdf). It also reminds me of the The Simantics Platform at the VTT Technical Research Centre of Finland (www.vtt.fi) and the mission of Dassault Systems (www.3ds.com). They all have the ISO15926 ontology in common. I wasn't sure if they were talking about linked data in the report: "To make information intelligent, new connections need to be developed so that Big Data ?knows? when and where it needs to go, and how to get there. If imaging data is better connected, the right doctor could automatically receive a patient?s rendered images so the information is finding the doctor instead of the doctor finding the information. " --- Opportunity for Liked Data? random paper with medical devices communicating with the semantic web: http://radiographics.rsna.org/content/30/7/2039.abstract http://www.mdpnp.org/uploads/8-3_Schluter_26Jan.pdf (devices commmunicating, like Industrial Internet) Further, they go into what is needed to to build the Industrial Internet: "The Industrial Internet will require an adequate backbone. Data centers, broadband spectrum, and fiber networks are all components of the ICT infrastructure that will need to be further developed to connect the various machines, systems, and networks across industries and geographies. This will require a combination of inter- and intra- state infrastructure order to support the significant growth in data flows involved with the Industrial Internet. " I heard that Oklahoma, and the U.S. in general, needs more fiber. Someone said that Denver, Dallas, Kansas City, Silicon Valley, Austin(?), all have good networks. How would the talent to build the Industrial Internet be gathered? Here are a few more quotes: "Other alternatives for sourcing cross-discipline talent might include developing the existing resources in the native domain through collaborative approaches. Instead of building or buying talent that has multiple skills, create environments that accelerate the ability of people with different skills to interact and innovate together. On a larger scale, approaches such as crowdsourcing might be able to close some of the capabilities gaps that are sure to occur." "Today, the people that manage big data systems or perform advanced analytics have developed unique talents through self-driven specialization, rather than through any programs that build a standard set of skills or principles. Co-development of curriculum, integration of academic staff into industry, and other approaches will be needed to ensure that the talent needs of the Industrial Internet do not outpace the educational system." There definately is a lag between the development of IT, and its adoption. In Chemical Engineering, I'm pretty sure people thought I was crazy when I started talking about the Semantic Web. People in network security, and even computer science were not familiar with it. If you're talking about Wikinomics (Openness, Peering, Sharing, Acting Global) thinking there might be some growth to do. I heard of people at universities and hackerspaces speak of themselves as universities, but their culture is very different. Maybe hackerspaces are on the extreme of being open, whereas universities are less so? Maybe this is the case with IP. Maybe less so, with papers (but who can access them?). See a presentation in 2008 by RIC Jackson, then Director of the FIATECH Consortium: (http://www.slccc.net/documents_pdf/Technology-Ric%20Jackson%200811.pdf). Adoption of new tech for the enterprise is slow: (http://pandodaily.com/2012/02/11/why-oracle-may-really-be-doomed-this-time/). There are some, such as the Mayor of Newark, NJ, who bothered to go to SXSW to speak about the adoption of more tech: (http://pandodaily.com/2013/03/10/cory-booker-calls-for-tech-empowered-open-democracy/). Here are three more quotes from the report: "Measures to ensure the security of restricted data, including intellectual property,proprietary information, and personally identifiable information (PII) are critical. " --- this reminds me of the Read Write Web Community Group "Currently there are several standards bodies, but they are fragmented. The promotion and adoption of common and consistent standards on data structure, encryption, transfer mechanisms, and the proper use of data will go a long way in advancing cyber security." I was made fun of by a CS graduate when I was excited about a possible new standard. "Academia: Further research on data security and privacy should be pursued, including research on enhancing IT security, metrology, inferencing concerns with non- sensitive data, and legal foundations for privacy in data aggregation." Perhaps more collaboration with the hacker community? Is it true that some programmers, and some in CS tend to build things and ignore security in the process? I wonder what is going on at hacker conferences like Blackhat and DEFCON. BTW, people at the Chaos Communication Congress are geniuses. Whew! That's enough. If you're interested in more, read the report. It's exciting. :) I asked myself this question: What is the future role of the University? The university may serve as a repository for books, a place to do research, and a meeting place. Lectures? I'm not sure. How do the things that Michael Hammer & Lisa W. Hershman talk about fit in? They wrote a book titled, "Faster, Cheaper, Better: The 9 Levers for Transforming How Work Gets Done". I believe they were talking about Business Process Improvement (https://en.wikipedia.org/wiki/Business_process_improvement). Would Process Owners, as mentioned by them, serve a major role in the Industrial Internet? (http://it.toolbox.com/wiki/index.php/Process_Owner) ---------------- Resources that I am considering reading: The Net Delusion: The Dark Side of Internet Freedom, Evengy Morozov, 2011 To Save Everything, Click Here: The Folly of Technological Solutionism, Evengy Morozov, 2013 The Wealth of Networks, Yochai Benkler, Yale University Press, 2006 Science and the Crisis in Society, Frank H. George, Wiley, 1970 Future Perfect: The Case for Progress in a Networked Age, Steven Johnson, 2012 Here Comes Everybody: The Power of Organization Without Organizations, Clay Shirky, 2008 Nasa's Advanced Automation for Space Missions, http://www.islandone.org/MMSG/aasm/ (Robots, Expert Systems, Etc..), The Technical Stuff, 1980 The Future: Six Drivers of Global Change, Al Gore, 2013, http://www.amazon.com/The-Future-Drivers-Global-Change/dp/0812992946, Reviewed by Tim Berners-Lee, may relate well to the previous link An Inquiry to Into the Nature and Causes of the Wealth of Nations, Adam Smith, LL.D. F.R.S., MDCCCXLIII (1843) (according to Wikipedia, it was first published in 1776) Books by Chris Anderson and Lawrence Lessig Consent of the Networked: The Worldwide Struggle for Internet Freedom, Rebecca MacKinnon, 2012 Business Process Improvement: the breakthrough strategy for total quality, productivity, and competitiveness, H J Harrington , 1991 Faster, better, cheaper : low-cost innovation in the U.S. space program, Howard E McCurdy, 2001 On Wed, Jan 9, 2013 at 11:42 PM, Michel Bauwens wrote: it seems to me that these shifts have already started, before 2013, including in these fields, but are also much more long-term transformations ... in the case of deep-pocketed and politically powerful vested interests, only moderate bottom-up advances can be expected in the very short term ... both telecom and banking are still heavily centralized, they enabled people-based p2p dynamics but control the infrastructure, the data, the design and many other aspects of their only partly distributed systems ... I'm sure the same is true of GE .. no corporation will allow a fully p2p distributed system without some form of centralized control Michel On Thu, Jan 10, 2013 at 2:54 AM, ProjectParadigm-ICT-Program wrote: 2013 will see the advent of new paradigms for infrastructures that up until now where centralized, i.e. electric power generation and distribution, intermodal transportation and logistics, food and agro-industrial production and distribution, industrial production and distribution, consumer products manufacturing and distribution, pharmaceuticals production and distribution, energy extraction and distribution (including coal, gas, shale oil/gas and biofuels). The data and telecom infrastructure and parallel the banking and financial sectors are the only ones espousing decentralized distributed P2P (and B2B) processes. Resilience is a property that can only be achieved by copying the structure of the internet and some of its inherent characteristics. By defining strategic infrastructures as decentralized networks of distributed P2P (B2B) processes embedded in an intelligent grid it becomes possible to define resilience in a way similar to the resilience of the Internet. And a resilient grid lends itself perfectly to embedding in a semantic web overlay grid. The Industrial Internet as defined by GE and outlined in a recent white paper comes pretty close to it but not quite yet. See http://www.gereports.com/meeting-of-minds-and-machines/. Milton Ponson GSM: +297 747 8280 PO Box 1154, Oranjestad Aruba, Dutch Caribbean Project Paradigm: A structured approach to bringing the tools for sustainable development to all stakeholders worldwide by creating ICT tools for NGOs worldwide and: providing online access to web sites and repositories of data and information for sustainable development 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 the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. ________________________________ From: Brent Shambaugh To: ProjectParadigm-ICT-Program Cc: Michel Bauwens ; Samuel Rose ; "public-lod at w3.org" ; Paul Cockshott Sent: Wednesday, January 9, 2013 2:10 AM Subject: Re: A Distributed Economy -- A blog involving Linked Data Oh well, I'll share my story on a W3C forum no less. Model, true. Would my experiences even translate? I think you'd have to see this from my own personal perspective. Even though I grew up in an American home there was a lot of discourse in my family. There wasn't a lot of room for personal expression, and my family was very religious so I was afraid of offending God if I went against the dominating figure and/or ideology in the family. I was also very shy growing up, and I did not have much money, even though I came from an upper middle class family. I felt out of place most of the time, and sometimes I had ideas that people did not seem to understand or be interested in. I liked computers, and wanted to learn more about them. I was always asking people doing computer stuff how to program, even though I had a lot of trouble doing it myself. I think it was because I struggled with algebra (and other maths), but more so algebra. I also was a bit lost in some documentation, and may have not been fully aware of other resources that may have helped. I was afraid of tinkering, but I built webpages and was proud of them and I also built structures in the woods (but that is a bit off topic). My family paid for my college. I'm thankful for that, but it also leaves me with a feeling of responsibility to them. I'll admit to not being in sync with things in my undergraduate years. It looks very good if you have an internship. But at the time I made a few mistakes perhaps. I was a bit afraid to try because the companies I qualified for either were not doing something that interested me and/or something that I felt reflected my beliefs, values and possibly something else that is hard to describe. In short, perhaps passion. Over time I realized that it would probably be wiser to accept things as is if I ever hoped to be employed. Making the sale was difficult though. I think perhaps people think I'm lazy, or uniformed, because I did not work (except for academic things) in college. Or was it emotion? Ideas out of place? I was also affected by many of the same family things growing up. I have an interest in physics, electronics, economics, systems, etc. I think that if I ever hope to use my education, and share what I have learned, I need to do something amazing. I could go back to school, take on a lot of debt, and just hope that I get enough good grades to impress enough people (and not have them think I'd get bored when trying to get a job). Or I could learn things on my own, participate in projects, and hope that people receive me with open arms. Since 2007 when I discovered Polywell nuclear fusion I've gained new perspective on the world. I never actually built a fusion reactor, but I did try to learn what was behind them. This motivated me to read lots of books, and my desire to do other things to explore my uniqueness as an individual led to even more books. GNU/Linux facilitated my graduate work, and I can relate to it's philosophy through my many frustrations. Open source is great, because I don't have to worry so much about my skills wasting away. Being at the university also helps. I also don't have to manufacture things or do anything special to have excitement about it. But you know, how much can you actually get from someone who hasn't experienced that much real employment? Because of that automatically people see me in a certain way. And my views may not be necessarily realistic for lack of experience. But whatever it is, it seems I have have found a lot of energy and my friends seem to notice. I think about what I am learning more too. But would this model help people in the real world? I feel that had it existed it could have helped me growing up, but that is my own personal experience. In addition to studying, a lot of my peers spent their time drinking beer, socializing, and playing and/or watching sports. And most seemed to have more money. Now most seem to have even more money, and spend time on Facebook talking about things they have bought or families that they are raising. Their educational level is hard to discern. Not many seem to be posting things about hacking, making or things that might suggest deep insight. But not everyone fits that. I guess what matters is whether it will work or not, and whether it truly will benefit others. For that both an experiment and conversation will help. Thank you Samuel for referring me to Michael. Milton, I am not certain what it will do yet. I am not certain what resilience truly means. I'm definitely bothered by the wastefulness brought upon by obsolescence of products. It would be much better I think if we knew how they worked so we could reuse the them (I'm saying the parts) in other things. We've had this problem at the hackerspace. We have lots of stuff around that if we had the blueprint, it would be much better. If we knew how this blueprint connected to other things I personally think that would be even better. On a separate issue. In graduate school there were people there that seemed really lost. I mean they were doing their work, but didn't seem to have a joy about it. There also was not a lot of organization, and it was hard to find things. Outside of school, there are people that I know could go to graduate school but didn't. It was frustrating to me that I could not seem to sell them on thinking more deeply about things, or when they said I was really smart (but did not have the confidence or belief that they could do it themselves). Still others just weren't there. I've seen those who weren't there at the hackerspace. I question why, and think the world would be a better place if this could be tapped into. " Roberto Verzola is to my mind the political economist who has done most in studying this, see http://p2pfoundation.net/Category:Commons_Economics ; Wolfgang Hoeschele is planning an ambitious database based on a Needs, Organisational REsources, (I forgot what the A stands for) I'm sure that the proposed modelling effort will contribute to this field; if you are ideologically open, you may also want to talk with people like Paul Cockshott and the people of the Center for Transition Science at UNAM in Mexico City; who are very good at econometric modelling and interested in a cybernetic planning revival, " I still have to think more about this. I was reading over it a bit today. I might have seen something about this today. Someone was talking about how technologies were allowing us (or could? ) to become more mobile, and that people really didn't have to be co located. I don't remember what technologies that they were referring. "Peer to peer processes in addition should be defined as geography independent, historically nomads, hunter gatherers and technomads in the modern age all show this to be true." I hope to write soon. On Tue, Jan 8, 2013 at 6:57 PM, Brent Shambaugh wrote: I'm feeling that this is shaped by my own personal experience? I'm willing, but should I risk putting it out there? -- P2P Foundation: http://p2pfoundation.net - http://blog.p2pfoundation.net Updates: http://twitter.com/mbauwens; http://www.facebook.com/mbauwens #82 on the (En)Rich list: http://enrichlist.org/the-complete-list/ -- P2P Foundation: http://p2pfoundation.net - http://blog.p2pfoundation.net Updates: http://twitter.com/mbauwens; http://www.facebook.com/mbauwens #82 on the (En)Rich list: http://enrichlist.org/the-complete-list/ _______________________________________________ P2P Foundation - Mailing list http://www.p2pfoundation.net https://lists.ourproject.org/cgi-bin/mailman/listinfo/p2p-foundation From pjmakey2 at gmail.com Mon Mar 18 00:59:05 2013 From: pjmakey2 at gmail.com (Peter juliano) Date: Mon, 18 Mar 2013 00:59:05 -0400 Subject: decode php base64 Message-ID: Not long ago, my friend resignation of the company. He left a few app's in php, some of those files are hashed with base64 code, he told me that those files handle http request on the server and some security rules. Because i'm migrating all these applications on django. I do not really care about those files, but today just for playing around, i try to see the code, and in a less of an hour can see all the code. I want to share the solution with this mail list http://pastebin.com/e6KJhAW8 -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Mon Mar 18 03:26:19 2013 From: frank at chagford.com (Frank Millman) Date: Mon, 18 Mar 2013 09:26:19 +0200 Subject: Just curious - I thought dict keys would maintain sequence Message-ID: Hi all I know that you cannot rely on the order of keys in a dictionary, and I am not attempting to do so. Nevertheless, the following surprised me. A program creates a dictionary with a known set of keys. I would have thought that multiple runs of the program would return the keys in the same sequence. As you can see, the results appear to be totally random. Just out of interest, I would appreciate an explanation. Thanks Frank Millman F:\>type test.py test_list = [ 'ert', 'jhg', 'yer', 'nli', 'vrg', 'qnh', 'kyh', 'cgj', 'lys', 'vyk', 'dws', 'fuj', 'ghj', 'puy', 'brc', 'dhy', 'jkl', 'gfd', 'jtf', 'dfp'] test_dict = dict([(x, None) for x in test_list]) print(test_dict.keys()) F:\>test.py dict_keys(['ghj', 'qnh', 'lys', 'ert', 'jhg', 'dfp', 'vrg', 'dws', 'jtf', 'puy', 'yer', 'brc', 'kyh', 'jkl', 'gfd', 'nli', 'fuj', 'dhy', 'cgj', 'vyk']) F:\>test.py dict_keys(['vrg', 'dfp', 'brc', 'yer', 'nli', 'jhg', 'cgj', 'ert', 'dws', 'gfd', 'puy', 'vyk', 'ghj', 'jkl', 'jtf', 'kyh', 'qnh', 'fuj', 'dhy', 'lys']) F:\>test.py dict_keys(['yer', 'nli', 'brc', 'fuj', 'cgj', 'dfp', 'dhy', 'vrg', 'jkl', 'jtf', 'vyk', 'ghj', 'qnh', 'kyh', 'gfd', 'ert', 'dws', 'jhg', 'lys', 'puy']) Python version is 3.3.0, win32. From rosuav at gmail.com Mon Mar 18 03:31:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Mar 2013 18:31:33 +1100 Subject: Just curious - I thought dict keys would maintain sequence In-Reply-To: References: Message-ID: On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman wrote: > Hi all > > I know that you cannot rely on the order of keys in a dictionary, and I am > not attempting to do so. > > Nevertheless, the following surprised me. A program creates a dictionary > with a known set of keys. I would have thought that multiple runs of the > program would return the keys in the same sequence. As you can see, the > results appear to be totally random. > > Just out of interest, I would appreciate an explanation. Mainly, it's just something you utterly cannot depend on, so it's allowed to vary based on the phase of the moon, the position of your hard drive platters, or anything else it likes. The hashing is actually randomized in recent versions of Python as a defense against a denial of service attack by generating hash collisions; that's most likely what you're seeing there. The dictionary object is not deterministic to that extent. :) ChrisA From frank at chagford.com Mon Mar 18 03:49:05 2013 From: frank at chagford.com (Frank Millman) Date: Mon, 18 Mar 2013 09:49:05 +0200 Subject: Just curious - I thought dict keys would maintain sequence In-Reply-To: References: Message-ID: On 18/03/2013 09:31, Chris Angelico wrote: > On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman wrote: >> Hi all >> >> I know that you cannot rely on the order of keys in a dictionary, and I am >> not attempting to do so. >> >> Nevertheless, the following surprised me. A program creates a dictionary >> with a known set of keys. I would have thought that multiple runs of the >> program would return the keys in the same sequence. As you can see, the >> results appear to be totally random. >> >> Just out of interest, I would appreciate an explanation. > > Mainly, it's just something you utterly cannot depend on, so it's > allowed to vary based on the phase of the moon, the position of your > hard drive platters, or anything else it likes. The hashing is > actually randomized in recent versions of Python as a defense against > a denial of service attack by generating hash collisions; that's most > likely what you're seeing there. The dictionary object is not > deterministic to that extent. :) > Now that you mention it, I do remember reading about the recent addition of a random element to the hashing mechanism. I am sure that is the explanation. Thanks, Chris Frank From __peter__ at web.de Mon Mar 18 03:52:28 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Mar 2013 08:52:28 +0100 Subject: Just curious - I thought dict keys would maintain sequence References: Message-ID: Chris Angelico wrote: > On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman wrote: >> Hi all >> >> I know that you cannot rely on the order of keys in a dictionary, and I >> am not attempting to do so. >> >> Nevertheless, the following surprised me. A program creates a dictionary >> with a known set of keys. I would have thought that multiple runs of the >> program would return the keys in the same sequence. As you can see, the >> results appear to be totally random. >> >> Just out of interest, I would appreciate an explanation. > > Mainly, it's just something you utterly cannot depend on, so it's > allowed to vary based on the phase of the moon, the position of your > hard drive platters, or anything else it likes. The hashing is > actually randomized in recent versions of Python as a defense against > a denial of service attack by generating hash collisions; that's most > likely what you're seeing there. The dictionary object is not > deterministic to that extent. :) If you set the PYTHONHASHSEED environment variable you will see the same order for every invocation. Anecdotal evidence: $ python3.3 -c'print(dict.fromkeys("abcde", ""))' {'c': '', 'b': '', 'a': '', 'e': '', 'd': ''} $ python3.3 -c'print(dict.fromkeys("abcde", ""))' {'a': '', 'c': '', 'b': '', 'e': '', 'd': ''} $ python3.3 -c'print(dict.fromkeys("abcde", ""))' {'b': '', 'c': '', 'a': '', 'd': '', 'e': ''} $ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys("abcde", ""))' {'e': '', 'd': '', 'a': '', 'c': '', 'b': ''} $ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys("abcde", ""))' {'e': '', 'd': '', 'a': '', 'c': '', 'b': ''} $ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys("abcde", ""))' {'e': '', 'd': '', 'a': '', 'c': '', 'b': ''} Only str, byte and datetime keys are affected. See http://docs.python.org/dev/reference/datamodel.html#object.__hash__ http://docs.python.org/dev/using/cmdline.html#envvar-PYTHONHASHSEED From steve+comp.lang.python at pearwood.info Mon Mar 18 03:59:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 07:59:51 GMT Subject: Just curious - I thought dict keys would maintain sequence References: Message-ID: <5146c976$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 18:31:33 +1100, Chris Angelico wrote: > On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman > wrote: >> Hi all >> >> I know that you cannot rely on the order of keys in a dictionary, and I >> am not attempting to do so. >> >> Nevertheless, the following surprised me. A program creates a >> dictionary with a known set of keys. I would have thought that multiple >> runs of the program would return the keys in the same sequence. As you >> can see, the results appear to be totally random. >> >> Just out of interest, I would appreciate an explanation. > > Mainly, it's just something you utterly cannot depend on, so it's > allowed to vary based on the phase of the moon, the position of your > hard drive platters, or anything else it likes. The hashing is actually > randomized in recent versions of Python as a defense against a denial of > service attack by generating hash collisions; that's most likely what > you're seeing there. The dictionary object is not deterministic to that > extent. :) Correct. If you try the same in Python 3.2 instead of 3.3, you will get the same order each time. You can read more about the dictionary hashing attack here: http://mail.python.org/pipermail/python-dev/2011-December/115116.html http://bugs.python.org/issue13703 http://bugs.python.org/issue14621 The current status is that Python's dict hashes are improved, but still leak enough information that attackers can cause a Denial Of Service attack with just a bit more effort than before, but work is ongoing to solve this issue. -- Steven From moonhkt at gmail.com Mon Mar 18 05:34:58 2013 From: moonhkt at gmail.com (moonhkt) Date: Mon, 18 Mar 2013 02:34:58 -0700 (PDT) Subject: Read utf-8 file Message-ID: <1f54b5e0-efac-4636-921d-aa087d05df44@a14g2000vbm.googlegroups.com> File have China Made ?? ? http://www.fileformat.info/info/unicode/char/4e2d/index.htm UTF-16 (hex) 0x4E2D (4e2d) UTF-8 (hex) 0xE4 0xB8 0xAD (e4b8ad) Read by od -cx utf_a.text 0000000 ? ** ** ? ** ** ? ** ** \n e4b8 ade5 9c8b e8a3 bd0a 0000012 Read by python, why python display as beow ? ??? u'\u4e2d\u570b\u88fd\n' <--- Value ??? <-- UTF-8 value u'\u4e2d' ? CJK UNIFIED IDEOGRAPH-4E2D u'\u570b' ? CJK UNIFIED IDEOGRAPH-570B u'\u88fd' ? CJK UNIFIED IDEOGRAPH-88FD import unicodedata import codecs # UNICODE .... file = codecs.open(options.filename, 'r','utf-8' ) try: for line in file: #print repr(line) #print "=========" print line.encode("utf") for keys in line.split(","): print repr(keys) ," <--- Value" , keys.encode("utf") ,"<-- UTF-8 value" for key in keys: try: name = unicodedata.name(unicode(key)) print "%-9s %-8s %-30s" % ( (repr(key)), key.encode("utf") , name ) How to display e4b8ad for ? in python ? From __peter__ at web.de Mon Mar 18 06:37:05 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Mar 2013 11:37:05 +0100 Subject: Read utf-8 file References: <1f54b5e0-efac-4636-921d-aa087d05df44@a14g2000vbm.googlegroups.com> Message-ID: moonhkt wrote: > How to display > e4b8ad for ? in python ? Python 2 >>> print u"?".encode("utf-8").encode("hex") e4b8ad Python 3 >>> print(binascii.b2a_hex("?".encode("utf-8")).decode("ascii")) e4b8ad From astrojohnr at gmail.com Mon Mar 18 08:55:18 2013 From: astrojohnr at gmail.com (John Rowland) Date: Mon, 18 Mar 2013 05:55:18 -0700 (PDT) Subject: "Learn Python Quickly" is FREE today March 18th Message-ID: <9cbb3e88-b3a3-4a93-9e4f-6e6d415a3a72@googlegroups.com> For just today, the book "Learn Python Quickly" is free to download from Amazon. Also, go to www.learnpythonquickly.com for more information. From tjreedy at udel.edu Mon Mar 18 23:23:07 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2013 23:23:07 -0400 Subject: "Learn Python Quickly" is FREE today March 18th In-Reply-To: <9cbb3e88-b3a3-4a93-9e4f-6e6d415a3a72@googlegroups.com> References: <9cbb3e88-b3a3-4a93-9e4f-6e6d415a3a72@googlegroups.com> Message-ID: On 3/18/2013 8:55 AM, John Rowland wrote: > For just today, the book "Learn Python Quickly" is free to download > from Amazon. Also, go to www.learnpythonquickly.com for more > information. I just 'bought' this to see if it is something I would recommend. I turned first to the IDLE section. A couple of suggestions: "Click Run -> Run Module F5 The following window will appear " That soon gets to be a nuisance and can be turned off with Options / Configure IDLE / General / Autosave Preferences (x) No prompt. I think even beginners should learn about the configure dialog. "It is essential that you include the .py extension." We fixed that nuisance last summer for 3.3. So: "For python versions before 3.3, ...." -- Terry Jan Reedy From astrojohnr at gmail.com Tue Mar 19 19:12:18 2013 From: astrojohnr at gmail.com (John Rowland) Date: Tue, 19 Mar 2013 16:12:18 -0700 (PDT) Subject: "Learn Python Quickly" is FREE today March 18th In-Reply-To: <9cbb3e88-b3a3-4a93-9e4f-6e6d415a3a72@googlegroups.com> References: <9cbb3e88-b3a3-4a93-9e4f-6e6d415a3a72@googlegroups.com> Message-ID: <663387ea-b7fe-485c-922e-6d7b9785fff7@googlegroups.com> On Monday, March 18, 2013 12:55:18 PM UTC, John Rowland wrote: > For just today, the book "Learn Python Quickly" is free to download from Amazon. > > Also, go to www.learnpythonquickly.com for more information. To Terry Reedy. That's just the sort of constructive criticism I was hoping would be forthcoming. Thank you. I'll note this on the web site and include it in the first book update. JR From laxmikant.general at gmail.com Mon Mar 18 09:30:15 2013 From: laxmikant.general at gmail.com (Laxmikant Chitare) Date: Mon, 18 Mar 2013 19:00:15 +0530 Subject: "eval vs operator.methodcaller" - which is better? Message-ID: Hi, I have a program that picks module and method name from a configuration file and executes the method. I have found two ways to achieve this. Apporach 1: --------------------------- moduleName = 'mymodule' #These two variables are read from conf file. methodName = 'mymethod' import operator myModule = __import__('mymodule') myMethod = operator.methodcaller('mymethod') val = myMethod(myModule) print val --------------------------- Apporach 2: --------------------------- moduleName = 'mymodule' #These two variables are read from conf file. methodName = 'mymethod' val = eval('myModule.' + methodName + '()') print val --------------------------- Question: Which approach is better and why. Is there any other better way to do this? Regards, Laxmikant From rosuav at gmail.com Mon Mar 18 09:39:10 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 00:39:10 +1100 Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare wrote: > moduleName = 'mymodule' #These two variables are read from conf file. > methodName = 'mymethod' > > import operator > myModule = __import__('mymodule') > myMethod = operator.methodcaller('mymethod') > val = myMethod(myModule) > print val Is there any reason not to do the obvious? val = myModule.__getattribute__(methodName)(... args ...) Works in 2.6 and 3.3, at least on the trivial example I tried. ChrisA From laxmikant.general at gmail.com Mon Mar 18 09:58:37 2013 From: laxmikant.general at gmail.com (Laxmikant Chitare) Date: Mon, 18 Mar 2013 19:28:37 +0530 Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: References: Message-ID: Aha, that was smart Chris. Thank you. But this raises another question in my mind. What is the use case for operator.methodcaller ? On 3/18/13, Chris Angelico wrote: > On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare > wrote: >> moduleName = 'mymodule' #These two variables are read from conf file. >> methodName = 'mymethod' >> >> import operator >> myModule = __import__('mymodule') >> myMethod = operator.methodcaller('mymethod') >> val = myMethod(myModule) >> print val > > Is there any reason not to do the obvious? > > val = myModule.__getattribute__(methodName)(... args ...) > > Works in 2.6 and 3.3, at least on the trivial example I tried. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Mon Mar 18 10:03:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 01:03:03 +1100 Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 12:58 AM, Laxmikant Chitare wrote: > Aha, that was smart Chris. Thank you. > > But this raises another question in my mind. What is the use case for > operator.methodcaller ? Most of the operator module is functional versions of what can be done elsewhere with operators. They're not generally needed unless you specifically need a function, such as for a map() call: >>> a=[1,2,3,4,5] >>> b=[50,40,30,20,10] >>> list(map(operator.add,a,b)) [51, 42, 33, 24, 15] (The list() call is unnecessary in Python 2, but means this will also work in Python 3.) ChrisA From steve+comp.lang.python at pearwood.info Mon Mar 18 10:23:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 14:23:27 GMT Subject: "eval vs operator.methodcaller" - which is better? References: Message-ID: <5147235f$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 19:28:37 +0530, Laxmikant Chitare wrote: > Aha, that was smart Chris. Thank you. > > But this raises another question in my mind. What is the use case for > operator.methodcaller ? The use-case is mostly to allow people to write code in a functional style, if they so choose. import operator func = operator.methodcaller("spam") items = map(func, [a, b, c, d]) is the functional-style equivalent of: items = [obj.spam() for obj in [a, b, c, d]] methodcaller makes a little more sense if you provide arguments: func = operator.methodcaller("spam", 1, 2, None, "ham") items = map(func, [a, b, c, d]) compared to: items = [obj.spam(1, 2, None, "ham") for obj in [a, b, c, d]] I expect that the methodcaller version will be very slightly faster in this case, since it doesn't have to parse the arguments every time the method is called. -- Steven From jeanmichel at sequans.com Mon Mar 18 09:58:44 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 18 Mar 2013 14:58:44 +0100 (CET) Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: Message-ID: <1282143233.6013541.1363615124749.JavaMail.root@sequans.com> ----- Original Message ----- > Hi, > > I have a program that picks module and method name from a > configuration file and executes the method. I have found two ways to > achieve this. > > Apporach 1: > --------------------------- > moduleName = 'mymodule' #These two variables are read from conf > file. > methodName = 'mymethod' > > import operator > myModule = __import__('mymodule') > myMethod = operator.methodcaller('mymethod') > val = myMethod(myModule) > print val > --------------------------- > > Apporach 2: > --------------------------- > moduleName = 'mymodule' #These two variables are read from conf > file. > methodName = 'mymethod' > > val = eval('myModule.' + methodName + '()') > print val > --------------------------- > > Question: Which approach is better and why. Is there any other better > way to do this? > > Regards, > Laxmikant > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, Any alternative to eval is always better than eval (aka eval is evil). Your code is not working in my python 2.5 env (operator has no methodcaller). try something like moduleName = 'mymodule' #These two variables are read from conf file. methodName = 'mymethod' myModule = __import__(moduleName) myFunc = getattr(myModule, methodName) myFunc() 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 Mar 18 10:04:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 01:04:50 +1100 Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: <1282143233.6013541.1363615124749.JavaMail.root@sequans.com> References: <1282143233.6013541.1363615124749.JavaMail.root@sequans.com> Message-ID: On Tue, Mar 19, 2013 at 12:58 AM, Jean-Michel Pichavant wrote: > myFunc = getattr(myModule, methodName) Doh! Thanks. I knew there was a shorter way of spelling it, rather than digging with dunder methods. That's the way I would recommend - slight tweak from the __getattribute__ version. ChrisA From steve+comp.lang.python at pearwood.info Mon Mar 18 10:15:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 14:15:14 GMT Subject: "eval vs operator.methodcaller" - which is better? References: Message-ID: <51472171$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 19:00:15 +0530, Laxmikant Chitare wrote: > Hi, > > I have a program that picks module and method name from a configuration > file and executes the method. I have found two ways to achieve this. > > Apporach 1: > --------------------------- > moduleName = 'mymodule' #These two variables are read from conf file. > methodName = 'mymethod' > > import operator > myModule = __import__('mymodule') > myMethod = operator.methodcaller('mymethod') > val = myMethod(myModule) > print val Since your example code only uses string literals, the best way to write this would be: import mymodule mymodule.mymethod() But I expect that your example was faulty, and you intended to use variables: myModule = __import__(moduleName) myMethod = operator.methodcaller(methodName) val = myMethod(myModule) This would be simpler, and probably faster too: myModule = __import__(moduleName) val = getattr(myModule, methodName)() It's certainly easier to read. > --------------------------- > > Apporach 2: > --------------------------- > moduleName = 'mymodule' #These two variables are read from conf file. > methodName = 'mymethod' > > val = eval('myModule.' + methodName + '()') > print val This example also fails, since you don't have anything called "myModule". I suspect you left out a line, myModule = __import__(moduleName). > --------------------------- > > Question: Which approach is better and why. Is there any other better > way to do this? You should avoid eval, it is a massive security risk unless you are an expert, and even then it is still a big security risk. It's also slower than the alternatives. -- Steven From laxmikant.general at gmail.com Mon Mar 18 10:36:26 2013 From: laxmikant.general at gmail.com (Laxmikant Chitare) Date: Mon, 18 Mar 2013 20:06:26 +0530 Subject: "eval vs operator.methodcaller" - which is better? In-Reply-To: <51472171$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <51472171$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thank you Chris, Michel and Steven for your feedback. Steven, yes I realised that the examples are faulty. I intended to use variables instead of string literals. I will be careful next time. On 3/18/13, Steven D'Aprano wrote: > On Mon, 18 Mar 2013 19:00:15 +0530, Laxmikant Chitare wrote: > >> Hi, >> >> I have a program that picks module and method name from a configuration >> file and executes the method. I have found two ways to achieve this. >> >> Apporach 1: >> --------------------------- >> moduleName = 'mymodule' #These two variables are read from conf file. >> methodName = 'mymethod' >> >> import operator >> myModule = __import__('mymodule') >> myMethod = operator.methodcaller('mymethod') >> val = myMethod(myModule) >> print val > > Since your example code only uses string literals, the best way to write > this would be: > > import mymodule > mymodule.mymethod() > > But I expect that your example was faulty, and you intended to use > variables: > > myModule = __import__(moduleName) > myMethod = operator.methodcaller(methodName) > val = myMethod(myModule) > > > This would be simpler, and probably faster too: > > myModule = __import__(moduleName) > val = getattr(myModule, methodName)() > > > It's certainly easier to read. > > >> --------------------------- >> >> Apporach 2: >> --------------------------- >> moduleName = 'mymodule' #These two variables are read from conf file. >> methodName = 'mymethod' >> >> val = eval('myModule.' + methodName + '()') >> print val > > This example also fails, since you don't have anything called "myModule". > > I suspect you left out a line, myModule = __import__(moduleName). > > >> --------------------------- >> >> Question: Which approach is better and why. Is there any other better >> way to do this? > > > You should avoid eval, it is a massive security risk unless you are an > expert, and even then it is still a big security risk. It's also slower > than the alternatives. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > From sntshkmr60 at gmail.com Mon Mar 18 09:56:16 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Mon, 18 Mar 2013 19:26:16 +0530 Subject: What are some other way to rewrite this if block? Message-ID: This simple script is about a public transport, here is the code: def report_status(should_be_on, came_on): if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or came_on > 24.0: return 'time not in range' elif should_be_on == came_on: return 'on time' elif should_be_on > came_on: return 'early' elif should_be_on < came_on: return 'delayed' else: return 'something might be wrong' print(report_status(123, 12.0)) I am looking forward of make the line starting with `if` short. Any tips are welcome. From jpiitula at ling.helsinki.fi Mon Mar 18 10:10:07 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Mar 2013 16:10:07 +0200 Subject: What are some other way to rewrite this if block? References: Message-ID: Santosh Kumar writes: > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > came_on > 24.0: > return 'time not in range' > elif should_be_on == came_on: > return 'on time' > elif should_be_on > came_on: > return 'early' > elif should_be_on < came_on: > return 'delayed' > else: > return 'something might be wrong' > > print(report_status(123, 12.0)) > > I am looking forward of make the line starting with `if` short. > > Any tips are welcome. A double tip: if (not (0.0 <= should_be_on <= 24.0) or not (0.0 <= came_on <= 24.0)): ... You might want to raise an exception from the range-check branch instead of returning a value. And raise an exception from the else-branch, because that branch should never be reached. From duncan.booth at invalid.invalid Mon Mar 18 10:43:50 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Mar 2013 14:43:50 GMT Subject: What are some other way to rewrite this if block? References: Message-ID: Jussi Piitulainen wrote: >> Any tips are welcome. > > A double tip: > > if (not (0.0 <= should_be_on <= 24.0) or > not (0.0 <= came_on <= 24.0)): > ... > Or even: if not (0.0 <= should_be_on <= 24.0 and 0.0 <= came_on <= 24.0): ... > You might want to raise an exception from the range-check branch > instead of returning a value. And raise an exception from the > else-branch, because that branch should never be reached. Or even lose the else branch entirely. If the code can never be reached then don't write it. Also you don't need 'elif' when the individual branches all return. Putting that together and allowing some flexibility in the definition of 'on time': EARLY_DELTA = 1.0/60 LATE_DELTA = 5.0/60 def report_status(should_be_on, came_on): if not (0.0 <= should_be_on <= 24.0 and 0.0 <= came_on <= 24.0): raise ValueError('time not in range') if should_be_on - EARLY_DELTA <= came_on <= should_be_on + LATE_DELTA: return 'on time' if came_on > should_be_on: return 'delayed' return 'early' Note that none of this will hande situations around midnight such as: should_be_on==23.5, came_on=0.5 -- Duncan Booth http://kupuguy.blogspot.com From jpiitula at ling.helsinki.fi Mon Mar 18 10:53:51 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Mar 2013 16:53:51 +0200 Subject: What are some other way to rewrite this if block? References: Message-ID: Duncan Booth writes: > Jussi Piitulainen wrote: > > >> Any tips are welcome. > > > > A double tip: > > > > if (not (0.0 <= should_be_on <= 24.0) or > > not (0.0 <= came_on <= 24.0)): > > ... > > > Or even: > > if not (0.0 <= should_be_on <= 24.0 and 0.0 <= came_on <= 24.0): > ... I'd still prefer to split the line, especially considering the fact that the request was to make the line shorter: if not (0.0 <= should_be_on <= 24.0 and 0.0 <= came_on <= 24.0): ... From yoursurrogategod at gmail.com Mon Mar 18 10:18:57 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Mon, 18 Mar 2013 07:18:57 -0700 (PDT) Subject: What are some other way to rewrite this if block? In-Reply-To: References: Message-ID: <3dcc50c9-5909-4b10-9eb4-fd0cc5d98f35@googlegroups.com> On Monday, March 18, 2013 9:56:16 AM UTC-4, Santosh Kumar wrote: > This simple script is about a public transport, here is the code: > > > > def report_status(should_be_on, came_on): > > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > > came_on > 24.0: > > return 'time not in range' > > elif should_be_on == came_on: > > return 'on time' > > elif should_be_on > came_on: > > return 'early' > > elif should_be_on < came_on: > > return 'delayed' > > else: > > return 'something might be wrong' > > > > print(report_status(123, 12.0)) > > > > I am looking forward of make the line starting with `if` short. > > > > Any tips are welcome. If you have a lot of conditions to check, you can't really get around it. From steve+comp.lang.python at pearwood.info Mon Mar 18 11:10:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 15:10:15 GMT Subject: What are some other way to rewrite this if block? References: Message-ID: <51472e56$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 19:26:16 +0530, Santosh Kumar wrote: > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > came_on > 24.0: > return 'time not in range' > elif should_be_on == came_on: > return 'on time' > elif should_be_on > came_on: > return 'early' > elif should_be_on < came_on: > return 'delayed' > else: > return 'something might be wrong' Untested, but something like this should work. It adjusts for the times which fall either side of midnight, it optionally allows for some "slop" in deciding whether an arrival was on time or not (defaults to 0). def report(scheduled, actual, slop=0.0): """Report whether actual time of arrival is on time, late, early or cancelled. Pass actual=None for cancelled services, otherwise both scheduled and actual must be given as float hours between 0 and 24. E.g. to indicate a time of 06:30, pass 6.5. Optional argument slop is a non-negative time in hours which services are allowed to be late or early and still count as "on time". E.g. if a service is allowed to arrive with two minutes either side of the scheduled time and still count as on time, pass slop=2.0/60. The slop defaults to 0.0. """ if not 0 <= scheduled < 24: raise ValueError('scheduled time out of range') if not 0 <= slop < 24: raise ValueError('slop out of range') if actual is None: return "service cancelled" if not 0 <= actual < 24: raise ValueError('actual arrival time out of range') diff = actual - scheduled # Adjust for discontinuity around midnight. We assume that arrivals # are never more than 12 hours away from their scheduled times. if diff < -12: # For example, scheduled=23:55, actual=00:05 gives diff of -23:50 diff += 24 elif diff > 12: diff -= 24 if diff < -slop: return "early" elif diff > slop: return "late" else: return "on time" One disadvantage with the function as written is that you have to give times as floats between 0 and 24, instead of a more natural HH:MM syntax. For example, 11:07am would have to be given as 11.116666666666667. Another weakness is that any slop allowance is symmetrical (e.g. you can't allow trains to arrive up to one minute early or five minutes late to be counted as "on time", the two figures have to be equal). A third weakness is that you can't allow for arrivals more than 12 hours early or late. > I am looking forward of make the line starting with `if` short. :-) -- Steven From rosuav at gmail.com Mon Mar 18 11:24:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 02:24:52 +1100 Subject: What are some other way to rewrite this if block? In-Reply-To: <51472e56$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <51472e56$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 19, 2013 at 2:10 AM, Steven D'Aprano wrote: > A third weakness is that you can't allow for arrivals more than 12 hours > early or late. Oh, but that'll NEVER happen. Oh wait, I've been on a service that was 12 hours late. Is there any chance that you could do your times of arrival and expectation in, say, integer seconds since 1970? ChrisA From rosuav at gmail.com Mon Mar 18 10:16:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 01:16:19 +1100 Subject: What are some other way to rewrite this if block? In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 12:56 AM, Santosh Kumar wrote: > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > came_on > 24.0: > return 'time not in range' > elif should_be_on == came_on: > return 'on time' > elif should_be_on > came_on: > return 'early' > elif should_be_on < came_on: > return 'delayed' > else: > return 'something might be wrong' > > print(report_status(123, 12.0)) Well, for a start, I wouldn't compare for equality there. What's your definition of "on time"? In Melbourne, for instance, a service is deemed "on time" if it's less than 1 minute early and less than 5 minutes late. This is probably too broad, but I would guess that up to 1 minute (or at least half a minute) either side should be considered on time. Are you catering here for custom objects or NaNs that might not be equal, less, or greater? If not, drop the else and just have three branches - for instance: if should_be_on >= came_on + 0.5: # Up to half a minute early is okay return 'early' elif should_be_on <= came_on - 1.0: # Up to one minute late is okay return 'delayed' else: return 'on time' As a matter of readability, incidentally, I'd be inclined to invert the conditions and check the time of arrival against the expected time: if came_on < should_be_on - 0.5: # Up to half a minute early is okay return 'early' elif came_on > should_be_on + 1.0: # Up to one minute late is okay return 'delayed' else: return 'on time' I don't understand your bounds check, though. Are you working with floating point hours in the day? (If so, it's still not necessarily right - it's not uncommon to refer to the hours post-midnight as 24:00, 25:00, etc. But for a toy and a PoC, that would work.) But you then pass the integer 123 as the first arg, which will fail that check. What _is_ your data type? ChrisA From laxmikant.general at gmail.com Mon Mar 18 10:19:41 2013 From: laxmikant.general at gmail.com (Laxmikant Chitare) Date: Mon, 18 Mar 2013 19:49:41 +0530 Subject: What are some other way to rewrite this if block? In-Reply-To: References: Message-ID: What about this one: if 0.0 < should_be_on > 24.0 or 0.0 < came_on > 24.0: Regards, Laxmikant On 3/18/13, Santosh Kumar wrote: > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > came_on > 24.0: > return 'time not in range' > elif should_be_on == came_on: > return 'on time' > elif should_be_on > came_on: > return 'early' > elif should_be_on < came_on: > return 'delayed' > else: > return 'something might be wrong' > > print(report_status(123, 12.0)) > > I am looking forward of make the line starting with `if` short. > > Any tips are welcome. > -- > http://mail.python.org/mailman/listinfo/python-list > From jeanmichel at sequans.com Mon Mar 18 10:32:03 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 18 Mar 2013 15:32:03 +0100 (CET) Subject: What are some other way to rewrite this if block? In-Reply-To: Message-ID: <1709020598.6039855.1363617123909.JavaMail.root@sequans.com> ----- Original Message ----- > This simple script is about a public transport, here is the code: > > def report_status(should_be_on, came_on): > if should_be_on < 0.0 or should_be_on > 24.0 or came_on < 0.0 or > came_on > 24.0: > return 'time not in range' > elif should_be_on == came_on: > return 'on time' > elif should_be_on > came_on: > return 'early' > elif should_be_on < came_on: > return 'delayed' > else: > return 'something might be wrong' > > print(report_status(123, 12.0)) > > I am looking forward of make the line starting with `if` short. > > Any tips are welcome. > -- > http://mail.python.org/mailman/listinfo/python-list You can remove the 'if' line, report_status asks for hours, the caller is supposed to provide valid hours. What if the caller gives you strings, integer, floats ? This is a never ending story. def report_status(should_be_on, came_on): # well if you really really want to test it assert(all([int(arg) in range(0,24) for arg in (should_be_on, came_on)])) return { 0 : 'on time', -1 : 'delayed', 1 : 'early'}[cmp(should_be_on, came_on)] JM Note : in my example, 24.0 is excluded from the valid durations but I think this is the correct behavior. -- 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 steve+comp.lang.python at pearwood.info Mon Mar 18 11:07:01 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 15:07:01 GMT Subject: What are some other way to rewrite this if block? References: Message-ID: <51472d95$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 15:32:03 +0100, Jean-Michel Pichavant wrote: > You can remove the 'if' line, report_status asks for hours, the caller > is supposed to provide valid hours. What if the caller gives you > strings, integer, floats ? This is a never ending story. I see you haven't been a programmer very long *wink* Yes, error checking and data validation is a never ending story. Welcome to programming. That's what we do. > def report_status(should_be_on, came_on): > > # well if you really really want to test it > assert(all([int(arg) in range(0,24) for arg in > (should_be_on, came_on)])) Please don't use assert for argument checking in public APIs. (And probably not in private APIs either.) assert is wrong for two reasons: 1) Invalid arguments should raise TypeError or ValueError. You wouldn't arbitrarily raise KeyError("expected 0 < arg < 24 but got arg = -1") or IOError("expected an int but got a string"). That would be unprofessional and foolish. So why raise AssertionError? 2) assert is not guaranteed to run, and you have *no control over it*. If the user calls python with the -O flag, asserts are disabled and your error checking is never performed. assert is designed to verify internal logic of your code, not caller- facing argument validation. -- Steven From anadionisio257 at gmail.com Mon Mar 18 11:28:46 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 18 Mar 2013 08:28:46 -0700 (PDT) Subject: Excel column 256 limit Message-ID: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Is there some way to go around this limit? I need to import data from python to excel and I need 1440 columns for that. From davea at davea.name Mon Mar 18 11:48:02 2013 From: davea at davea.name (Dave Angel) Date: Mon, 18 Mar 2013 11:48:02 -0400 Subject: Excel column 256 limit In-Reply-To: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Message-ID: <51473732.9050000@davea.name> On 03/18/2013 11:28 AM, Ana Dion?sio wrote: > Is there some way to go around this limit? I need to import data from python to excel and I need 1440 columns for that. > Doesn't sound like a Python question. But one answer is Libre Office Calc, which seems to have a 1024 column limit. -- DaveA From steve+comp.lang.python at pearwood.info Mon Mar 18 11:50:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2013 15:50:21 GMT Subject: Excel column 256 limit References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Message-ID: <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 08:28:46 -0700, Ana Dion?sio wrote: > Is there some way to go around this limit? I need to import data from > python to excel and I need 1440 columns for that. That's an Excel question, it has nothing to do with Python. Have you considered using something other than Excel? As I understand it, OpenOffice, LibreOffice, and Gnumeric do not have a 256 column limit. Gnumeric is Linux-only, but the other two are available for Windows and Mac, and they are all free, open source software, and they all will read and write Excel spreadsheets. http://openoffice.org/ http://www.libreoffice.org/ http://projects.gnome.org/gnumeric/index.shtml -- Steven From gmx at ross.cx Mon Mar 18 13:38:28 2013 From: gmx at ross.cx (Michael Ross) Date: Mon, 18 Mar 2013 18:38:28 +0100 Subject: Excel column 256 limit In-Reply-To: <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 18 Mar 2013 16:50:21 +0100, Steven D'Aprano wrote: > On Mon, 18 Mar 2013 08:28:46 -0700, Ana Dion?sio wrote: > >> Is there some way to go around this limit? I need to import data from >> python to excel and I need 1440 columns for that. > > That's an Excel question, it has nothing to do with Python. > > Have you considered using something other than Excel? As I understand it, > OpenOffice, LibreOffice, and Gnumeric do not have a 256 column limit. Just for completeness: Excel in it's "Office 2010" version does not have a 256 column limit either. I can use > 2000 columns without problem. From anadionisio257 at gmail.com Mon Mar 18 15:00:49 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 18 Mar 2013 12:00:49 -0700 (PDT) Subject: Excel column 256 limit In-Reply-To: References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> But I still get the error and I use Excel 2010. I'm trying to export data in a list to Excel From anadionisio257 at gmail.com Mon Mar 18 15:00:49 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 18 Mar 2013 12:00:49 -0700 (PDT) Subject: Excel column 256 limit In-Reply-To: References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> But I still get the error and I use Excel 2010. I'm trying to export data in a list to Excel From auriocus at gmx.de Mon Mar 18 15:04:12 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 18 Mar 2013 20:04:12 +0100 Subject: Excel column 256 limit In-Reply-To: <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> Message-ID: Am 18.03.13 20:00, schrieb Ana Dion?sio: > But I still get the error and I use Excel 2010. > > I'm trying to export data in a list to Excel > Unless you tell *how exactly* do you export the data into excel format, we probably can't help you. You could try to write a .csv ASCII file, for instance. Christian From neilc at norwich.edu Tue Mar 19 10:07:54 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2013 14:07:54 GMT Subject: Excel column 256 limit References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> Message-ID: On 2013-03-18, Ana Dion?sio wrote: > But I still get the error and I use Excel 2010. > > I'm trying to export data in a list to Excel xlrd: Library for developers to extract data from Microsoft Excel (tm). It is for *reading* Excel files, not writing them. To get data into Excel use the csv module and create the file using the default 'excel-csv' format. Then load the file using Excel. Creating an Excel file directly in Python is possible, but I think it will require use of the Pywin32 extensions. -- Neil Cerutti From gmx at ross.cx Tue Mar 19 10:22:04 2013 From: gmx at ross.cx (Michael Ross) Date: Tue, 19 Mar 2013 15:22:04 +0100 Subject: Excel column 256 limit In-Reply-To: References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> Message-ID: On Tue, 19 Mar 2013 15:07:54 +0100, Neil Cerutti wrote: > On 2013-03-18, Ana Dion?sio wrote: >> But I still get the error and I use Excel 2010. >> >> I'm trying to export data in a list to Excel > > xlrd: Library for developers to extract data from Microsoft Excel > (tm). > > It is for *reading* Excel files, not writing them. To get data > into Excel use the csv module and create the file using the > default 'excel-csv' format. Then load the file using Excel. > > Creating an Excel file directly in Python is possible, but I > think it will require use of the Pywin32 extensions. > I use and recommend http://pythonhosted.org/openpyxl/ for creating Excel files from Python. No trouble so far. From python.list at tim.thechases.com Tue Mar 19 10:44:12 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 Mar 2013 09:44:12 -0500 Subject: Excel column 256 limit In-Reply-To: References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> Message-ID: <20130319094412.423fdabf@bigbox.christie.dr> On 2013-03-19 14:07, Neil Cerutti wrote: > On 2013-03-18, Ana Dion?sio wrote: > > But I still get the error and I use Excel 2010. > > > > I'm trying to export data in a list to Excel > > xlrd: Library for developers to extract data from Microsoft Excel > (tm). > > It is for *reading* Excel files, not writing them. There's xlrd[1] for reading and xlwt[2] for writing native XLS files. If the OP needs greater control over things like formatting and formula-cells, I'd suggest xlwt, as CSV restricts you to shoveling around the data, not its formatting. -tkc [1] https://pypi.python.org/pypi/xlrd [2] https://pypi.python.org/pypi/xlwt From ian.g.kelly at gmail.com Tue Mar 19 18:09:24 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Mar 2013 16:09:24 -0600 Subject: Excel column 256 limit In-Reply-To: <20130319094412.423fdabf@bigbox.christie.dr> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> <20130319094412.423fdabf@bigbox.christie.dr> Message-ID: On Tue, Mar 19, 2013 at 8:44 AM, Tim Chase wrote: > On 2013-03-19 14:07, Neil Cerutti wrote: >> On 2013-03-18, Ana Dion?sio wrote: >> > But I still get the error and I use Excel 2010. >> > >> > I'm trying to export data in a list to Excel >> >> xlrd: Library for developers to extract data from Microsoft Excel >> (tm). >> >> It is for *reading* Excel files, not writing them. > > There's xlrd[1] for reading and xlwt[2] for writing native XLS files. > If the OP needs greater control over things like formatting and > formula-cells, I'd suggest xlwt, as CSV restricts you to shoveling > around the data, not its formatting. xlwt however only writes .xls files, not the newer .xlsx files, so it is still subject to the 256-column limit no matter what version of Excel you use to open the workbook. From neilc at norwich.edu Wed Mar 20 10:17:09 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 20 Mar 2013 14:17:09 GMT Subject: Excel column 256 limit References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> <978a0895-902d-458c-8afd-d2a72f00feeb@googlegroups.com> <20130319094412.423fdabf@bigbox.christie.dr> Message-ID: On 2013-03-19, Ian Kelly wrote: > On Tue, Mar 19, 2013 at 8:44 AM, Tim Chase > wrote: >> On 2013-03-19 14:07, Neil Cerutti wrote: >>> On 2013-03-18, Ana Dion?sio wrote: >>> > But I still get the error and I use Excel 2010. >>> > >>> > I'm trying to export data in a list to Excel >>> >>> xlrd: Library for developers to extract data from Microsoft Excel >>> (tm). >>> >>> It is for *reading* Excel files, not writing them. >> >> There's xlrd[1] for reading and xlwt[2] for writing native XLS >> files. If the OP needs greater control over things like >> formatting and formula-cells, I'd suggest xlwt, as CSV >> restricts you to shoveling around the data, not its >> formatting. > > xlwt however only writes .xls files, not the newer .xlsx files, > so it is still subject to the 256-column limit no matter what > version of Excel you use to open the workbook. It's also Python 2.3-2.7 only. :( -- Neil Cerutti From sg552 at hotmail.co.uk Tue Mar 19 11:25:59 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Tue, 19 Mar 2013 15:25:59 +0000 Subject: Excel column 256 limit In-Reply-To: <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> <514737bc$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 18/03/2013 15:50, Steven D'Aprano wrote: > [...] > > Gnumeric is Linux-only No it isn't. I use it on Windows 7 with no problem. -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness From invalid at invalid.invalid Mon Mar 18 12:28:31 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 18 Mar 2013 16:28:31 +0000 (UTC) Subject: Excel column 256 limit References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Message-ID: On 2013-03-18, Dave Angel wrote: > On 03/18/2013 11:28 AM, Ana Dion?sio wrote: > >> Is there some way to go around this limit? I need to import data from >> python to excel and I need 1440 columns for that. > > Doesn't sound like a Python question. But one answer is Libre Office > Calc, which seems to have a 1024 column limit. [I don't see how something with a 1024 column limit is one answer for a requirement of 1440 columns.] IMO, if 256 columns isn't enough, then a spreadsheet probably isn't the right tool. If you need 1440 columns then I can't even imagine a case where a spreadsheet is the right tool. I've seen people spend weeks trying to do something with excel that would have taken a few hours using Numpy/Scipy/Scientific-Python. -- Grant Edwards grant.b.edwards Yow! I want to kill at everyone here with a cute gmail.com colorful Hydrogen Bomb!! From maillist at schwertberger.de Mon Mar 18 13:00:48 2013 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Mon, 18 Mar 2013 18:00:48 +0100 Subject: Excel column 256 limit In-Reply-To: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Message-ID: <51474840.6050105@schwertberger.de> Am 18.03.2013 16:28, schrieb Ana Dion?sio: > Is there some way to go around this limit? I need to import data from python to excel and I need 1440 columns for that. There are many versions of Excel. The recent ones can handle more than 256 columns. If your version doesn't, then Python won't help you to increase this limit... There are many ways to get data from Python into Excel. If you have any specific problems, you should provide more details. Regards, Dietmar From jmcnamara13 at gmail.com Sat Mar 30 12:43:19 2013 From: jmcnamara13 at gmail.com (jmcnamara13 at gmail.com) Date: Sat, 30 Mar 2013 09:43:19 -0700 (PDT) Subject: Excel column 256 limit In-Reply-To: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> References: <5ff118cb-a57b-45d6-9a5c-e0e3db4b0327@googlegroups.com> Message-ID: On Monday, 18 March 2013 15:28:46 UTC, Ana Dion?sio wrote: > Is there some way to go around this limit? I need to import data from python to excel and I need 1440 columns for that. Hi, The 256 column limit is an Excel limitation for XLS files. Try XlsxWriter, it supports Excel's XLSX limits of 1,048,576 rows x 16,384 columns: http://pypi.python.org/pypi/XlsxWriter/ https://xlsxwriter.readthedocs.org/ John From yoursurrogategod at gmail.com Mon Mar 18 13:17:30 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Mon, 18 Mar 2013 13:17:30 -0400 Subject: [Python 3.3.0] Getting tkinter to work on Python 3 Message-ID: Hi. I'm having a problem trying to get this to work well. Basically, whenever I try to import tkinter, this is the issue that I have: >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/tkinter/__init__.py", line 40, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' I'm running Ubuntu. If I need to provide any further info, please let me know. -------------- next part -------------- An HTML attachment was scrubbed... URL: From xenplex at gmail.com Mon Mar 18 14:22:41 2013 From: xenplex at gmail.com (Ritchie Flick) Date: Mon, 18 Mar 2013 19:22:41 +0100 Subject: [Python 3.3.0] Getting tkinter to work on Python 3 In-Reply-To: References: Message-ID: Seems tkinter is missing in standard installation in ubuntu. Try: sudo apt-get install python3-tk On Mon, Mar 18, 2013 at 6:17 PM, Yves S. Garret wrote: > Hi. I'm having a problem trying to get this to work well. Basically, > whenever I try to > import tkinter, this is the issue that I have: > > >>> import tkinter > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python3.3/tkinter/__init__.py", line 40, in > import _tkinter # If this fails your Python may not be configured for > Tk > ImportError: No module named '_tkinter' > > I'm running Ubuntu. If I need to provide any further info, please let me > know. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Ritchie Flick -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoursurrogategod at gmail.com Mon Mar 18 14:29:59 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Mon, 18 Mar 2013 14:29:59 -0400 Subject: [Python 3.3.0] Getting tkinter to work on Python 3 In-Reply-To: References: Message-ID: I have. This is what I did and the result that I'm seeing. $ sudo apt-get install python3-tk [sudo] password for ysg: Reading package lists... Done Building dependency tree Reading state information... Done python3-tk is already the newest version. python3-tk set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. $ python3 Python 3.3.0 (default, Mar 11 2013, 15:04:13) [GCC 4.5.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/tkinter/__init__.py", line 40, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' >>> :-/ On Mon, Mar 18, 2013 at 2:22 PM, Ritchie Flick wrote: > Seems tkinter is missing in standard installation in ubuntu. Try: > sudo apt-get install python3-tk > > > On Mon, Mar 18, 2013 at 6:17 PM, Yves S. Garret < > yoursurrogategod at gmail.com> wrote: > >> Hi. I'm having a problem trying to get this to work well. Basically, >> whenever I try to >> import tkinter, this is the issue that I have: >> >> >>> import tkinter >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib/python3.3/tkinter/__init__.py", line 40, in >> >> import _tkinter # If this fails your Python may not be configured for >> Tk >> ImportError: No module named '_tkinter' >> >> I'm running Ubuntu. If I need to provide any further info, please let me >> know. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Ritchie Flick > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lele at metapensiero.it Mon Mar 18 14:39:57 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Mon, 18 Mar 2013 19:39:57 +0100 Subject: [Python 3.3.0] Getting tkinter to work on Python 3 References: Message-ID: <87boagpn5u.fsf@nautilus.nautilus> "Yves S. Garret" writes: > I have. This is what I did and the result that I'm seeing. > > $ sudo apt-get install python3-tk You installed a "custom" python 3.3, didn't you? So it does not help installing Ubuntu's python3-tk: your python3.3 interpreter won't even look into "system" packages. Most probably, you need to install the proper development libraries and *recompile* the Python 3.3 interpreter: # apt-get install tk-dev 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 yoursurrogategod at gmail.com Mon Mar 18 21:52:20 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Mon, 18 Mar 2013 18:52:20 -0700 (PDT) Subject: [Python 3.3.0] Getting tkinter to work on Python 3 In-Reply-To: References: Message-ID: <5a9db8f4-c75e-466e-8e06-3e88d6ba93c0@googlegroups.com> On Monday, March 18, 2013 2:39:57 PM UTC-4, Lele Gaifax wrote: > "Yves S. Garret" writes: > > > I have. This is what I did and the result that I'm seeing. > > > > $ sudo apt-get install python3-tk > > You installed a "custom" python 3.3, didn't you? So it does not help > installing Ubuntu's python3-tk: your python3.3 interpreter won't even > look into "system" packages. > > Most probably, you need to install the proper development libraries and > *recompile* the Python 3.3 interpreter: > > # apt-get install tk-dev > > ciao, lele. > -- > nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri > real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. > le.. at metapensiero.it | -- Fortunato Depero, 1929. Ok, it now seems to work. Weird. I had tk-dev installed (it seems) and then after I re-compiled my interpreter just now, it's working. Thanks for your help. From yoursurrogategod at gmail.com Mon Mar 18 21:52:20 2013 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Mon, 18 Mar 2013 18:52:20 -0700 (PDT) Subject: [Python 3.3.0] Getting tkinter to work on Python 3 In-Reply-To: References: Message-ID: <5a9db8f4-c75e-466e-8e06-3e88d6ba93c0@googlegroups.com> On Monday, March 18, 2013 2:39:57 PM UTC-4, Lele Gaifax wrote: > "Yves S. Garret" writes: > > > I have. This is what I did and the result that I'm seeing. > > > > $ sudo apt-get install python3-tk > > You installed a "custom" python 3.3, didn't you? So it does not help > installing Ubuntu's python3-tk: your python3.3 interpreter won't even > look into "system" packages. > > Most probably, you need to install the proper development libraries and > *recompile* the Python 3.3 interpreter: > > # apt-get install tk-dev > > ciao, lele. > -- > nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri > real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. > le.. at metapensiero.it | -- Fortunato Depero, 1929. Ok, it now seems to work. Weird. I had tk-dev installed (it seems) and then after I re-compiled my interpreter just now, it's working. Thanks for your help. From tjreedy at udel.edu Mon Mar 18 23:39:12 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2013 23:39:12 -0400 Subject: [Python 3.3.0] Getting tkinter to work on Python 3 In-Reply-To: <5a9db8f4-c75e-466e-8e06-3e88d6ba93c0@googlegroups.com> References: <5a9db8f4-c75e-466e-8e06-3e88d6ba93c0@googlegroups.com> Message-ID: On 3/18/2013 9:52 PM, Yves S. Garret wrote: > Ok, it now seems to work. Weird. I had tk-dev installed (it seems) > and then after I re-compiled my interpreter just now, it's working. If your previous compilation was before tk-dev was installed, it will not have compiled _tkinter properly. On PC, one also has to re-compile after doing equivalent of downloading tk-dev. -- Terry Jan Reedy From victorhooi at gmail.com Mon Mar 18 16:38:59 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Mon, 18 Mar 2013 13:38:59 -0700 (PDT) Subject: Writing Python framework for declarative checks? Message-ID: <856820af-23a0-40d8-bd5d-1dd666be7df8@googlegroups.com> HI, NB: I've posted this question on Reddit as well (but didn't get many responses from Pythonistas) - hope it's ok if I post here as well. We currently use a collection of custom Python scripts to validate various things in our production environment/configuration. Many of these are simple XML checks (i.e. validate that the value of this XML tag here equals the value in that file over there). Others might be to check that a host is up, or that this application's crontab start time is within 20 minutes of X, or that a logfile on a server contains a certain line. The checks are executed automatically before every production push. The scripts are written imperatively. E.g.: SSH into a server Open up a file Parse the XML Search for a XML tag Store the value in a variable Compare it to another value somewhere else. I'd like to look at writing a framework to do these validation in a slightly more declarative way - i.e. instead of defining how the server should check something, we should just be able to say value should equal foobar - and let the framework handle the how. I was thinking we could then schedule the checks and shove the jobs onto a queue like Celery. To stop me from re-inventing the wheel - are there any existing projects that do something like this already? Or has anybody here done something similar, or would be able to offer any advice? (I aware of things like Puppet or Chef - or even Salt Stack - however, these are for managing deployments, or actually pushing out configurations. These validation scripts are more to ensure that the configuration changes done by hand are sane, or don't violate certain basic rules). Cheers, Victor From jeanmichel at sequans.com Tue Mar 19 06:28:16 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 19 Mar 2013 11:28:16 +0100 (CET) Subject: Writing Python framework for declarative checks? In-Reply-To: <856820af-23a0-40d8-bd5d-1dd666be7df8@googlegroups.com> Message-ID: <1201432836.6508194.1363688896000.JavaMail.root@sequans.com> ----- Original Message ----- > HI, > > NB: I've posted this question on Reddit as well (but didn't get many > responses from Pythonistas) - hope it's ok if I post here as well. > > We currently use a collection of custom Python scripts to validate > various things in our production environment/configuration. > > Many of these are simple XML checks (i.e. validate that the value of > this XML tag here equals the value in that file over there). Others > might be to check that a host is up, or that this application's > crontab start time is within 20 minutes of X, or that a logfile on a > server contains a certain line. > > The checks are executed automatically before every production push. > > The scripts are written imperatively. E.g.: > > SSH into a server > Open up a file > Parse the XML > Search for a XML tag > Store the value in a variable > Compare it to another value somewhere else. > I'd like to look at writing a framework to do these validation in a > slightly more declarative way - i.e. instead of defining how the > server should check something, we should just be able to say > value should equal foobar - and let the framework handle > the how. Using a continuous integration software like Jenkins, have it schedule checks upon whatever trigger you need. In jenkins you can add shell or python batchs from which you can call your python scripts. A Jenkins python batch would look like this : -- Job A -- *Python batch* import checkers for tag, value in [ ('xmlTag', 'value'), ('xmlTag2', 'value2'), ... ]: checkers.checkXmlTag(tag, value) 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 Tue Mar 19 06:38:15 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 19 Mar 2013 03:38:15 -0700 (PDT) Subject: Writing Python framework for declarative checks? References: <856820af-23a0-40d8-bd5d-1dd666be7df8@googlegroups.com> Message-ID: <6701e6d4-815e-4907-8176-909c8bf470d5@o9g2000pbt.googlegroups.com> On Mar 19, 1:38?am, Victor Hooi wrote: > We currently use a collection of custom Python scripts to validate various things in our production environment/configuration. > > Many of these are simple XML checks (i.e. validate that the value of this XML tag here equals the value in that file over there). Others might be to check that a host is up, or that this application's crontab start time is within 20 minutes of X, or that a logfile on a server contains a certain line. > > The checks are executed automatically before every production push. > > The scripts are written imperatively. E.g.: > > SSH into a server > Open up a file > Parse the XML > Search for a XML tag > Store the value in a variable > Compare it to another value somewhere else. > I'd like to look at writing a framework to do these validation in a slightly more declarative way - i.e. instead of defining how the server should check something, we should just be able to say value should equal foobar - and let the framework handle the how. > > I was thinking we could then schedule the checks and shove the jobs onto a queue like Celery. > > To stop me from re-inventing the wheel - are there any existing projects that do something like this already? > > Or has anybody here done something similar, or would be able to offer any advice? > > (I aware of things like Puppet or Chef - or even Salt Stack - however, these are for managing deployments, or actually pushing out configurations. These validation scripts are more to ensure that the configuration changes done by hand are sane, or don't violate certain basic rules). There is fabric http://docs.fabfile.org/en/1.6/ Basically does the two jobs 1. allowing python functions to be called from the command line 2. Giving ssh a more pythonic feel You could use the framework to build your own DSL. [And/or maybe ask the fabric guys what they think of your idea(s) ] [Disclaimer: Ive not used fabric myself] From pengyu.ut at gmail.com Mon Mar 18 17:17:27 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 18 Mar 2013 16:17:27 -0500 Subject: The usage of -m option of python Message-ID: Hi, I don't quite understand how -m option is used. And it is difficult to search for -m in google. Could anybody provide me with an example on how to use this option? Thanks! -m module-name Searches sys.path for the named module and runs the corresponding .py file as a script. -- Regards, Peng From rosuav at gmail.com Mon Mar 18 17:35:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2013 08:35:04 +1100 Subject: The usage of -m option of python In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 8:17 AM, Peng Yu wrote: > Hi, > > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on > how to use this option? Thanks! > > -m module-name > Searches sys.path for the named module and runs the > corresponding .py file as a script. Well, I just searched for 'python m module', but I agree it's not easy. Anyway, Google read my mind and returned this: http://www.python.org/dev/peps/pep-0338/ ChrisA From modulok at gmail.com Mon Mar 18 18:34:21 2013 From: modulok at gmail.com (Modulok) Date: Mon, 18 Mar 2013 16:34:21 -0600 Subject: The usage of -m option of python In-Reply-To: References: Message-ID: >> Hi, >> >> I don't quite understand how -m option is used. And it is difficult to >> search for -m in google. Could anybody provide me with an example on >> how to use this option? Thanks! >> >> -m module-name >> Searches sys.path for the named module and runs the >> corresponding .py file as a script. > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on > how to use this option? Thanks! Forgive me if I'm too verbose: When this module is imported via a regular python import statement, the module's special property ``__name__`` is automatically set to the name of the module, as a string. For example:: >>> import random >>> random.__name__ >>> 'random' If a file is executed as a script from the operating system's command line, the value of the ``__main__`` property is instead automatically set to the string "__main__". This is useful because many python modules have a line such as:: if __name__ == "__main__": # Do something different... # Maybe run some unit tests or something. # Or perhaps parse some command line arguments... This means you can cd into the python modules directory on your system and execute one of the built-in modules directly:: cd /usr/local/lib/python3.3 python3.3 random.py # Tests the random number functions and spits out the result to the # console. We have one file with two behaviors, depending on how it gets executed. You can use the same concept in your own scripts to have both a command line script that does something useful, as well as an importable python module to use in other scripts. Remember, if ``__name__ == "__main__"`` the file is being run as a script. Otherwise it's being imported as a module. So what about that ``-m`` option? Having to cd into the python module directory every time you need to execute a module as a script is cumbersome. The ``-m`` flag is basically a shortcut. These are basically the same:: cd /usr/local/lib/python3.3 python3.3 random.py Same as:: python3.3 -m random #<-- I can do this from any directory. The modules in the standard library have no obligation to do anything useful, or even anything at all, if execute directly but you can use the same idea to execute modules as scripts from packages you create. -Modulok- From tjreedy at udel.edu Mon Mar 18 23:03:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2013 23:03:15 -0400 Subject: The usage of -m option of python In-Reply-To: References: Message-ID: On 3/18/2013 5:17 PM, Peng Yu wrote: > Hi, > > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on > how to use this option? python -m test at a command line runs the regression tests in the test package python -m test -v test_difflib runs test.test_difflib in verbose mode. These are alternatives to python ... Python just searches for module itself, same as for import, but executes it as main module instead of importing. This is really handy for developers running tests, where path-to-test is not only a nuisance to type, but different for development builds than for installations, and of course, different for each version. Let python find the /Lib corresponding to the executable. I am not sure if it works for things outside /Lib -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 27 13:52:15 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Mar 2013 13:52:15 -0400 Subject: The usage of -m option of python In-Reply-To: References: Message-ID: On 3/18/2013 11:03 PM, Terry Reedy wrote: > On 3/18/2013 5:17 PM, Peng Yu wrote: >> Hi, >> >> I don't quite understand how -m option is used. And it is difficult to >> search for -m in google. Could anybody provide me with an example on >> how to use this option? > > python -m test > at a command line runs the regression tests in the test package > python -m test -v test_difflib > runs test.test_difflib in verbose mode. > > These are alternatives to > python ... > Python just searches for module itself, same as for import, but executes > it as main module instead of importing. > > This is really handy for developers running tests, where path-to-test is > not only a nuisance to type, but different for development builds than > for installations, and of course, different for each version. Let python > find the /Lib corresponding to the executable. > > I am not sure if it works for things outside /Lib It does. All startup options are explained in the section "1.1 Command line" of the doc "Python Setup and Usage" The entry for -m starts "Search sys.path for the named module and execute its contents as the __main__ module." and continues another 14 lines. Along with other startup options, '-m' is indexed on the Symbols page of the index. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Mar 19 03:06:01 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2013 07:06:01 GMT Subject: The usage of -m option of python References: Message-ID: <51480e59$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Mar 2013 16:17:27 -0500, Peng Yu wrote: > Hi, > > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on how > to use this option? Thanks! > > -m module-name > Searches sys.path for the named module and runs the > corresponding .py file as a script. You use it to run a python module or package as a script, without caring whether it is a .py file, a .pyc file, a package, compressed in a zip file, a module written in C inside a .dll or .so file, or caring exactly where it is. python -m module arguments is conceptually like: * launch Python * insert arguments into sys.argv * import module * run it as a script * exit So long as the module is *somewhere* on your PYTHONPATH, -m will find it and run it. Whether it does something useful or not will depend on the module. Here is one example of a module written to be callable as a script: [steve at ando ~]$ python -m timeit -s "x = [3, 5, 2, 8, 1, 9, 7]" "x.sort()" 1000000 loops, best of 3: 0.451 usec per loop Notice that I did not need to worry about where the timeit module actually lives on disk. All I needed to know is that it was somewhere in the standard library. -- Steven From werotizy at freent.dd Wed Mar 27 13:06:04 2013 From: werotizy at freent.dd (Tom P) Date: Wed, 27 Mar 2013 18:06:04 +0100 Subject: The usage of -m option of python In-Reply-To: References: Message-ID: On 03/18/2013 10:17 PM, Peng Yu wrote: > Hi, > > I don't quite understand how -m option is used. And it is difficult to > search for -m in google. Could anybody provide me with an example on > how to use this option? Thanks! > > -m module-name > Searches sys.path for the named module and runs the > corresponding .py file as a script. > The most practical use I know is to run the debug program.. python -mpdb yourprogramm.py arguments.. From nickzacharatos at gmail.com Mon Mar 18 21:57:30 2013 From: nickzacharatos at gmail.com (NZach) Date: Mon, 18 Mar 2013 18:57:30 -0700 (PDT) Subject: Problem this random seed() Message-ID: Hello everyone, i am using the MMK.py example from a SimPy tutorial, which can be found here: http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf I have made very little changes to the code and i have upload it here: http://codeviewer.org/view/code:30d3 The problem is that i am executing the main() function in lines 83 and 90, but i do not receive the same result, although the random seed is used in the G class. Any idea please, how can i solve it ? Thanks, Nicholas. From techgeek201 at gmail.com Mon Mar 18 22:36:49 2013 From: techgeek201 at gmail.com (eli m) Date: Mon, 18 Mar 2013 19:36:49 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <4b13ad53-a269-437d-a4df-6ba52c56c167@googlegroups.com> On Monday, March 18, 2013 6:57:30 PM UTC-7, NZach wrote: > Hello everyone, > > > > i am using the MMK.py example from a SimPy tutorial, which can be found here: http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf > > > > I have made very little changes to the code and i have upload it here: > > http://codeviewer.org/view/code:30d3 > > > > The problem is that i am executing the main() function in lines 83 and 90, but > > i do not receive the same result, although the random seed is used in the G > > class. > > > > Any idea please, how can i solve it ? > > > > > > Thanks, > > > > Nicholas. What errors did it show? From wuwei23 at gmail.com Mon Mar 18 22:51:19 2013 From: wuwei23 at gmail.com (alex23) Date: Mon, 18 Mar 2013 19:51:19 -0700 (PDT) Subject: Problem this random seed() References: Message-ID: On Mar 19, 11:57?am, NZach wrote: > The problem is that i am executing ?the main() function in lines 83 and 90, but > i do not receive the ?same result, although the random seed is used in the G > class. > > Any idea please, how can i solve it ? The seed is used to create a Random instance at the very start of the module. This means it will have the same state for each run of the module, but not for each execution of the main function. To have each execution of main() return the same result, you will need to set the seed _within_ the main function. Try adding this as the first line in main: G.Rnd = Random(12345) This should ensure that the state of your random generator is the same for each execution of the main() function and any subsequent functions it calls that rely on G.Rnd. From nickzacharatos at gmail.com Tue Mar 19 06:52:11 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 03:52:11 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <0d49facc-b14d-4818-9cf3-d750181d79f8@googlegroups.com> @eli m : The problem is that i execute on lines 83 and 90 the main() and although the seed value is the same, equal to 12345, i receive different results from lines 85 and 92. @alex23: I changed the code, http://codeviewer.org/view/code:30d4, but i still receive have the same problem. The results are different. Any help please From nickzacharatos at gmail.com Tue Mar 19 06:54:44 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 03:54:44 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: @eli m : The problem is that i execute on lines 83 and 90 the main() and although the seed value is the same, equal to 12345, i receive different results from lines 85 and 92. @alex23: I changed the code, http://codeviewer.org/view/code:30d4, but i still receive have the same problem. The results are different. Any idea please From svenito at gmail.com Tue Mar 19 07:59:20 2013 From: svenito at gmail.com (Sven) Date: Tue, 19 Mar 2013 11:59:20 +0000 Subject: Problem this random seed() In-Reply-To: References: Message-ID: On 19 March 2013 10:54, NZach wrote: > @eli m : The problem is that i execute on lines 83 and 90 the main() and > although the seed value is the same, equal to 12345, i receive different > results from lines 85 and 92. > > @alex23: I changed the code, http://codeviewer.org/view/code:30d4, but i > still receive have the same problem. The results are different. > > Any idea please > have you actually tried printing out the return value of G.Rnd.expovariate(MachineClass.SrvRate) ? I'm not sure as I have not used SimPy before, but the values you are printing out at the bottom seem to be related to the timing, specifically now(), which would give you a different result each time. If you print out or inspect the result of expovariate, it should be the same each time you run main. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From nickzacharatos at gmail.com Tue Mar 19 08:27:55 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 05:27:55 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <618539ea-7a9e-4cd1-8413-22a8491077e8@googlegroups.com> Thank you @sven ! I thought that the time was reset automatically after calling the second main. Yes, i checked the values and they are the same. From nickzacharatos at gmail.com Tue Mar 19 08:27:55 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 05:27:55 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <618539ea-7a9e-4cd1-8413-22a8491077e8@googlegroups.com> Thank you @sven ! I thought that the time was reset automatically after calling the second main. Yes, i checked the values and they are the same. From nickzacharatos at gmail.com Tue Mar 19 09:50:34 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 06:50:34 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: Sorry, my previous reply was completely wrong. The time is initialized through the initialize() to 0. So, each time i call main() the simulation time is initialized to 0. I changed the code in order to print and check the values of G.Rnd.expovariate(MachineClass.SrvRate) and G.Rnd.expovariate(ArrivalClass.ArvRate) here is the code and the changes i made : http://codeviewer.org/view/code:30d8 The values are not the same. The result i take is the following: Result from main() call No. 1 is 0.0452927906737 Result from main() call No. 2 is 0.0588336669949 2 First time Execution of Main Main [0.07267291894782457, 0.019146562687989536, 0.034780398625615376, 0.005528912370370478, 0.023636815811338075] [0.13472907136407936, 0.0025553071735785462, 0.08868344131130483, 0.05381286556098766, 0.044091180681591464] Second time Execution of Main [0.0335704752213292, 0.1321512230812724, 0.16025979406301488, 0.029210377271523574, 0.006680846943670858] [0.20642889529587374, 0.047894131266223446, 0.10958802111803392, 0.02393344456847461, 0.13280785022932287] From nickzacharatos at gmail.com Tue Mar 19 09:50:34 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 06:50:34 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: Sorry, my previous reply was completely wrong. The time is initialized through the initialize() to 0. So, each time i call main() the simulation time is initialized to 0. I changed the code in order to print and check the values of G.Rnd.expovariate(MachineClass.SrvRate) and G.Rnd.expovariate(ArrivalClass.ArvRate) here is the code and the changes i made : http://codeviewer.org/view/code:30d8 The values are not the same. The result i take is the following: Result from main() call No. 1 is 0.0452927906737 Result from main() call No. 2 is 0.0588336669949 2 First time Execution of Main Main [0.07267291894782457, 0.019146562687989536, 0.034780398625615376, 0.005528912370370478, 0.023636815811338075] [0.13472907136407936, 0.0025553071735785462, 0.08868344131130483, 0.05381286556098766, 0.044091180681591464] Second time Execution of Main [0.0335704752213292, 0.1321512230812724, 0.16025979406301488, 0.029210377271523574, 0.006680846943670858] [0.20642889529587374, 0.047894131266223446, 0.10958802111803392, 0.02393344456847461, 0.13280785022932287] From svenito at gmail.com Tue Mar 19 10:19:10 2013 From: svenito at gmail.com (Sven) Date: Tue, 19 Mar 2013 14:19:10 +0000 Subject: Problem this random seed() In-Reply-To: References: Message-ID: On 19 March 2013 13:50, NZach wrote: > Sorry, my previous reply was completely wrong. The time is initialized > through the initialize() to 0. So, each time i call main() the simulation > time is initialized to 0. > > I changed the code in order to print and check the values of > > G.Rnd.expovariate(MachineClass.SrvRate) and > G.Rnd.expovariate(ArrivalClass.ArvRate) > > here is the code and the changes i made : > http://codeviewer.org/view/code:30d8 > > The values are not the same. > > The result i take is the following: > > Result from main() call No. 1 is 0.0452927906737 > Result from main() call No. 2 is 0.0588336669949 > 2 > First time Execution of Main Main > [0.07267291894782457, 0.019146562687989536, 0.034780398625615376, > 0.005528912370370478, 0.023636815811338075] > [0.13472907136407936, 0.0025553071735785462, 0.08868344131130483, > 0.05381286556098766, 0.044091180681591464] > Second time Execution of Main > [0.0335704752213292, 0.1321512230812724, 0.16025979406301488, > 0.029210377271523574, 0.006680846943670858] > [0.20642889529587374, 0.047894131266223446, 0.10958802111803392, > 0.02393344456847461, 0.13280785022932287] > In the new code you are creating one instance of G which you seed with 1234 and then calling expovariate on it each time you call main without reseeding. You're only seeding it once and reusing it, so you would get different values. What you had before, where you seeded G.Rnd in the main was fine. I also suggest you change one thing at a time, rather than reworking large parts each iteration. All I was suggesting was a simple print statement in the Run method like you had it before -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Mar 19 10:18:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2013 14:18:36 GMT Subject: Problem this random seed() References: Message-ID: <514873bc$0$6599$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Mar 2013 06:50:34 -0700, NZach wrote: > Sorry, my previous reply was completely wrong. The time is initialized > through the initialize() to 0. So, each time i call main() the > simulation time is initialized to 0. > > I changed the code in order to print and check the values of > > G.Rnd.expovariate(MachineClass.SrvRate) and > G.Rnd.expovariate(ArrivalClass.ArvRate) > > here is the code and the changes i made : > http://codeviewer.org/view/code:30d8 > > The values are not the same. Why you think that they should be? They are using random values, of course they will be different, until you reset the seed. py> from random import expovariate, seed py> seed(123) py> [expovariate(1) for i in range(3)] [2.949543607473089, 2.4397037404431217, 0.8983482559638] py> [expovariate(1) for i in range(3)] [2.2284035134067692, 0.10402931548508174, 3.2661334288222377] py> seed(123) # reset the seed py> [expovariate(1) for i in range(3)] [2.949543607473089, 2.4397037404431217, 0.8983482559638] In your case, you initialise the seed once, using: class G: Rnd = Random(12345) so when you want to run the same results again, you have to call: G.Rnd.seed(12345) By the way, what is the purpose of class G? Also, you import expovariate from the Random module, but never use it. -- Steven From nickzacharatos at gmail.com Tue Mar 19 10:44:47 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 07:44:47 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> OK, i changed the code again. Delete the G class (The purpose of G class was to refer to global variables). Add Rnd.seed(12345) in main() function. The new code : http://codeviewer.org/view/code:30da i print the Rnd.expovariate(ArrivalClass.ArvRate). The output i get be executing the above code is the following : --- 0.134729071364 0.00255530717358 0.0886834413113 Result = 0.0571622124959 0.134729071364 0.00255530717358 0.0886834413113 Result = 0.0453791550084 --- So, the problem is probably with time (which is what @Stev mentioned before). But i still cant understand the reason. From the SimPy documentation : http://simpy.sourceforge.net/SimPyDocs/Manuals/SManual.html it says for the initialize(): "The initialize statement initialises global simulation variables and sets the software clock to 0.0. It must appear in your program before any SimPy process objects are activated." Any idea why that happens ? From svenito at gmail.com Tue Mar 19 11:05:44 2013 From: svenito at gmail.com (Sven) Date: Tue, 19 Mar 2013 15:05:44 +0000 Subject: Problem this random seed() In-Reply-To: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> References: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> Message-ID: On 19 March 2013 14:44, NZach wrote: > OK, i changed the code again. Delete the G class (The purpose of G class > was to refer to global variables). Add Rnd.seed(12345) in main() function. > The new code : http://codeviewer.org/view/code:30da > > i print the Rnd.expovariate(ArrivalClass.ArvRate). > > The output i get be executing the above code is the following : > --- > 0.134729071364 > 0.00255530717358 > 0.0886834413113 > > Result = 0.0571622124959 > 0.134729071364 > 0.00255530717358 > 0.0886834413113 > > Result = 0.0453791550084 > --- > > > So, the problem is probably with time (which is what @Stev mentioned > before). > > But i still cant understand the reason. From the SimPy documentation : > http://simpy.sourceforge.net/SimPyDocs/Manuals/SManual.html > it says for the initialize(): "The initialize statement initialises global > simulation variables and sets the software clock to 0.0. It must appear in > your program before any SimPy process objects are activated." > > Any idea why that happens > I am guessing it's because now gives you the current clock value. Yes, initialise sets it to 0.0, but on execution now will change to the time since initialise(), so you will get varying values. That's my best guess -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Mar 19 11:09:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2013 15:09:08 GMT Subject: Problem this random seed() References: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> Message-ID: <51487f93$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Mar 2013 07:44:47 -0700, NZach wrote: > OK, i changed the code again. Delete the G class (The purpose of G class > was to refer to global variables). Add Rnd.seed(12345) in main() > function. The new code : http://codeviewer.org/view/code:30da > > i print the Rnd.expovariate(ArrivalClass.ArvRate). > > The output i get be executing the above code is the following : --- > 0.134729071364 > 0.00255530717358 > 0.0886834413113 > > Result = 0.0571622124959 > 0.134729071364 > 0.00255530717358 > 0.0886834413113 > > Result = 0.0453791550084 > --- > > > So, the problem is probably with time (which is what @Stev mentioned > before). Who is "Stev"? If you mean me, Steve or Steven, I did not say anything about time. I mentioned the random number generator *seed*. The random number generator cannot read your mind and automatically reset back to the start just because you want it to reset. You have to actually set the seed to the same value it was. py> from random import Random py> Rnd = Random(12345) py> Rnd.expovariate(2) 0.43779052477592995 py> Rnd.expovariate(2) 2.2941973691140807 py> Rnd.seed(12345) py> Rnd.expovariate(2) 0.43779052477592995 py> Rnd.expovariate(2) 2.2941973691140807 > But i still cant understand the reason. From the SimPy documentation : > http://simpy.sourceforge.net/SimPyDocs/Manuals/SManual.html it says for > the initialize(): "The initialize statement initialises global > simulation variables and sets the software clock to 0.0. It must appear > in your program before any SimPy process objects are activated." That has nothing to do with the random numbers generated by expovariate(). -- Steven From svenito at gmail.com Tue Mar 19 11:19:36 2013 From: svenito at gmail.com (Sven) Date: Tue, 19 Mar 2013 15:19:36 +0000 Subject: Problem this random seed() In-Reply-To: <51487f93$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> <51487f93$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19 March 2013 15:09, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 19 Mar 2013 07:44:47 -0700, NZach wrote: > > > OK, i changed the code again. Delete the G class (The purpose of G class > > was to refer to global variables). Add Rnd.seed(12345) in main() > > function. The new code : http://codeviewer.org/view/code:30da > > > > i print the Rnd.expovariate(ArrivalClass.ArvRate). > > > > The output i get be executing the above code is the following : --- > > 0.134729071364 > > 0.00255530717358 > > 0.0886834413113 > > > > Result = 0.0571622124959 > > 0.134729071364 > > 0.00255530717358 > > 0.0886834413113 > > > > Result = 0.0453791550084 > > --- > > > > > > So, the problem is probably with time (which is what @Stev mentioned > > before). > > Who is "Stev"? If you mean me, Steve or Steven, I did not say anything > about time. I mentioned the random number generator *seed*. > > I think he meant me. > > But i still cant understand the reason. From the SimPy documentation : > > http://simpy.sourceforge.net/SimPyDocs/Manuals/SManual.html it says for > > the initialize(): "The initialize statement initialises global > > simulation variables and sets the software clock to 0.0. It must appear > > in your program before any SimPy process objects are activated." > > That has nothing to do with the random numbers generated by expovariate(). > > No, but in early versions he was printing out the time (or a time related term) and was wondering why that is different too. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From nickzacharatos at gmail.com Tue Mar 19 10:44:47 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 07:44:47 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <00329c02-21b7-438e-8551-0f4677d01474@googlegroups.com> OK, i changed the code again. Delete the G class (The purpose of G class was to refer to global variables). Add Rnd.seed(12345) in main() function. The new code : http://codeviewer.org/view/code:30da i print the Rnd.expovariate(ArrivalClass.ArvRate). The output i get be executing the above code is the following : --- 0.134729071364 0.00255530717358 0.0886834413113 Result = 0.0571622124959 0.134729071364 0.00255530717358 0.0886834413113 Result = 0.0453791550084 --- So, the problem is probably with time (which is what @Stev mentioned before). But i still cant understand the reason. From the SimPy documentation : http://simpy.sourceforge.net/SimPyDocs/Manuals/SManual.html it says for the initialize(): "The initialize statement initialises global simulation variables and sets the software clock to 0.0. It must appear in your program before any SimPy process objects are activated." Any idea why that happens ? From nickzacharatos at gmail.com Tue Mar 19 10:18:37 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 07:18:37 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <2d0604f8-7700-4dee-8a62-69c94d908ee6@googlegroups.com> Probably a better code : http://codeviewer.org/view/code:30d9 I run the program once using comment in line 39 and then using comment in line 62. The results are not the same. The problem is with the Random. Although, i use seed value equal to 12345, i do not take the same results. :[ Any idea please From nickzacharatos at gmail.com Tue Mar 19 11:23:47 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 08:23:47 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: References: Message-ID: <729b7df7-d1b5-4397-b659-fdab25f10dd2@googlegroups.com> ?? ?????, 19 ??????? 2013 3:57:30 ?.?. UTC+2, ? ??????? NZach ??????: > Hello everyone, > > > > i am using the MMK.py example from a SimPy tutorial, which can be found here: http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf > > > > I have made very little changes to the code and i have upload it here: > > http://codeviewer.org/view/code:30d3 > > > > The problem is that i am executing the main() function in lines 83 and 90, but > > i do not receive the same result, although the random seed is used in the G > > class. > > > > Any idea please, how can i solve it ? > > > > > > Thanks, > > > > Nicholas. Yes, sorry, I meant @sven not @Stev. The problem with the random number is solved. From nickzacharatos at gmail.com Tue Mar 19 11:26:42 2013 From: nickzacharatos at gmail.com (NZach) Date: Tue, 19 Mar 2013 08:26:42 -0700 (PDT) Subject: Problem this random seed() In-Reply-To: <729b7df7-d1b5-4397-b659-fdab25f10dd2@googlegroups.com> References: <729b7df7-d1b5-4397-b659-fdab25f10dd2@googlegroups.com> Message-ID: <9bb3bf94-5e26-4c97-af10-7650f110e0f1@googlegroups.com> ?? ?????, 19 ??????? 2013 5:23:47 ?.?. UTC+2, ? ??????? NZach ??????: > ?? ?????, 19 ??????? 2013 3:57:30 ?.?. UTC+2, ? ??????? NZach ??????: > > > Hello everyone, > > > > > > > > > > > > i am using the MMK.py example from a SimPy tutorial, which can be found here: http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf > > > > > > > > > > > > I have made very little changes to the code and i have upload it here: > > > > > > http://codeviewer.org/view/code:30d3 > > > > > > > > > > > > The problem is that i am executing the main() function in lines 83 and 90, but > > > > > > i do not receive the same result, although the random seed is used in the G > > > > > > class. > > > > > > > > > > > > Any idea please, how can i solve it ? > > > > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > Nicholas. > > > > Yes, sorry, I meant @sven not @Stev. > > > > The problem with the random number is solved. Thank you very much for the replies. I will check what the now() prints and probably if i wont find any solution i will create new topic. From pengyu.ut at gmail.com Mon Mar 18 22:43:04 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Mon, 18 Mar 2013 21:43:04 -0500 Subject: How avoid installing directories match some pattern when using distutils.core setup? Message-ID: Hi, By default, setup.py will install everything in the source directory. I want mask some directories so that they will not be installed. Is there a way to do so in setup.py? -- Regards, Peng From frank at chagford.com Tue Mar 19 03:26:36 2013 From: frank at chagford.com (Frank Millman) Date: Tue, 19 Mar 2013 09:26:36 +0200 Subject: Best way to find starting directory Message-ID: Hi all I want to locate a file relative to the directory from which the main program was launched. I have found two ways of finding the starting directory - 1. import os dir = os.getcwd() 2. import os.path import __main__ dir = os.path.dirname(__main__.__file__) I know that the first one will return the wrong result if os.chdir() has been executed, but I don't do that. Apart from that, is either version preferred over the other, or is there another way? Thanks Frank Millman From __peter__ at web.de Tue Mar 19 03:55:45 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Mar 2013 08:55:45 +0100 Subject: Best way to find starting directory References: Message-ID: Frank Millman wrote: > I want to locate a file relative to the directory from which the main > program was launched. > > I have found two ways of finding the starting directory - > > 1. > import os > dir = os.getcwd() This gives the current working directory... > 2. > import os.path > import __main__ > dir = os.path.dirname(__main__.__file__) ... and this gives the location of your main script. > I know that the first one will return the wrong result if os.chdir() has > been executed, but I don't do that. You'll get different results when you launch the script with an explicit path: $ cat millman/demo.py import os import __main__ print "cwd:", os.getcwd() print "script path:", os.path.abspath(os.path.dirname(__main__.__file__)) $ python millman/demo.py cwd: /home/frank script path: /home/frank/millman From frank at chagford.com Tue Mar 19 04:21:27 2013 From: frank at chagford.com (Frank Millman) Date: Tue, 19 Mar 2013 10:21:27 +0200 Subject: Best way to find starting directory In-Reply-To: References: Message-ID: On 19/03/2013 09:55, Peter Otten wrote: > Frank Millman wrote: > >> I want to locate a file relative to the directory from which the main >> program was launched. >> >> I have found two ways of finding the starting directory - >> >> 1. >> import os >> dir = os.getcwd() > > This gives the current working directory... > >> 2. >> import os.path >> import __main__ >> dir = os.path.dirname(__main__.__file__) > > ... and this gives the location of your main script. > >> I know that the first one will return the wrong result if os.chdir() has >> been executed, but I don't do that. > > You'll get different results when you launch the script with an explicit > path: > > $ cat millman/demo.py > import os > import __main__ > > print "cwd:", os.getcwd() > print "script path:", os.path.abspath(os.path.dirname(__main__.__file__)) > $ python millman/demo.py > cwd: /home/frank > script path: /home/frank/millman > > That makes sense. I usually launch the script from its own directory, but that is not guaranteed. Therefore option 2 is the way to go. Thanks, Peter Frank From davea at davea.name Tue Mar 19 08:46:45 2013 From: davea at davea.name (Dave Angel) Date: Tue, 19 Mar 2013 08:46:45 -0400 Subject: Best way to find starting directory In-Reply-To: References: Message-ID: <51485E35.7090501@davea.name> On 03/19/2013 04:21 AM, Frank Millman wrote: > On 19/03/2013 09:55, Peter Otten wrote: >> Frank Millman wrote: >> >>> I want to locate a file relative to the directory from which the main >>> program was launched. >>> >>> I have found two ways of finding the starting directory - >>> >>> 1. >>> import os >>> dir = os.getcwd() >> >> This gives the current working directory... >> >>> 2. >>> import os.path >>> import __main__ >>> dir = os.path.dirname(__main__.__file__) >> >> ... and this gives the location of your main script. >> >>> I know that the first one will return the wrong result if os.chdir() has >>> been executed, but I don't do that. >> >> You'll get different results when you launch the script with an explicit >> path: >> >> $ cat millman/demo.py >> import os >> import __main__ >> >> print "cwd:", os.getcwd() >> print "script path:", os.path.abspath(os.path.dirname(__main__.__file__)) >> $ python millman/demo.py >> cwd: /home/frank >> script path: /home/frank/millman >> >> > > That makes sense. I usually launch the script from its own directory, > but that is not guaranteed. > > Therefore option 2 is the way to go. You might want to reconsider. There are really two different kinds of data files you might want to access from your script. The first is constant data that gets initialized when the script is installed. And the second is user data that he's thinking about right now. For example, if a script uses a saved cache of prime numbers to make calculations a bit faster, it might keep that file in with its own source code, or relative to it. And if I wanted to calculate md5 sums for a directory tree, I'd usually make that my cwd before starting the script. Config files are somewhere in between. In Linux, get them relative to the $HOME environment variable. FWIW, I try to keep all the first kind of files on a separate partition, and except where other programs force me, never let them leak onto the OS+program partition. That way, I'm not likely to lose an important jpeg when the OS trashes its partition. This particular paranoia is left over from my Windows days, but I stick to it anyway. It also makes it easier to migrate to a new OS. Just format the OS partition and install the OS and all the apps. The data is already separate. -- DaveA From frank at chagford.com Tue Mar 19 10:29:36 2013 From: frank at chagford.com (Frank Millman) Date: Tue, 19 Mar 2013 16:29:36 +0200 Subject: Best way to find starting directory In-Reply-To: <51485E35.7090501@davea.name> References: <51485E35.7090501@davea.name> Message-ID: On 19/03/2013 14:46, Dave Angel wrote: > On 03/19/2013 04:21 AM, Frank Millman wrote: >> On 19/03/2013 09:55, Peter Otten wrote: >>> Frank Millman wrote: >>> >>>> I want to locate a file relative to the directory from which the main >>>> program was launched. >>>> >>>> I have found two ways of finding the starting directory - >>>> >>>> 1. >>>> import os >>>> dir = os.getcwd() >>> >>> This gives the current working directory... >>> >>>> 2. >>>> import os.path >>>> import __main__ >>>> dir = os.path.dirname(__main__.__file__) >>> >>> ... and this gives the location of your main script. >>> [...] >> >> That makes sense. I usually launch the script from its own directory, >> but that is not guaranteed. >> >> Therefore option 2 is the way to go. > > You might want to reconsider. There are really two different kinds of > data files you might want to access from your script. The first is > constant data that gets initialized when the script is installed. And > the second is user data that he's thinking about right now. > > For example, if a script uses a saved cache of prime numbers to make > calculations a bit faster, it might keep that file in with its own > source code, or relative to it. > > And if I wanted to calculate md5 sums for a directory tree, I'd usually > make that my cwd before starting the script. > > Config files are somewhere in between. In Linux, get them relative to > the $HOME environment variable. > > FWIW, I try to keep all the first kind of files on a separate partition, > and except where other programs force me, never let them leak onto the > OS+program partition. That way, I'm not likely to lose an important > jpeg when the OS trashes its partition. This particular paranoia is > left over from my Windows days, but I stick to it anyway. It also makes > it easier to migrate to a new OS. Just format the OS partition and > install the OS and all the apps. The data is already separate. > Thanks Dave, good advice. I learnt an important lesson from Peter's response, as I did not fully understand the difference before. Now that I do, I am better equipped to make the correct decision for a given situation. As you say, there is a variety of types of data that one might to store externally. My current scenario is that, in my business/accounting application, I use xml to store form definitions, report definitions, etc, which are kept in the database (compressed). I am now constructing some xml schemas to validate the xml files. I need to store the schemas somewhere, so I have created a directory called 'schemas' under the main directory. I need to access them from various parts of the application, so I need a reliable way to locate the 'schemas' directory. In theory I could store them somewhere different, and use a parameter to provide the path. But they are only used within the context of the application, so I think it makes sense to keep them alongside the 'py' files that make up the application. Frank From davea at davea.name Tue Mar 19 11:03:49 2013 From: davea at davea.name (Dave Angel) Date: Tue, 19 Mar 2013 11:03:49 -0400 Subject: Best way to find starting directory In-Reply-To: References: <51485E35.7090501@davea.name> Message-ID: <51487E55.6040704@davea.name> On 03/19/2013 10:29 AM, Frank Millman wrote: > On 19/03/2013 14:46, Dave Angel wrote: >> On 03/19/2013 04:21 AM, Frank Millman wrote: >>> On 19/03/2013 09:55, Peter Otten wrote: >>>> Frank Millman wrote: >>>> >>>>> I want to locate a file relative to the directory from which the main >>>>> program was launched. >>>>> >>>>> I have found two ways of finding the starting directory - >>>>> >>>>> 1. >>>>> import os >>>>> dir = os.getcwd() >>>> >>>> This gives the current working directory... >>>> >>>>> 2. >>>>> import os.path >>>>> import __main__ >>>>> dir = os.path.dirname(__main__.__file__) >>>> >>>> ... and this gives the location of your main script. >>>> > [...] >>> >>> That makes sense. I usually launch the script from its own directory, >>> but that is not guaranteed. >>> >>> Therefore option 2 is the way to go. >> >> You might want to reconsider. There are really two different kinds of >> data files you might want to access from your script. The first is >> constant data that gets initialized when the script is installed. And >> the second is user data that he's thinking about right now. >> >> For example, if a script uses a saved cache of prime numbers to make >> calculations a bit faster, it might keep that file in with its own >> source code, or relative to it. >> >> And if I wanted to calculate md5 sums for a directory tree, I'd usually >> make that my cwd before starting the script. >> >> Config files are somewhere in between. In Linux, get them relative to >> the $HOME environment variable. >> >> FWIW, I try to keep all the first kind of files on a separate partition, >> and except where other programs force me, never let them leak onto the >> OS+program partition. That way, I'm not likely to lose an important >> jpeg when the OS trashes its partition. This particular paranoia is >> left over from my Windows days, but I stick to it anyway. It also makes >> it easier to migrate to a new OS. Just format the OS partition and >> install the OS and all the apps. The data is already separate. >> > > Thanks Dave, good advice. > > I learnt an important lesson from Peter's response, as I did not fully > understand the difference before. Now that I do, I am better equipped to > make the correct decision for a given situation. > > As you say, there is a variety of types of data that one might to store > externally. My current scenario is that, in my business/accounting > application, I use xml to store form definitions, report definitions, > etc, which are kept in the database (compressed). I am now constructing > some xml schemas to validate the xml files. I need to store the schemas > somewhere, so I have created a directory called 'schemas' under the main > directory. I need to access them from various parts of the application, > so I need a reliable way to locate the 'schemas' directory. Rather than having various parts of the code all figuring this sort of thing out for themself, let them all call a common place. If there's nothing in common but the directory, then save that as a global in some module that multiple modules can import. But if there's more that could/should be shared, then make a whole module, or maybe a class, implemmnting that behavior. If nothing else, it then means there's only one place to change when you change your mind. > > In theory I could store them somewhere different, and use a parameter to > provide the path. But they are only used within the context of the > application, so I think it makes sense to keep them alongside the 'py' > files that make up the application. > In putting them there, you are making two assumptions. One is that only one user will ever run this, and two is that the user will not need two sets of those 'schemas'. If the user is tracking two different companies, each with the same code, but different xml and different database, this would be the wrong place to put it. But it's up to you to decide those assumptions, not I. -- DaveA From frank at chagford.com Wed Mar 20 01:58:11 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 20 Mar 2013 07:58:11 +0200 Subject: Best way to find starting directory In-Reply-To: <51487E55.6040704@davea.name> References: <51485E35.7090501@davea.name> <51487E55.6040704@davea.name> Message-ID: On 19/03/2013 17:03, Dave Angel wrote: > On 03/19/2013 10:29 AM, Frank Millman wrote: >> On 19/03/2013 14:46, Dave Angel wrote: >> >> As you say, there is a variety of types of data that one might to store >> externally. My current scenario is that, in my business/accounting >> application, I use xml to store form definitions, report definitions, >> etc, which are kept in the database (compressed). I am now constructing >> some xml schemas to validate the xml files. I need to store the schemas >> somewhere, so I have created a directory called 'schemas' under the main >> directory. I need to access them from various parts of the application, >> so I need a reliable way to locate the 'schemas' directory. > > Rather than having various parts of the code all figuring this sort of > thing out for themself, let them all call a common place. If there's > nothing in common but the directory, then save that as a global in some > module that multiple modules can import. But if there's more that > could/should be shared, then make a whole module, or maybe a class, > implemmnting that behavior. If nothing else, it then means there's only > one place to change when you change your mind. > >> >> In theory I could store them somewhere different, and use a parameter to >> provide the path. But they are only used within the context of the >> application, so I think it makes sense to keep them alongside the 'py' >> files that make up the application. >> > > In putting them there, you are making two assumptions. One is that only > one user will ever run this, and two is that the user will not need two > sets of those 'schemas'. If the user is tracking two different > companies, each with the same code, but different xml and different > database, this would be the wrong place to put it. But it's up to you > to decide those assumptions, not I. > Maybe I did not explain very well. I fully expect a large number of users, tracking a large number of companies, to access the same schema file at the same time. In fact I use lxml to parse the xml once it has been read from the database and decompressed. There are a limited number of 'types' of xml file (form definition, service definition, report definition, etc), and each type has its own schema. lxml will use a validating schema if you pass the path to the xsd file as a parameter to the parser. I create separate parsers, one for each type, when the program starts. But I still need to tell it where to find the xsd file. They are stored in a sub-directory called 'schemas'. Therefore when I create the parsers I have the following - import os import __main__ from lxml import etree schema_path = os.path.join( os.path.dirname(__main__.__file__), 'schemas') form_schema=etree.XMLSchema( file=os.path.join(schema_path, 'form.xsd')) form_parser = etree.XMLParser( schema=form_schema, attribute_defaults=True, remove_comments=True, remove_blank_text=True) I hope that is clearer. If you can see anything wrong with this approach, please let me know. I would much rather find out now rather than when my 'large number of users' becomes a reality! Thanks Frank From davea at davea.name Wed Mar 20 04:56:16 2013 From: davea at davea.name (Dave Angel) Date: Wed, 20 Mar 2013 04:56:16 -0400 Subject: Best way to find starting directory In-Reply-To: References: <51485E35.7090501@davea.name> <51487E55.6040704@davea.name> Message-ID: <514979B0.3060406@davea.name> On 03/20/2013 01:58 AM, Frank Millman wrote: > On 19/03/2013 17:03, Dave Angel wrote: >> On 03/19/2013 10:29 AM, Frank Millman wrote: >>> On 19/03/2013 14:46, Dave Angel wrote: >>> >> In putting them there, you are making two assumptions. One is that only >> one user will ever run this, and two is that the user will not need two >> sets of those 'schemas'. If the user is tracking two different >> companies, each with the same code, but different xml and different >> database, this would be the wrong place to put it. But it's up to you >> to decide those assumptions, not I. >> > > Maybe I did not explain very well. I fully expect a large number of > users, tracking a large number of companies, to access the same schema > file at the same time. So the scheme does NOT describe an individual company, but something more general? Presumably there's a separate database per company? Why then is the schema separately stored in each database? > > In fact I use lxml to parse the xml once it has been read from the > database and decompressed. There are a limited number of 'types' of xml > file (form definition, service definition, report definition, etc), and > each type has its own schema. lxml will use a validating schema if you > pass the path to the xsd file as a parameter to the parser. I create > separate parsers, one for each type, when the program starts. But I > still need to tell it where to find the xsd file. > > They are stored in a sub-directory called 'schemas'. Clearly I don't understand your model well enough to advise you one way or the other. All I can do is ask questions whose answers might remind you of things you know but I do not. This code is running on a server, with simultaneous users? And all users who run it will be using identical xml, which will only be updated when a new version of the script is installed? And each time a user starts the application, you read the xml from the database, write it to a sub-directory 'schemas' and subsequently in the run you access it with lxml? You've considered what happens when one user is creating the files, while another user is still accessing them? Are these 'files' so enormous that you can't just use in-memory file objects? The analogy to global variables must be clear. They're fine if they're constant. But as soon as you have multiple threads making new versions of them, everything can easily get out of whack. -- DaveA From frank at chagford.com Wed Mar 20 05:38:36 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 20 Mar 2013 11:38:36 +0200 Subject: Best way to find starting directory In-Reply-To: <514979B0.3060406@davea.name> References: <51485E35.7090501@davea.name> <51487E55.6040704@davea.name> <514979B0.3060406@davea.name> Message-ID: On 20/03/2013 10:56, Dave Angel wrote: > On 03/20/2013 01:58 AM, Frank Millman wrote: >> On 19/03/2013 17:03, Dave Angel wrote: >>> On 03/19/2013 10:29 AM, Frank Millman wrote: >>>> On 19/03/2013 14:46, Dave Angel wrote: >>>> >>> In putting them there, you are making two assumptions. One is that only >>> one user will ever run this, and two is that the user will not need two >>> sets of those 'schemas'. If the user is tracking two different >>> companies, each with the same code, but different xml and different >>> database, this would be the wrong place to put it. But it's up to you >>> to decide those assumptions, not I. >>> >> >> Maybe I did not explain very well. I fully expect a large number of >> users, tracking a large number of companies, to access the same schema >> file at the same time. > > So the scheme does NOT describe an individual company, but something > more general? Presumably there's a separate database per company? Why > then is the schema separately stored in each database? > >> >> In fact I use lxml to parse the xml once it has been read from the >> database and decompressed. There are a limited number of 'types' of xml >> file (form definition, service definition, report definition, etc), and >> each type has its own schema. lxml will use a validating schema if you >> pass the path to the xsd file as a parameter to the parser. I create >> separate parsers, one for each type, when the program starts. But I >> still need to tell it where to find the xsd file. >> >> They are stored in a sub-directory called 'schemas'. > > Clearly I don't understand your model well enough to advise you one way > or the other. All I can do is ask questions whose answers might remind > you of things you know but I do not. > > This code is running on a server, with simultaneous users? And all > users who run it will be using identical xml, which will only be updated > when a new version of the script is installed? And each time a user > starts the application, you read the xml from the database, write it to > a sub-directory 'schemas' and subsequently in the run you access it > with lxml? You've considered what happens when one user is creating the > files, while another user is still accessing them? > > Are these 'files' so enormous that you can't just use in-memory file > objects? > > The analogy to global variables must be clear. They're fine if they're > constant. But as soon as you have multiple threads making new versions > of them, everything can easily get out of whack. > Dave, I really appreciate your input, but we are talking at cross purposes somewhere along the line - I am not sure where. Firstly, just to ensure there is no confusion, I am not talking about *database* schemas, I am talking about *xml* schemas. From Wikipedia, "An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself." Let's focus on 'form definitions'. What I call a 'form' is something that can be displayed on a user's screen, for data entry, data display, or both, containing text, input fields, checkboxes, buttons, etc, etc. I have devised an xml format to describe the form. When requested, the xml file is read in and sent to the client, which extracts the elements and renders them on the screen. All form definitions are stored in the database. To ensure that they conform to the standard structure which the client is expecting, I have written an XML schema that can be used to validate the content. The XML schema is stored in its sub-directory permanently. Once debugged, it will never be altered. It is the equivalent of source code, that is read and interpreted at execution time. When a user selects a menu option, the form definition is read in from the database, parsed and validated by lxml using the schema, and if ok it will be sent to the client for rendering. Otherwise an exception will be raised. Hope this makes more sense. Frank From davea at davea.name Wed Mar 20 06:17:31 2013 From: davea at davea.name (Dave Angel) Date: Wed, 20 Mar 2013 06:17:31 -0400 Subject: Best way to find starting directory In-Reply-To: References: <51485E35.7090501@davea.name> <51487E55.6040704@davea.name> <514979B0.3060406@davea.name> Message-ID: <51498CBB.1050000@davea.name> On 03/20/2013 05:38 AM, Frank Millman wrote: > On 20/03/2013 10:56, Dave Angel wrote: >> On 03/20/2013 01:58 AM, Frank Millman wrote: >>> On 19/03/2013 17:03, Dave Angel wrote: >> >> > > Dave, I really appreciate your input, but we are talking at cross > purposes somewhere along the line - I am not sure where. > > Firstly, just to ensure there is no confusion, I am not talking about > *database* schemas, I am talking about *xml* schemas. From Wikipedia, > "An XML schema is a description of a type of XML document, typically > expressed in terms of constraints on the structure and content of > documents of that type, above and beyond the basic syntactical > constraints imposed by XML itself." > > Let's focus on 'form definitions'. What I call a 'form' is something > that can be displayed on a user's screen, for data entry, data display, > or both, containing text, input fields, checkboxes, buttons, etc, etc. I > have devised an xml format to describe the form. When requested, the xml > file is read in and sent to the client, which extracts the elements and > renders them on the screen. > > All form definitions are stored in the database. To ensure that they > conform to the standard structure which the client is expecting, I have > written an XML schema that can be used to validate the content. > > The XML schema is stored in its sub-directory permanently. Once > debugged, it will never be altered. It is the equivalent of source code, > that is read and interpreted at execution time. That paragraph says it all. It's constant, so it belongs with the source code. Somehow I thought you were writing the xml into that directory. Thanks for clarifying. > > When a user selects a menu option, the form definition is read in from > the database, parsed and validated by lxml using the schema, and if ok > it will be sent to the client for rendering. Otherwise an exception will > be raised. > > Hope this makes more sense. > > Frank > > -- DaveA From adamnizar01 at gmail.com Tue Mar 19 09:16:15 2013 From: adamnizar01 at gmail.com (adamnizar01 at gmail.com) Date: Tue, 19 Mar 2013 06:16:15 -0700 (PDT) Subject: How to extract certain set of lines from PDF Message-ID: Hello, I need to extract certain set of lines from PDF Ex:- IF(......) .......... .......... IF(.....) ........... ........... ENDIF ENDIF I need to copy entire lines from first "IF" till last "ENDIF".and extract it to seperate row of excel sheet.when ever a new occurrance of this kind of IF loops are found out. From joel.goldstick at gmail.com Tue Mar 19 09:46:00 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 19 Mar 2013 09:46:00 -0400 Subject: How to extract certain set of lines from PDF In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 9:16 AM, wrote: > Hello, > > I need to extract certain set of lines from PDF > Ex:- > IF(......) > .......... > .......... > IF(.....) > ........... > ........... > ENDIF > ENDIF > > I need to copy entire lines from first "IF" till last "ENDIF".and extract > it to seperate row of excel sheet.when ever a new occurrance of this kind > of IF loops are found out. > -- > http://mail.python.org/mailman/listinfo/python-list > You might start with this: http://knowah.github.com/PyPDF2/ I've never had to read pdf files, but it looks like there are several libraries to choose from -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From razinzamada at gmail.com Tue Mar 19 10:01:52 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 07:01:52 -0700 (PDT) Subject: How to extract certain set of lines from PDF In-Reply-To: References: Message-ID: <68de7633-a07b-495b-b555-2951508027bc@googlegroups.com> Thank you for your response,in case if its a word file how could i do this. On Tuesday, March 19, 2013 7:16:00 PM UTC+5:30, Joel Goldstick wrote: > On Tue, Mar 19, 2013 at 9:16 AM, wrote: > > Hello, > > > > I need to extract certain set of lines from PDF > > Ex:- > > IF(......) > > .......... > > .......... > > ? ?IF(.....) > > ? ?........... > > ? ?........... > > ? ?ENDIF > > ENDIF > > > > I need to copy entire lines from first "IF" till last "ENDIF".and extract it to seperate row of excel sheet.when ever a new occurrance of this kind of IF loops are found out. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > You might start with this: http://knowah.github.com/PyPDF2/ > > > I've never had to read pdf files, but it looks like there are several libraries to choose from > > > > > -- > > > Joel Goldstick > http://joelgoldstick.com From razinzamada at gmail.com Tue Mar 19 10:01:52 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 07:01:52 -0700 (PDT) Subject: How to extract certain set of lines from PDF In-Reply-To: References: Message-ID: <68de7633-a07b-495b-b555-2951508027bc@googlegroups.com> Thank you for your response,in case if its a word file how could i do this. On Tuesday, March 19, 2013 7:16:00 PM UTC+5:30, Joel Goldstick wrote: > On Tue, Mar 19, 2013 at 9:16 AM, wrote: > > Hello, > > > > I need to extract certain set of lines from PDF > > Ex:- > > IF(......) > > .......... > > .......... > > ? ?IF(.....) > > ? ?........... > > ? ?........... > > ? ?ENDIF > > ENDIF > > > > I need to copy entire lines from first "IF" till last "ENDIF".and extract it to seperate row of excel sheet.when ever a new occurrance of this kind of IF loops are found out. > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > You might start with this: http://knowah.github.com/PyPDF2/ > > > I've never had to read pdf files, but it looks like there are several libraries to choose from > > > > > -- > > > Joel Goldstick > http://joelgoldstick.com From s.arun316 at gmail.com Tue Mar 19 09:56:58 2013 From: s.arun316 at gmail.com (s.arun316 at gmail.com) Date: Tue, 19 Mar 2013 06:56:58 -0700 (PDT) Subject: How to send data from excel to website using python please help? Message-ID: <4cfedfe7-8ade-4ef6-a5a9-b9be3f37e813@googlegroups.com> Hi, im new to python. Wanted to know how to extract data from excel sheet and send it to webpage form. Thanks in advance. From neilc at norwich.edu Tue Mar 19 10:22:14 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2013 14:22:14 GMT Subject: How to send data from excel to website using python please help? References: <4cfedfe7-8ade-4ef6-a5a9-b9be3f37e813@googlegroups.com> Message-ID: On 2013-03-19, s.arun316 at gmail.com wrote: > Hi, im new to python. Wanted to know how to extract data from > excel sheet and send it to webpage form. Thanks in advance. I like to export Excel documents as csv files and read them using the csv module's DictReader class. You can read from them directly using something like xlrd if you prefer, but I find it pales in comparison. My advice is to avoid reading the Excel file directly unless you have no other choice. Happily (for me) I don't know the answer to the second part of your question. -- Neil Cerutti From joel.goldstick at gmail.com Tue Mar 19 10:52:34 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 19 Mar 2013 10:52:34 -0400 Subject: How to send data from excel to website using python please help? In-Reply-To: References: <4cfedfe7-8ade-4ef6-a5a9-b9be3f37e813@googlegroups.com> Message-ID: On Tue, Mar 19, 2013 at 10:22 AM, Neil Cerutti wrote: > On 2013-03-19, s.arun316 at gmail.com wrote: > > Hi, im new to python. Wanted to know how to extract data from > > excel sheet and send it to webpage form. Thanks in advance. > > Can you be more clear about what you want to do with this data? "Send it to webpage form" sounds like you want to use the data to fill in fields in a form on some website. Is that what you mean? Is the website yours or some third party's? > I like to export Excel documents as csv files and read them using > the csv module's DictReader class. > > You can read from them directly using something like xlrd if you > prefer, but I find it pales in comparison. My advice is to avoid > reading the Excel file directly unless you have no other choice. > > Happily (for me) I don't know the answer to the second part of > your question. > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From razinzamada at gmail.com Tue Mar 19 10:20:57 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 07:20:57 -0700 (PDT) Subject: Need help in extracting lines from word using python Message-ID: I'm currently trying to extract some data between 2 lines of an input file using Python. the infile is set up such that there is a line -START- where I need the next 10 lines of code if and only if the -END- condition occurs before the next -START-. The -START- line occurs many times before the -END-. Heres a general example of what I mean: blah blah -START- 10 lines I DONT need blah -START- 10 lines I need blah blah -END- blah blah -START- 10 lines I dont need blah -START- .... and so on and so forth so far I have only been able to get the -START- + 10 lines for every iteration, but am at a total loss when it comes to specifying the condition to only write if the -END- condition comes before another -START- condition. I'm a bit of a newb, so any help will be greatly appreciated. heres the code I have for printing the -START- + 10 lines: in = open('input.log') out = open('output.txt', 'a') lines = in.readlines() for i, line in enumerate(lines): if (line.find('START')) > -1: out.write(line) out.write(lines[i + 1]) out.write(lines[i + 2]) out.write(lines[i + 3]) out.write(lines[i + 4]) out.write(lines[i + 5]) out.write(lines[i + 6]) out.write(lines[i + 7]) out.write(lines[i + 8]) out.write(lines[i + 9]) out.write(lines[i + 10]) From steve+comp.lang.python at pearwood.info Tue Mar 19 10:41:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2013 14:41:22 GMT Subject: Need help in extracting lines from word using python References: Message-ID: <51487911$0$6599$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Mar 2013 07:20:57 -0700, razinzamada wrote: > I'm currently trying to extract some data between 2 lines of an input > file using Python. the infile is set up such that there is a line > -START- where I need the next 10 lines of code if and only if the -END- > condition occurs before the next -START-. The -START- line occurs many > times before the -END-. Heres a general example of what I mean: > > blah > blah > -START- > 10 lines I DONT need > blah > -START- > 10 lines I need > blah > blah > -END- > blah > blah > -START- > 10 lines I dont need > blah > -START- > > .... and so on and so forth [...] > heres the code I have for printing the -START- + 10 lines: > > in = open('input.log') No it is not. "in" is a reserved word in Python, that code cannot possibly work, it will give a SyntaxError. Try this code. Untested but it should do want you want. infile = open('input.log') outfile = open('output.txt', 'a') # Accumulate lines between START and END lines, ignoring everything else. collect = False # Initially we start by ignoring lines. for line in infile: if '-START-' in line: # Ignore any lines already seen, and start collecting. accum = [] collect = True elif '-END-' in line: # Write the first ten accumulated lines. outfile.writelines(accum[:10]) # Clear the accumulated lines. accum = [] # and stop collecting until the next START line collect = False elif collect: accum.append(line) outfile.close() infile.close() -- Steven From razinzamada at gmail.com Wed Mar 20 02:13:42 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 23:13:42 -0700 (PDT) Subject: Need help in extracting lines from word using python In-Reply-To: <51487911$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <51487911$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <73c06136-249a-41fd-862f-c454362fbc62@googlegroups.com> Thanks steven On Tuesday, March 19, 2013 8:11:22 PM UTC+5:30, Steven D'Aprano wrote: > On Tue, 19 Mar 2013 07:20:57 -0700, razinzamada wrote: > > > > > I'm currently trying to extract some data between 2 lines of an input > > > file using Python. the infile is set up such that there is a line > > > -START- where I need the next 10 lines of code if and only if the -END- > > > condition occurs before the next -START-. The -START- line occurs many > > > times before the -END-. Heres a general example of what I mean: > > > > > > blah > > > blah > > > -START- > > > 10 lines I DONT need > > > blah > > > -START- > > > 10 lines I need > > > blah > > > blah > > > -END- > > > blah > > > blah > > > -START- > > > 10 lines I dont need > > > blah > > > -START- > > > > > > .... and so on and so forth > > > > [...] > > > > > heres the code I have for printing the -START- + 10 lines: > > > > > > in = open('input.log') > > > > No it is not. "in" is a reserved word in Python, that code cannot > > possibly work, it will give a SyntaxError. > > > > > > Try this code. Untested but it should do want you want. > > > > > > infile = open('input.log') > > outfile = open('output.txt', 'a') > > # Accumulate lines between START and END lines, ignoring everything else. > > collect = False # Initially we start by ignoring lines. > > for line in infile: > > if '-START-' in line: > > # Ignore any lines already seen, and start collecting. > > accum = [] > > collect = True > > elif '-END-' in line: > > # Write the first ten accumulated lines. > > outfile.writelines(accum[:10]) > > # Clear the accumulated lines. > > accum = [] > > # and stop collecting until the next START line > > collect = False > > elif collect: > > accum.append(line) > > > > outfile.close() > > infile.close() > > > > > > > > -- > > Steven From davea at davea.name Tue Mar 19 10:54:24 2013 From: davea at davea.name (Dave Angel) Date: Tue, 19 Mar 2013 10:54:24 -0400 Subject: Need help in extracting lines from word using python In-Reply-To: References: Message-ID: <51487C20.2070209@davea.name> On 03/19/2013 10:20 AM, razinzamada at gmail.com wrote: > I'm currently trying to extract some data between 2 lines of an input file Your subject line says "from word". I'm only guessing that you might mean Microsoft Word, a proprietary program that does not, by default, save text files. The following code and description assumes a text file, so there's a contradiction. > using Python. the infile is set up such that there is a line -START- where I need the next 10 lines of code if and only if the -END- condition occurs before the next -START-. The -START- line occurs many times before the -END-. Heres a general example of what I mean: > In other words, you want to scan for -END-, then go backwards to -START- and use the first ten of the lines between? Try coding it that way, and perhaps it'll be easier. You also need to consider (and specify behavior for) the possibility that start and end are less than 10 lines apart. > blah > blah > -START- > 10 lines I DONT need > blah > -START- > 10 lines I need > blah > blah > -END- > blah > blah > -START- > 10 lines I dont need > blah > -START- > > .... and so on and so forth > > so far I have only been able to get the -START- + 10 lines for every iteration, but am at a total loss when it comes to specifying the condition to only write if the -END- condition comes before another -START- condition. I'm a bit of a newb, so any help will be greatly appreciated. > > > heres the code I have for printing the -START- + 10 lines: > > in = open('input.log') > out = open('output.txt', 'a') > > lines = in.readlines() > for i, line in enumerate(lines): > if (line.find('START')) > -1: > out.write(line) > out.write(lines[i + 1]) > out.write(lines[i + 2]) > out.write(lines[i + 3]) > out.write(lines[i + 4]) > out.write(lines[i + 5]) > out.write(lines[i + 6]) > out.write(lines[i + 7]) > out.write(lines[i + 8]) > out.write(lines[i + 9]) > out.write(lines[i + 10]) or just out.write(lines[i:i+11) to write out all 11 of them. > -- DaveA From razinzamada at gmail.com Wed Mar 20 02:14:54 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 23:14:54 -0700 (PDT) Subject: Need help in extracting lines from word using python In-Reply-To: References: Message-ID: <877193b9-80f3-466f-b93e-d9eb5150a313@googlegroups.com> Thanks DAVE On Tuesday, March 19, 2013 8:24:24 PM UTC+5:30, Dave Angel wrote: > On 03/19/2013 10:20 AM, razinzamada at gmail.com wrote: > > > I'm currently trying to extract some data between 2 lines of an input file > > > > Your subject line says "from word". I'm only guessing that you might > > mean Microsoft Word, a proprietary program that does not, by default, > > save text files. The following code and description assumes a text > > file, so there's a contradiction. > > > > > > > using Python. the infile is set up such that there is a line -START- where I need the next 10 lines of code if and only if the -END- condition occurs before the next -START-. The -START- line occurs many times before the -END-. Heres a general example of what I mean: > > > > > > > In other words, you want to scan for -END-, then go backwards to -START- > > and use the first ten of the lines between? Try coding it that way, and > > perhaps it'll be easier. > > > > You also need to consider (and specify behavior for) the possibility > > that start and end are less than 10 lines apart. > > > > > blah > > > blah > > > -START- > > > 10 lines I DONT need > > > blah > > > -START- > > > 10 lines I need > > > blah > > > blah > > > -END- > > > blah > > > blah > > > -START- > > > 10 lines I dont need > > > blah > > > -START- > > > > > > .... and so on and so forth > > > > > > so far I have only been able to get the -START- + 10 lines for every iteration, but am at a total loss when it comes to specifying the condition to only write if the -END- condition comes before another -START- condition. I'm a bit of a newb, so any help will be greatly appreciated. > > > > > > > > > heres the code I have for printing the -START- + 10 lines: > > > > > > in = open('input.log') > > > out = open('output.txt', 'a') > > > > > > lines = in.readlines() > > > for i, line in enumerate(lines): > > > if (line.find('START')) > -1: > > > out.write(line) > > > out.write(lines[i + 1]) > > > out.write(lines[i + 2]) > > > out.write(lines[i + 3]) > > > out.write(lines[i + 4]) > > > out.write(lines[i + 5]) > > > out.write(lines[i + 6]) > > > out.write(lines[i + 7]) > > > out.write(lines[i + 8]) > > > out.write(lines[i + 9]) > > > out.write(lines[i + 10]) > > > > or just out.write(lines[i:i+11) to write out all 11 of them. > > > > > > > > > -- > > DaveA From razinzamada at gmail.com Wed Mar 20 02:14:54 2013 From: razinzamada at gmail.com (razinzamada at gmail.com) Date: Tue, 19 Mar 2013 23:14:54 -0700 (PDT) Subject: Need help in extracting lines from word using python In-Reply-To: References: Message-ID: <877193b9-80f3-466f-b93e-d9eb5150a313@googlegroups.com> Thanks DAVE On Tuesday, March 19, 2013 8:24:24 PM UTC+5:30, Dave Angel wrote: > On 03/19/2013 10:20 AM, razinzamada at gmail.com wrote: > > > I'm currently trying to extract some data between 2 lines of an input file > > > > Your subject line says "from word". I'm only guessing that you might > > mean Microsoft Word, a proprietary program that does not, by default, > > save text files. The following code and description assumes a text > > file, so there's a contradiction. > > > > > > > using Python. the infile is set up such that there is a line -START- where I need the next 10 lines of code if and only if the -END- condition occurs before the next -START-. The -START- line occurs many times before the -END-. Heres a general example of what I mean: > > > > > > > In other words, you want to scan for -END-, then go backwards to -START- > > and use the first ten of the lines between? Try coding it that way, and > > perhaps it'll be easier. > > > > You also need to consider (and specify behavior for) the possibility > > that start and end are less than 10 lines apart. > > > > > blah > > > blah > > > -START- > > > 10 lines I DONT need > > > blah > > > -START- > > > 10 lines I need > > > blah > > > blah > > > -END- > > > blah > > > blah > > > -START- > > > 10 lines I dont need > > > blah > > > -START- > > > > > > .... and so on and so forth > > > > > > so far I have only been able to get the -START- + 10 lines for every iteration, but am at a total loss when it comes to specifying the condition to only write if the -END- condition comes before another -START- condition. I'm a bit of a newb, so any help will be greatly appreciated. > > > > > > > > > heres the code I have for printing the -START- + 10 lines: > > > > > > in = open('input.log') > > > out = open('output.txt', 'a') > > > > > > lines = in.readlines() > > > for i, line in enumerate(lines): > > > if (line.find('START')) > -1: > > > out.write(line) > > > out.write(lines[i + 1]) > > > out.write(lines[i + 2]) > > > out.write(lines[i + 3]) > > > out.write(lines[i + 4]) > > > out.write(lines[i + 5]) > > > out.write(lines[i + 6]) > > > out.write(lines[i + 7]) > > > out.write(lines[i + 8]) > > > out.write(lines[i + 9]) > > > out.write(lines[i + 10]) > > > > or just out.write(lines[i:i+11) to write out all 11 of them. > > > > > > > > > -- > > DaveA From Robert.Flintham at uhb.nhs.uk Tue Mar 19 11:10:42 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Tue, 19 Mar 2013 15:10:42 +0000 Subject: "module could not be found" error Message-ID: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> Hi, I'm trying to run the following, with representing an array of floating point numbers: ------------------------------------------------------------ import numpy as np import scipy as sp from scipy import optimize xdata= ydata= def t2fit(x,T2,A): return A * np.exp(-x/T2) popt, pcov = optimize.curve_fit(t2fit, xdata, ydata, p0=None, sigma=None) ------------------------------------------------------------ But I'm getting an ImportError: Traceback (most recent call last): File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1397, in debugger.run(setup['file'], None, None) File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1090, in run pydev_imports.execfile(file, globals, locals) #execute the script File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\_pydev_execfile.py", line 38, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script File "K:\PROGRAMMING\MRI_Python\fatfrac.py", line 7, in from scipy import optimize File "K:\Python33\lib\site-packages\scipy\optimize\__init__.py", line 147, in from ._minimize import * File "K:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line 29, in from .lbfgsb import _minimize_lbfgsb File "K:\Python33\lib\site-packages\scipy\optimize\lbfgsb.py", line 40, in from . import _lbfgsb ImportError: DLL load failed: The specified module could not be found. I've checked the path, and the file lbfgsb.py is definitely at that location (as are optimize.py and _minimize.py). Does anyone know why I'm getting the error? All the best, Rob Robert Flintham Trainee Clinical Scientist - MRI Tel: +44 (0)121 371 7000 Email: Robert.Flintham at uhb.nhs.uk Web: http://www.uhb.nhs.uk We're bringing the world's most advanced cancer treatments to Birmingham. Find out more at www.qecancerappeal.org or text QEHB01 ?5 to 70070 to donate ?5 to our appeal. RRPPS Medical Physics - University Hospitals Birmingham NHS Foundation Trust 63 Melchett Road, Kings Norton, Birmingham, B30 3HP [cid:image001.gif at 01CE24B3.0686DA50] DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.gif Type: image/gif Size: 1941 bytes Desc: image001.gif URL: From davea at davea.name Tue Mar 19 11:24:18 2013 From: davea at davea.name (Dave Angel) Date: Tue, 19 Mar 2013 11:24:18 -0400 Subject: "module could not be found" error In-Reply-To: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> References: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> Message-ID: <51488322.8060603@davea.name> On 03/19/2013 11:10 AM, Robert Flintham wrote: > Hi, > > I'm trying to run the following, with representing an array of floating point numbers: > > ------------------------------------------------------------ > import numpy as np > import scipy as sp > from scipy import optimize > > xdata= > ydata= > > def t2fit(x,T2,A): > return A * np.exp(-x/T2) > > popt, pcov = optimize.curve_fit(t2fit, xdata, ydata, p0=None, sigma=None) > ------------------------------------------------------------ > > But I'm getting an ImportError: > > Traceback (most recent call last): > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1397, in > debugger.run(setup['file'], None, None) > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1090, in run > pydev_imports.execfile(file, globals, locals) #execute the script > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\_pydev_execfile.py", line 38, in execfile > exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script > File "K:\PROGRAMMING\MRI_Python\fatfrac.py", line 7, in > from scipy import optimize > File "K:\Python33\lib\site-packages\scipy\optimize\__init__.py", line 147, in > from ._minimize import * > File "K:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line 29, in > from .lbfgsb import _minimize_lbfgsb > File "K:\Python33\lib\site-packages\scipy\optimize\lbfgsb.py", line 40, in > from . import _lbfgsb > ImportError: DLL load failed: The specified module could not be found. > > > I've checked the path, and the file lbfgsb.py is definitely at that location (as are optimize.py and _minimize.py). Does anyone know why I'm getting the error? > You're on Windows, so presumably you're using the PATH environment variable for the following search. You checked the path for what file? it's looking for _lhfgsb.dll, or maybe _lhfgsb.pyc which is imported by lbfgsh.py. The latter file is found, as you can tell from the stack trace. That's the file you got the error in. So perhaps the dll isn't being loaded into a directory that's on the PATH. -- DaveA From joel.goldstick at gmail.com Tue Mar 19 11:26:02 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 19 Mar 2013 11:26:02 -0400 Subject: "module could not be found" error In-Reply-To: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> References: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> Message-ID: On Tue, Mar 19, 2013 at 11:10 AM, Robert Flintham < Robert.Flintham at uhb.nhs.uk> wrote: > Hi,**** > > ** ** > > I?m trying to run the following, with representing an array of > floating point numbers:**** > > ** ** > > ------------------------------------------------------------**** > > import numpy as np**** > > import scipy as sp**** > > from scipy import optimize**** > > ** ** > > xdata=**** > > ydata=**** > > ** ** > > def t2fit(x,T2,A):**** > > return A * np.exp(-x/T2)**** > > ** ** > > popt, pcov = optimize.curve_fit(t2fit, xdata, ydata, p0=None, sigma=None)* > *** > > ------------------------------------------------------------**** > > ** ** > > But I?m getting an ImportError:**** > > ** ** > > Traceback (most recent call last):**** > > File > "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", > line 1397, in **** > > debugger.run(setup['file'], None, None)**** > > File > "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", > line 1090, in run**** > > pydev_imports.execfile(file, globals, locals) #execute the script**** > > File > "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\_pydev_execfile.py", > line 38, in execfile**** > > exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the > script**** > > File "K:\PROGRAMMING\MRI_Python\fatfrac.py", line 7, in **** > > from scipy import optimize**** > > File "K:\Python33\lib\site-packages\scipy\optimize\__init__.py", line > 147, in **** > > from ._minimize import ***** > > File "K:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line > 29, in **** > > from .lbfgsb import _minimize_lbfgsb**** > > File "K:\Python33\lib\site-packages\scipy\optimize\lbfgsb.py", line 40, > in **** > > from . import _lbfgsb**** > > ImportError: DLL load failed: The specified module could not be found.**** > > ** > Looking at the paths, it looks like some packages are for p 2.7 and some for p 3.3 > ** > > ** ** > > I?ve checked the path, and the file lbfgsb.py is definitely at that > location (as are optimize.py and _minimize.py). Does anyone know why I?m > getting the error?**** > > ** ** > > All the best,**** > > Rob**** > > ** ** > > ** ** > > ** ** > > *Robert Flintham > Trainee Clinical Scientist - MRI***** > > Tel:**** > > +44 (0)121 371 7000**** > > Email:**** > > Robert.Flintham at uhb.nhs.uk**** > > Web:**** > > http://www.uhb.nhs.uk**** > > > *We?re bringing the world's most advanced cancer treatments to Birmingham. > Find out more at www.qecancerappeal.org or text **QEHB01 ?5** to **70070**to donate ?5 to our appeal. > ** > ** > RRPPS > Medical Physics - University Hospitals Birmingham NHS Foundation Trust > 63 Melchett Road, Kings Norton, > Birmingham, B30 3HP > ** > ******* > > > > DISCLAIMER: > > This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.gif Type: image/gif Size: 1941 bytes Desc: not available URL: From Robert.Flintham at uhb.nhs.uk Tue Mar 19 11:58:51 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Tue, 19 Mar 2013 15:58:51 +0000 Subject: "module could not be found" error In-Reply-To: <20130319152807.D3D6B4584D3@nhs-pd1e-esg008.ad1.nhs.net> References: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> <20130319152807.D3D6B4584D3@nhs-pd1e-esg008.ad1.nhs.net> Message-ID: <20130319155905.E385E448958@nhs-pd1e-esg110.ad1.nhs.net> Joel: The 2.7 is the version number of the PyDev plugin for Eclipse, rather than the Python version number. Dave: I don't have access to the system's PATH environment variable because this computer is very tightly controlled. However, my user PATH environment contains "K:\Python33", which I haven't had a problem with before when importing modules from site-packages. The directory "site-packages\scipy\optimize" contains (among other things): __init.py__ _minimize.py _lbfgsb.pyd lbfgsb.py So I'm not entirely sure what it is that it can't find. All the best, Rob (Apologies for lengthy disclaimers, I can't get rid of them. Work email.) -----Original Message----- From: Python-list [mailto:python-list-bounces+robert.flintham=uhb.nhs.uk at python.org] On Behalf Of Dave Angel Sent: 19 March 2013 15:24 To: python-list at python.org Subject: Re: "module could not be found" error On 03/19/2013 11:10 AM, Robert Flintham wrote: > Hi, > > I'm trying to run the following, with representing an array of floating point numbers: > > ------------------------------------------------------------ > import numpy as np > import scipy as sp > from scipy import optimize > > xdata= > ydata= > > def t2fit(x,T2,A): > return A * np.exp(-x/T2) > > popt, pcov = optimize.curve_fit(t2fit, xdata, ydata, p0=None, > sigma=None) > ------------------------------------------------------------ > > But I'm getting an ImportError: > > Traceback (most recent call last): > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1397, in > debugger.run(setup['file'], None, None) > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1090, in run > pydev_imports.execfile(file, globals, locals) #execute the script > File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\_pydev_execfile.py", line 38, in execfile > exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script > File "K:\PROGRAMMING\MRI_Python\fatfrac.py", line 7, in > from scipy import optimize > File "K:\Python33\lib\site-packages\scipy\optimize\__init__.py", line 147, in > from ._minimize import * > File "K:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line 29, in > from .lbfgsb import _minimize_lbfgsb > File "K:\Python33\lib\site-packages\scipy\optimize\lbfgsb.py", line 40, in > from . import _lbfgsb > ImportError: DLL load failed: The specified module could not be found. > > > I've checked the path, and the file lbfgsb.py is definitely at that location (as are optimize.py and _minimize.py). Does anyone know why I'm getting the error? > You're on Windows, so presumably you're using the PATH environment variable for the following search. You checked the path for what file? it's looking for _lhfgsb.dll, or maybe _lhfgsb.pyc which is imported by lbfgsh.py. The latter file is found, as you can tell from the stack trace. That's the file you got the error in. So perhaps the dll isn't being loaded into a directory that's on the PATH. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. From steve+comp.lang.python at pearwood.info Tue Mar 19 22:07:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2013 02:07:51 GMT Subject: "module could not be found" error References: <20130319151020.0606144837F@nhs-pd1e-esg103.ad1.nhs.net> <20130319152807.D3D6B4584D3@nhs-pd1e-esg008.ad1.nhs.net> Message-ID: <514919f6$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Mar 2013 15:58:51 +0000, Robert Flintham wrote: > Joel: The 2.7 is the version number of the PyDev plugin for Eclipse, > rather than the Python version number. > > Dave: I don't have access to the system's PATH environment variable > because this computer is very tightly controlled. However, my user PATH > environment contains "K:\Python33", which I haven't had a problem with > before when importing modules from site-packages. You seem to have a conflict between Eclipse, which is expecting Python 2.7, and your PATH, which is Python 3.3. It's possible that you've got some Python 3.3 modules in a Python 2.7 installation, and things are getting confused. By the way, do you mean the PYTHONPATH, which is different from the PATH? I don't use Windows, so I might be missing something, but normally Python will search for modules in the PYTHONPATH, not PATH. The best thing to do is to check what path Python is using at run-time rather than to try to predict from the PATH or PYTHONPATH environment variables. Put this at the very beginning of your code, and report what it prints. import sys print (sys.version) print (sys.path) (I've included parentheses around the print calls in case you're running under Python 3.) Another thing to try, can you run your code directly without using Eclipse? It may be that Eclipse is confused and if you run the code directly it will be fine. From your Windows command line (cmd.exe, I think) try running this command and see what it does: python C:\path\to\my\project\myproject.py You may need to provide the full path to the python executable. -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 19 21:50:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2013 01:50:02 GMT Subject: "module could not be found" error References: Message-ID: <514915ca$0$30001$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Mar 2013 15:10:42 +0000, Robert Flintham wrote: > equiv=Content-Type content="text/html; charset=iso-8859-1"> name=Generator content="Microsoft Word 12 (filtered medium)"> PyQt4 ! I tried to collect other experiences via Google. No luck. jmf From accessnewbie at gmail.com Tue Mar 19 20:34:26 2013 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Tue, 19 Mar 2013 17:34:26 -0700 (PDT) Subject: Grouping on and exporting to csv files Message-ID: <5c26021f-3285-400f-995d-93c2f74ee5d9@googlegroups.com> My current Test_Sort.csv looks like this (which constantly changes-although never more than 4 records, thus far anyway): RecNo,Count,District,Fruit,StoreNo 1,100,0,oranges,1254 2,30,3,apples,654 3,100,0,bananas,21 4,0,4,grapes,478 I wrote the following python 2.7 script (stuck with 2.7) --------------------- import sys import csv import operator source = "E:\\Data\\Test_Sort.csv" result = "E:\\Data\\Test_Sort1.csv" with open(source,"rb") as source: rdr= csv.reader( source ) with open(result,"wb") as result: next(rdr, None) # Skip header wtr= csv.writer( result ) for r in rdr: wtr.writerow( (r[2], r[3])) # Only write columns 3 and 4 to a csv file exit exit data = csv.reader(open("E:\\Data\\Test_Sort1.csv"),delimiter=',') sortedlist = sorted(data, key=operator.itemgetter(0,1)) # sort by column 1, the 2 print sortedlist ----------------------------- My sortedlist results are: [['0', 'bananas'], ['0', 'oranges'], ['3', 'apples'], ['4', 'grapes']] I want to output all fruits with the same District number out to a csv file called by its District number. (No headers) Thus in above example I would ultimately have three csv files: 0.csv bananas oranges 3.csv apples 4.csv grapes Question is : Any ideas as to how export this sortedlist to the tables described above? I already have a script that already will look at each file and count the number of lines and insert the correct number of commas and the word "and" where appropriate in a sentence. My ultimate goal is to read each file and print out a sentence based on whether it has record or not, and if so how many records and then add the word "and" and/or commas between records if greater than 1. I will then concatenate all the sentences together to form a paragraph. Thus, the above example would say: The western district sold bananas and oranges. The central district sold apples. The southern district sold grapes. or if the files were: 0.csv apples bananas oranges 2.csv grapes The resulting paragraph would read: The western district sold apples, bananas, and oranges. The eastern district sold grapes. It may seem like a crazy way about getting my results but it was the best I could come up with given my limited knowledge of python. Thanks for any and all help. From __peter__ at web.de Wed Mar 20 03:21:40 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Mar 2013 08:21:40 +0100 Subject: Grouping on and exporting to csv files References: <5c26021f-3285-400f-995d-93c2f74ee5d9@googlegroups.com> Message-ID: accessnewbie at gmail.com wrote: > My current Test_Sort.csv looks like this (which constantly > changes-although never more than 4 records, thus far anyway): > > RecNo,Count,District,Fruit,StoreNo > 1,100,0,oranges,1254 > 2,30,3,apples,654 > 3,100,0,bananas,21 > 4,0,4,grapes,478 > > I wrote the following python 2.7 script (stuck with 2.7) > > --------------------- > import sys > import csv > import operator > > > source = "E:\\Data\\Test_Sort.csv" > result = "E:\\Data\\Test_Sort1.csv" > > with open(source,"rb") as source: > rdr= csv.reader( source ) > with open(result,"wb") as result: > next(rdr, None) # Skip header > wtr= csv.writer( result ) > for r in rdr: > wtr.writerow( (r[2], r[3])) # Only write columns 3 and 4 to a > csv file > exit > exit > > data = csv.reader(open("E:\\Data\\Test_Sort1.csv"),delimiter=',') > sortedlist = sorted(data, key=operator.itemgetter(0,1)) # sort by column > 1, the 2 print sortedlist > > ----------------------------- > > My sortedlist results are: > > [['0', 'bananas'], ['0', 'oranges'], ['3', 'apples'], ['4', 'grapes']] > > I want to output all fruits with the same District number out to a csv > file called by its District number. (No headers) > > Thus in above example I would ultimately have three csv files: > > 0.csv > bananas > oranges > > 3.csv > apples > > 4.csv > grapes > > Question is : Any ideas as to how export this sortedlist to the tables > described above? The standard library offers itertools.groupby() for district, group in itertools.groupby( sortedlist, key=operator.itemgetter(0)): with open(district + ".csv", "wb") as outfile: csv.writer(outfile).writerows(group) If you want try to do it by hand as an exercise -- you need a variable to keep track of the current district: last_district = None for row in sortedlist: district = row[0] if last_district != district: # open new file/writer last_district = district # write row > I already have a script that already will look at each file and count the > number of lines and insert the correct number of commas and the word "and" > where appropriate in a sentence. > > My ultimate goal is to read each file and print out a sentence based on > whether it has record or not, and if so how many records and then add the > word "and" and/or commas between records if greater than 1. I will then > concatenate all the sentences together to form a paragraph. > > Thus, the above example would say: > > The western district sold bananas and oranges. The central district sold > apples. The southern district sold grapes. Have a look at str.join(): >>> colors = ["red", "yellow", "blue"] >>> print "Who's afraid of {}, and {}?".format(", ".join(colors[:-1]), colors[-1]) Who's afraid of red, yellow, and blue? > or if the files were: > > 0.csv > apples > bananas > oranges > > 2.csv > grapes > > The resulting paragraph would read: > > The western district sold apples, bananas, and oranges. The eastern > district sold grapes. > > It may seem like a crazy way about getting my results but it was the best > I could come up with given my limited knowledge of python. No, it is what experienced programmers do all the time -- break a complex task into manageable steps, come up with a simple solution for each step, and then improve these steps as needed. From alec.taylor6 at gmail.com Tue Mar 19 22:03:53 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 19 Mar 2013 19:03:53 -0700 (PDT) Subject: Are there any Python libraries/frameworks which generate AngularJS? Message-ID: I find the stateless SOA architecture to be increasingly useful and relevant. For example, it allows you to write once; deploy to: - Website (for viewing in web browsers) - Native mobile apps (using Adobe PhoneGap or similar) - Ubuntu apps - Windows Metro Store apps (for Windows 8) Unfortunately this design has a major drawback; slower development time. Using any ORM and an associated form generator, one can develop their web application very quickly. Are there any ORM form generators for Python which can translate Models to AngularJS forms? [including CSRF token and RESTful setup; with JSON as format] Thanks for all suggestions, Alec Taylor BTW: Also posted this on stackoverflow - http://stackoverflow.com/q/15513907 PS: I currently use the web2py framework; but this is an important enough feature that I am willing to switch to ANY other Python web-framework? From dreamingforward at gmail.com Wed Mar 20 00:46:32 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 19 Mar 2013 21:46:32 -0700 Subject: OOPv2: [Was: Message passing syntax for objects] Message-ID: Hopefully this won't be considered mail spam, but another quora answer that gets to the idea I'm after: http://qr.ae/TMh7A Reposted here for those who don't have accounts: Q. Is it time for us to dump the OOP paradigm? If yes, what can replace it? When I was using C++ and Java, more of my time was spent fitting the problem to languages' OO paradigm than actually solving the problem. When I used Python, I found I was focusing on the problem more compared to other languages, but still that fitting aspect remained. I am looking for a language design perspective answer, where we can compare logic programming, functional, etc approaches and really see if the OOP still fits/necessary and do we need to evolve towards a better paradigm. A. Yes. OOP was the evolution of applying abstraction to a programming language, to the machine, having to remember that we used to deal very concretely with switches and bits. Looking back, it can be seen to having gone too far. We don't need objects. Programmers don't model physical things within the computer, except in the limited domain of (generally game) simulation. It misinformed the paradigm in the wrong direction as many people found when programmers started making vast hierarchies of objects to try to categorize reality (Suburu inherits from Car inherits from Vehicle inherits from.....). So we went the wrong direction. What's to replace it? There was an interesting discussion on comp.lang.python started in 2004 by Mark Hahn about prototypes. (See: Google Groups and Google Groups). I think somehow it captures the idea pretty well. Prototypes are a refactoring of all the explorations that OOP made, taking us back to our roots. From the high-level abstraction of "objects" in the computer, back to the simple, understandable (C) structs and then encoding a way to shape or "template" data into a form that can take on abstract qualities which can then be used in a very general way. The key difference? You're not way up in abstraction-land attempting to impose your personal taxonomy into the machine; instead, you're working from the common-ground of the machine and co-ordinating a object/data space into existence where other programmers can actually use them. In other words, you're advancing the state-of-the-art of data structuring instead of applying some conceptual, hyper-personal abstraction into your code and onto the machine. The result? Programmers can start making very simple, loosely-coupled, universal types and build upwards with other programmers into more and more complex, re-usable "mashups". This will create modularity, agility, and facilitate the evolution of a "universal programming space" as well as create the Open Source Culture that the Internet needs to re-start itself. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Mar 20 01:39:58 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 19 Mar 2013 22:39:58 -0700 Subject: OOPv2: [Was: Message passing syntax for objects] In-Reply-To: References: Message-ID: On Tue, Mar 19, 2013 at 9:46 PM, Mark Janssen wrote: > Hopefully this won't be considered mail spam, but another quora answer that > gets to the idea I'm after: http://qr.ae/TMh7A > > Reposted here for those who don't have accounts: > > Q. Is it time for us to dump the OOP paradigm? If yes, what can replace it? > > When I was using C++ and Java, more of my time was spent fitting the problem > to languages' OO paradigm than actually solving the problem. > When I used Python, I found I was focusing on the problem more compared to > other languages, but still that fitting aspect remained. > > I am looking for a language design perspective answer, where we can compare > logic programming, functional, etc approaches and really see if the OOP > still fits/necessary and do we need to evolve towards a better paradigm. > > > > A. Yes. OOP was the evolution of applying abstraction to a programming > language, to the machine, having to remember that we used to deal very > concretely with switches and bits. Looking back, it can be seen to having > gone too far. > > We don't need objects. Programmers don't model physical things within the > computer, except in the limited domain of (generally game) simulation. It > misinformed the paradigm in the wrong direction as many people found when > programmers started making vast hierarchies of objects to try to categorize > reality (Suburu inherits from Car inherits from Vehicle inherits from.....). > So we went the wrong direction. > > What's to replace it? > > There was an interesting discussion on comp.lang.python started in 2004 by > Mark Hahn about prototypes. (See: Google Groups and Google Groups). I > think somehow it captures the idea pretty well. (Actual links to the referenced discussion(s) would be appreciated.) > Prototypes are a refactoring of all the explorations that OOP made, taking > us back to our roots. From the high-level abstraction of "objects" in the > computer, back to the simple, understandable (C) structs and then encoding a > way to shape or "template" data into a form that can take on abstract > qualities which can then be used in a very general way. The key difference? > You're not way up in abstraction-land attempting to impose your personal > taxonomy into the machine; instead, you're working from the common-ground of > the machine and co-ordinating a object/data space into existence where other > programmers can actually use them. In other words, you're advancing the > state-of-the-art of data structuring instead of applying some conceptual, > hyper-personal abstraction into your code and onto the machine. > > The result? Programmers can start making very simple, loosely-coupled, > universal types and build upwards with other programmers into more and more > complex, re-usable "mashups". > > This will create modularity, agility, and facilitate the evolution of a > "universal programming space" as well as create the Open Source Culture that > the Internet needs to re-start itself. What a crock. Prototype-based languages are a somewhat interesting alternative model, but IMO they are nowhere near as "game-changing" as the post suggests. The elimination of classes simplifies the MOP/metamodel a bit, but AFAICT doesn't improve much otherwise. If prototypes were so revolutionary, they would presumably be faring better in the marketplace of ideas (its promoters have been at it since about as long as Python's have, apparently with less luck). If you need evidence, look at JavaScript. It is, for better or worse, among the most popular languages of our time and it is prototype-based, but virtually no one chooses to make use of its prototypical nature; almost all projects seem to end up consciously re-implementing an approximation of traditional classes on top of the prototype system (using one of several techniques, there seeming to be no widespread agreement about which one is superior). Even prior to JavaScript, in orthodox prototype-based languages, there is/was even a concept of "traits" objects, which basically play much the same role as classes in traditional OOP. Also, I cannot for the life of me figure out how you made the abrupt leap from message-passing to prototype-based OOP. I echo Mark Lawrence's comment from your previous thread. +1 best trolling so far this millennium. Have fun with your architecture astronautics. Regards, Chris From n.bhavitha at gmail.com Wed Mar 20 05:40:16 2013 From: n.bhavitha at gmail.com (Bhavitha Nagaraju) Date: Wed, 20 Mar 2013 15:10:16 +0530 Subject: link is unavailable http://mail.python.org/mailman/listinfo/python-list Message-ID: Hi all, The link for sendkeys, which is a pre-requiste for winGuipython is unavailable. http://mail.python.org/mailman/listinfo/python-list. Could you suggest , where I could get the sendKeys for now? Thanking in advance. Bhavitha -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Wed Mar 20 06:10:33 2013 From: davea at davea.name (Dave Angel) Date: Wed, 20 Mar 2013 06:10:33 -0400 Subject: link is unavailable http://mail.python.org/mailman/listinfo/python-list In-Reply-To: References: Message-ID: <51498B19.5060209@davea.name> On 03/20/2013 05:40 AM, Bhavitha Nagaraju wrote: > Hi all, > > > > The link for sendkeys, which is a pre-requiste for winGuipython is > unavailable. http://mail.python.org/mailman/listinfo/python-list. Could you > suggest , where I could get the sendKeys for now? > > > Looks like you pasted the wrong link into your message. That one is for the mailing list we're using here. For sendkeys, you could use: http://pypi.python.org/pypi/SendKeys http://www.rutherfurd.net/python/sendkeys/ broken-link https://bitbucket.org/orutherfurd/sendkeys not broken https://bitbucket.org/markm/sendkeysctypes re-implemented without any C compiling needed I don't run Windows, so I couldn't actually check any of these out, but at least this gives you some more links to try. -- DaveA From nh.jones01 at gmail.com Wed Mar 20 08:52:40 2013 From: nh.jones01 at gmail.com (Norah Jones) Date: Wed, 20 Mar 2013 12:52:40 +0000 Subject: Multiple rows from MySQL query saved in an array structure Message-ID: I have this Python code: self.lock_tables("read", ['nets_permissions as n', 'devices_permissions as d']) usrs = self.db.get("SELECT n.user_id FROM nets_permissions as n \ left join devices_permissions as d \ on n.user_id = d.user_id \ where d.user_id is null \ and n.network_id=%s and n.perm3", netid) self.unlock_tables() for usr in usrs: self.lock_tables("write", ['devices_permissions']) self.db.execute("INSERT devices_permissions SET \ user_id=%s, network_id=%s, device_id=%s, perm=%s",\ usr, netid, sensid, perm) self.unlock_tables(); I first do a query to retrieve some user_id from two tables. I want save this user_id in one variable and after do a for loop to insert this records in another table... This code doesn't work. I obtain this error: Exception: Multiple rows returned for Database.get() query How can I retrieve this multiple rows and then process everyone of them at one time? -------------- next part -------------- An HTML attachment was scrubbed... URL: From melo.dumoulin at hotmail.com Wed Mar 20 09:33:42 2013 From: melo.dumoulin at hotmail.com (franzferdinand) Date: Wed, 20 Mar 2013 06:33:42 -0700 (PDT) Subject: "monty" < "python" Message-ID: >>> "Monty" < "Python" True >>> "Z" < "a" True >>> "Monty" < "Montague" False What's the rule about that? Is it the number of letters or what? thanks From jan at codein.is Wed Mar 20 09:38:23 2013 From: jan at codein.is (Jan Oelze) Date: Wed, 20 Mar 2013 14:38:23 +0100 Subject: "monty" < "python" In-Reply-To: References: Message-ID: <3CF84D67-668E-46C7-908D-A81D41021299@codein.is> From the docs[0]: "Strings are compared lexicographically using the numeric equivalents (the result of the built-in function ord()) of their characters. Unicode and 8-bit strings are fully interoperable in this behavior." [0] http://docs.python.org/2/reference/expressions.html#not-in On 20.03.2013, at 14:33, franzferdinand wrote: >>>> "Monty" < "Python" > True >>>> "Z" < "a" > True >>>> "Monty" < "Montague" > > False > What's the rule about that? Is it the number of letters or what? > thanks > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at feete.org Wed Mar 20 10:17:13 2013 From: ian at feete.org (Ian Foote) Date: Wed, 20 Mar 2013 14:17:13 +0000 Subject: "monty" < "python" In-Reply-To: <3CF84D67-668E-46C7-908D-A81D41021299@codein.is> References: <3CF84D67-668E-46C7-908D-A81D41021299@codein.is> Message-ID: <5149C4E9.9090009@feete.org> On 20/03/13 13:38, Jan Oelze wrote: > "Strings are compared lexicographically using the numeric equivalents > (the result of the built-in function ord()) of their characters. Unicode > and 8-bit strings are fully interoperable in this behavior." This isn't true in python 3: Python 3.2.3 (default, Oct 19 2012, 19:53:57) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> b'bytes' < 'unicode' Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: bytes() < str() Ian F From jan at codein.is Wed Mar 20 10:23:32 2013 From: jan at codein.is (Jan Oelze) Date: Wed, 20 Mar 2013 15:23:32 +0100 Subject: "monty" < "python" In-Reply-To: <5149C4E9.9090009@feete.org> References: <3CF84D67-668E-46C7-908D-A81D41021299@codein.is> <5149C4E9.9090009@feete.org> Message-ID: <4742E591-166D-4C78-AA8C-05F88D1CCB66@codein.is> Interesting. Thanks! On 20.03.2013, at 15:17, Ian Foote wrote: > On 20/03/13 13:38, Jan Oelze wrote: > >> "Strings are compared lexicographically using the numeric equivalents >> (the result of the built-in function ord()) of their characters. Unicode >> and 8-bit strings are fully interoperable in this behavior." > > This isn't true in python 3: > > Python 3.2.3 (default, Oct 19 2012, 19:53:57) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> b'bytes' < 'unicode' > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: bytes() < str() > > Ian F > -- > http://mail.python.org/mailman/listinfo/python-list From michael.weylandt at gmail.com Wed Mar 20 09:40:52 2013 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Wed, 20 Mar 2013 13:40:52 +0000 Subject: "monty" < "python" In-Reply-To: References: Message-ID: It's lexigraphic (order by first letter, but if those are the same, compare the second, but if those are same compare the third, ... if one ends while the other continues, it's considered 'lower') on the character's ASCII (binary encoding values): http://www.asciitable.com/ Note that all the upper case values appear before the lower case values. (And there are some other 'characters' like newline before that but you won't see them) Cheers, Michael On Wed, Mar 20, 2013 at 1:33 PM, franzferdinand wrote: >>>> "Monty" < "Python" > True >>>> "Z" < "a" > True >>>> "Monty" < "Montague" > > False > What's the rule about that? Is it the number of letters or what? > thanks > -- > http://mail.python.org/mailman/listinfo/python-list From roy at panix.com Wed Mar 20 09:58:34 2013 From: roy at panix.com (Roy Smith) Date: Wed, 20 Mar 2013 09:58:34 -0400 Subject: "monty" < "python" References: Message-ID: In article , Jan Oelze wrote: > From the docs[0]: > > "Strings are compared lexicographically using the numeric equivalents (the > result of the built-in function ord()) of their characters. Unicode and 8-bit > strings are fully interoperable in this behavior." Note, however, that sorting order is a really complicated subject. Different languages have all sorts of rules for how to alphabetize entries in a directory or dictionary. Does N sort the same as N? Does E sort the same as E? What about C and C? Are these pairs all the same letter, one of which is decorated with some mark, or are they different letters? If you're worried about these sorts of things, you need to be looking at the locale module. From melo.dumoulin at hotmail.com Wed Mar 20 10:03:20 2013 From: melo.dumoulin at hotmail.com (franzferdinand) Date: Wed, 20 Mar 2013 07:03:20 -0700 (PDT) Subject: "monty" < "python" References: Message-ID: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Ok, thanks everybody! From tjreedy at udel.edu Thu Mar 21 04:08:03 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Mar 2013 04:08:03 -0400 Subject: "monty" < "python" In-Reply-To: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> References: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Message-ID: On 3/20/2013 10:03 AM, franzferdinand wrote: > Ok, thanks everybody! Threads are like the Sorcerer's Apprentice. You can start 'em, but you cannot stop 'em ;-) -- Terry Jan Reedy From roy at panix.com Thu Mar 21 08:45:59 2013 From: roy at panix.com (Roy Smith) Date: Thu, 21 Mar 2013 08:45:59 -0400 Subject: "monty" < "python" References: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > On 3/20/2013 10:03 AM, franzferdinand wrote: > > Ok, thanks everybody! > > Threads are like the Sorcerer's Apprentice. You can start 'em, but you > cannot stop 'em ;-) Of course you can stop threads. Just call _exit(). No more threads! From rosuav at gmail.com Thu Mar 21 08:55:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Mar 2013 23:55:09 +1100 Subject: "monty" < "python" In-Reply-To: References: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Message-ID: On Thu, Mar 21, 2013 at 11:45 PM, Roy Smith wrote: > In article , > Terry Reedy wrote: > >> On 3/20/2013 10:03 AM, franzferdinand wrote: >> > Ok, thanks everybody! >> >> Threads are like the Sorcerer's Apprentice. You can start 'em, but you >> cannot stop 'em ;-) > > Of course you can stop threads. Just call _exit(). No more threads! I don't think Mickey Mouse knew about that call, otherwise he'd have used it. Either that, or he had a completely saturated system and couldn't type anything at the console, so it took the wizard's SSH session to deal with the problem using "kill -9". ChrisA From davea at davea.name Thu Mar 21 09:02:51 2013 From: davea at davea.name (Dave Angel) Date: Thu, 21 Mar 2013 09:02:51 -0400 Subject: "monty" < "python" In-Reply-To: References: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Message-ID: <514B04FB.4030006@davea.name> On 03/21/2013 08:55 AM, Chris Angelico wrote: > On Thu, Mar 21, 2013 at 11:45 PM, Roy Smith wrote: >> In article , >> Terry Reedy wrote: >> >>> On 3/20/2013 10:03 AM, franzferdinand wrote: >>>> Ok, thanks everybody! >>> >>> Threads are like the Sorcerer's Apprentice. You can start 'em, but you >>> cannot stop 'em ;-) >> >> Of course you can stop threads. Just call _exit(). No more threads! > > I don't think Mickey Mouse knew about that call, otherwise he'd have > used it. Either that, or he had a completely saturated system and > couldn't type anything at the console, so it took the wizard's SSH > session to deal with the problem using "kill -9". > Denial-of-service, the traditional way. -- DaveA From wayne at waynewerner.com Thu Mar 21 08:56:18 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 21 Mar 2013 07:56:18 -0500 (CDT) Subject: "monty" < "python" In-Reply-To: References: <950edea7-f778-4c9f-bbbb-6d050030acfe@g8g2000vbf.googlegroups.com> Message-ID: On Thu, 21 Mar 2013, Roy Smith wrote: > In article , > Terry Reedy wrote: > >> On 3/20/2013 10:03 AM, franzferdinand wrote: >>> Ok, thanks everybody! >> >> Threads are like the Sorcerer's Apprentice. You can start 'em, but you >> cannot stop 'em ;-) > > Of course you can stop threads. Just call _exit(). No more threads! Thank you for making me laugh this morning - I found that extremely amusing. -W From invalid at invalid.invalid Wed Mar 20 12:04:28 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 20 Mar 2013 16:04:28 +0000 (UTC) Subject: "monty" < "python" References: Message-ID: On 2013-03-20, franzferdinand wrote: >>>> "Monty" < "Python" > True >>>> "Z" < "a" > True >>>> "Monty" < "Montague" > > False > What's the rule about that? I don't know what "that" refers to in your question, but 'a' comes before 'y' if that's what you're asking. > Is it the number of letters or what? Individual letters are compared until a mismatch is found. -- Grant Edwards grant.b.edwards Yow! You were s'posed at to laugh! gmail.com From wxjmfauth at gmail.com Wed Mar 20 15:40:57 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 20 Mar 2013 12:40:57 -0700 (PDT) Subject: "monty" < "python" References: Message-ID: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> ---- Courageous people can try to do something with the unicode collation algorithm (see unicode.org). Some time ago, for the fun, I wrote something (not perfect) with a reduced keys table (see unicode.org), only a keys subset for some scripts hold in memory. It works with Py32 and Py33. In an attempt to just see the performance and how it "can react", I did an horrible mistake, I forgot Py33 is now optimized for ascii user, it is no more unicode compliant and I stupidely tested/sorted lists of French words... jmf From tim.delaney at aptare.com Wed Mar 20 17:02:53 2013 From: tim.delaney at aptare.com (Tim Delaney) Date: Thu, 21 Mar 2013 08:02:53 +1100 Subject: "monty" < "python" In-Reply-To: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: On 21 March 2013 06:40, jmfauth wrote: > ---- > [snip usual rant from jmf] Franz, please pay no attention to jmf. He has become obsessed with a single small regression in Python 3.3 in performance with how strings perform in a very small domain that rarely shows up in practice (although as he has demonstrated, it is easy to create a microbenchmark that makes it appear to be much worse than it is). The regression is a consequence of the decision in Python 3.3 to *correctly* support the full range of Unicode characters whilst also reducing the required memory where possible. In the vast majority of cases this is a performance *improvement*. It is only "optimised for the ascii user" in the sense that in the Unicode standard the pre-existing ASCII characters only require 1 byte per code point and hence can be stored in less memory than most other Unicode code points. The possible character widths are 1, 2 and 4 bytes. The actual regression occurs when concatentating/replacing/etc a character to a string that is wider than any other character currently in the string. In this situation the new string needs to be widened (increase the number of bytes used by every character) which is a much more expensive operation than simply creating a new string (which is what would happen if the character was the same size or smaller). It has been acknowledged as a real regression, but he keeps hijacking every thread where strings are mentioned to harp on about it. He has shown no inclination to attempt to *fix* the regression and is rapidly coming to be regarded as a troll by most participants in this list. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Wed Mar 20 21:41:19 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 Mar 2013 19:41:19 -0600 Subject: "monty" < "python" In-Reply-To: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: <514A653F.3090509@gmail.com> On 03/20/2013 01:40 PM, jmfauth wrote: > I forgot Py33 is now optimized for ascii user, it is no more > unicode compliant and I stupidely tested/sorted lists of French > words... Just because you keep saying it does not make it true. How is Py33 not unicode compliant anymore? And maybe you ought to post some real code too. (not like you've posted to date with the little one-liners that aren't actually used in practice.) From steve+comp.lang.python at pearwood.info Wed Mar 20 22:52:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2013 02:52:04 GMT Subject: "monty" < "python" References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: <514a75d3$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Mar 2013 12:40:57 -0700, jmfauth wrote: > it [Python3.3] is no more unicode compliant I don't often call people a liar. I prefer to think that they are merely confused, or honestly hold a mistaken belief. But in this case, I will make an exception. JMF, I believe you are deliberately, maliciously lying about Python, to further what I believe is your irrational hatred of ASCII users and your desire to punish them with poor performance, even when that affects *everybody*. -- Steven From rustompmody at gmail.com Wed Mar 20 23:12:13 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 20 Mar 2013 20:12:13 -0700 (PDT) Subject: "monty" < "python" References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: On Mar 21, 12:40?am, jmfauth wrote: > ---- > > Courageous people can try to do something with the unicode > collation algorithm (see unicode.org). Some time ago, for the fun, > I wrote something (not perfect) with a reduced keys table (see > unicode.org), only a keys subset for some scripts hold in memory. > > It works with Py32 and Py33. In an attempt to just see the > performance and how it "can react", I did an horrible mistake, > I forgot Py33 is now optimized for ascii user, it is no more > unicode compliant and I stupidely tested/sorted lists of French > words... Now lets take this piece by piece? "I did an horrible mistake" : I am sorry. Did you get bruised? Break some bones? And is 'h' a vowel in french? "I forgot Py33 is now optimized for ascii user" Ok. "it is no more unicode compliant" I asked earlier and I ask again -- What do you mean by (non)compliant? From steve+comp.lang.python at pearwood.info Thu Mar 21 00:28:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2013 04:28:15 GMT Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Mar 2013 20:12:13 -0700, rusi wrote: > "I did an horrible mistake" [...] is 'h' a vowel in french? No it is not, and writing "an horrible" is a trivial typo which can easily happen if you start thinking "an awful ..." (for example) and then change to "horrible". Been there, done that. But more interesting is the idea that in English we use "an" before words that start with a vowel, and "a" with words that start with a consonant: a tiger a car a house but an elephant an ambulance an unit Wait, what? "An unit"? What rubbish is that? The rule actually depends on the *sound* of the first syllable, not the letter. If the first syllable is a consonant sound, we say and write "a", even if the first letter is a vowel: a unique opportunity since the U in "unique" is pronounced as a "Yoo" sound rather than "Ah" sound. Likewise if the first consonant is silent, we use "an": an honourable man half an hour Now think of somebody who pronounces horrible with a silent "h". In English, an initial H used to *always* be silent, nowadays only some such words are. It's more common in dialect though. "I made a 'orrible mistake in getting a 'Arry Potter tattoo on my forehead." "I made an 'orrible mistake in getting an 'Arry Potter tattoo on my forehead." Say each sentence aloud. The second sounds far more natural, the "n" in "an" creates a bridge between the vowel sounds of "a" and "orrible". By the way, the "n" in "an" is not the only such "bridging" sound. In Shakespearean times, it was usual to use "mine" in the same fashion: my wife my peach but mine husband mine apple This-language-lesson-was-brought-to-you-by-the-letters-thorn-wynn-and-ash- ly y'rs, -- Steven From orgnut at yahoo.com Thu Mar 21 02:26:43 2013 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 20 Mar 2013 23:26:43 -0700 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/20/2013 09:28 PM, Steven D'Aprano wrote: > On Wed, 20 Mar 2013 20:12:13 -0700, rusi wrote: > >> "I did an horrible mistake" [...] is 'h' a vowel in french? > > > This-language-lesson-was-brought-to-you-by-the-letters-thorn-wynn-and-ash- > ly y'rs, > As a point of totally irrelevant trivia... (And I am going strictly from memory of hearing this, so I can't cite any references to confirm it, but anyway my memory says...) The word "apron" was originally "napron", and over the years the phrase "a napron" mutated to "an apron". So that became the accepted word. -=- Larry -=- From dhwild at talktalk.net Thu Mar 21 05:36:20 2013 From: dhwild at talktalk.net (David H Wild) Date: Thu, 21 Mar 2013 09:36:20 +0000 (GMT) Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <532fd4741ddhwild@talktalk.net> In article , Larry Hudson wrote: > The word "apron" was originally "napron", and over the years the phrase > "a napron" mutated to "an apron". So that became the accepted word. Similarly, the snake was a nadder - congruent with the natterjack toad. -- David Wild using RISC OS on broadband www.davidhwild.me.uk From rosuav at gmail.com Thu Mar 21 06:09:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Mar 2013 21:09:52 +1100 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: <532fd4741ddhwild@talktalk.net> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> <532fd4741ddhwild@talktalk.net> Message-ID: On Thu, Mar 21, 2013 at 8:36 PM, David H Wild wrote: > In article , Larry Hudson > wrote: >> The word "apron" was originally "napron", and over the years the phrase >> "a napron" mutated to "an apron". So that became the accepted word. > > Similarly, the snake was a nadder - congruent with the natterjack toad. Hey look, snakes, we're back on topic! ChrisA From istjanichtzufassen at gmail.com Thu Mar 21 09:26:29 2013 From: istjanichtzufassen at gmail.com (istjanichtzufassen at gmail.com) Date: Thu, 21 Mar 2013 06:26:29 -0700 (PDT) Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: <532fd4741ddhwild@talktalk.net> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> <532fd4741ddhwild@talktalk.net> Message-ID: <28cc7e8d-a9e8-43a0-9305-4861d397ea6b@googlegroups.com> Am Donnerstag, 21. M?rz 2013 10:36:20 UTC+1 schrieb David H Wild: > In article , Larry Hudson > > wrote: > > > The word "apron" was originally "napron", and over the years the phrase > > > "a napron" mutated to "an apron". So that became the accepted word. > > > > Similarly, the snake was a nadder - congruent with the natterjack toad. > And conversely, the "nickname" once was "an ekename", meaning an additional name. From rosuav at gmail.com Thu Mar 21 09:38:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2013 00:38:12 +1100 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: <28cc7e8d-a9e8-43a0-9305-4861d397ea6b@googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> <532fd4741ddhwild@talktalk.net> <28cc7e8d-a9e8-43a0-9305-4861d397ea6b@googlegroups.com> Message-ID: On Fri, Mar 22, 2013 at 12:26 AM, wrote: > Am Donnerstag, 21. M?rz 2013 10:36:20 UTC+1 schrieb David H Wild: >> In article , Larry Hudson >> >> wrote: >> >> > The word "apron" was originally "napron", and over the years the phrase >> >> > "a napron" mutated to "an apron". So that became the accepted word. >> >> Similarly, the snake was a nadder - congruent with the natterjack toad. >> > > And conversely, the "nickname" once was "an ekename", meaning an additional name. Until Eccles came along. Most people call him by his nickname, which is "Nick". ChrisA From ppearson at nowhere.invalid Thu Mar 21 17:52:37 2013 From: ppearson at nowhere.invalid (Peter Pearson) Date: 21 Mar 2013 21:52:37 GMT Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> <532fd4741ddhwild@talktalk.net> Message-ID: On Thu, 21 Mar 2013 21:09:52 +1100, Chris Angelico wrote: > On Thu, Mar 21, 2013 at 8:36 PM, David H Wild wrote: >> In article , Larry Hudson >> wrote: >>> The word "apron" was originally "napron", and over the years the phrase >>> "a napron" mutated to "an apron". So that became the accepted word. >> >> Similarly, the snake was a nadder - congruent with the natterjack toad. > > Hey look, snakes, we're back on topic! Ha! Great shot, Chris A. People who enjoy this sort of linguistic diversion would very likely enjoy John McWhorter's classes from the Teaching Company, which is where I first encountered many of the examples given in this thread. -- To email me, substitute nowhere->spamcop, invalid->net. From rosuav at gmail.com Thu Mar 21 17:59:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2013 08:59:46 +1100 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> <532fd4741ddhwild@talktalk.net> Message-ID: On Fri, Mar 22, 2013 at 8:52 AM, Peter Pearson wrote: > On Thu, 21 Mar 2013 21:09:52 +1100, Chris Angelico wrote: >> On Thu, Mar 21, 2013 at 8:36 PM, David H Wild wrote: >>> In article , Larry Hudson >>> wrote: >>>> The word "apron" was originally "napron", and over the years the phrase >>>> "a napron" mutated to "an apron". So that became the accepted word. >>> >>> Similarly, the snake was a nadder - congruent with the natterjack toad. >> >> Hey look, snakes, we're back on topic! > > Ha! Great shot, Chris A. > > People who enjoy this sort of linguistic diversion would > very likely enjoy John McWhorter's classes from the Teaching > Company, which is where I first encountered many of the examples > given in this thread. I love a good grammar discussion. Programming requires precise use of some language, so programmers tend to appreciate precise use of other languages too. Plus, in one of my other lives, I'm a D&D Dungeon Master with a reputation for puns and wordplay in my descriptions... though I'm as often slapped as clapped for them. ChrisA From invalid at invalid.invalid Thu Mar 21 13:31:32 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 21 Mar 2013 17:31:32 +0000 (UTC) Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-03-21, Steven D'Aprano wrote: > By the way, the "n" in "an" is not the only such "bridging" sound. In > Shakespearean times, it was usual to use "mine" in the same fashion: In many (most?) modern, non-rhotic, dialects of English one inserts an "intrusive" bridging "R" sound after a word that ends in certain vowel sounds and is followed by a word starting with a vowel. That description is a bit hard to "picture", but if you read the examples in the link below, you'll recogize it immediately: http://en.wikipedia.org/wiki/Linking_and_intrusive_R#Linking_R However, this only affects spoken English -- not written English. Is the Python language rhotic or non-rhotic? -- Grant Edwards grant.b.edwards Yow! Hello, GORRY-O!! at I'm a GENIUS from HARVARD!! gmail.com From tjreedy at udel.edu Thu Mar 21 19:05:33 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Mar 2013 19:05:33 -0400 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/21/2013 1:31 PM, Grant Edwards wrote: http://en.wikipedia.org/wiki/Linking_and_intrusive_R > Is the Python language rhotic or non-rhotic? Python uses American rather that British English, which would make it rhotic. I never imagined that there were people who would mix up 'tuner' and 'tuna'. Live and learn. -- Terry Jan Reedy From stefan_ml at behnel.de Sun Mar 24 10:25:56 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 24 Mar 2013 15:25:56 +0100 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Terry Reedy, 22.03.2013 00:05: > I never imagined that there were people who would mix up 'tuner' and > 'tuna'. Live and learn. I assume you know "The Chaos" ? http://ncf.idallen.com/english.html Stefan From breamoreboy at yahoo.co.uk Sun Mar 24 12:12:54 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Mar 2013 16:12:54 +0000 Subject: Vowels [was Re: "monty" < "python"] In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/03/2013 14:25, Stefan Behnel wrote: > Terry Reedy, 22.03.2013 00:05: >> I never imagined that there were people who would mix up 'tuner' and >> 'tuna'. Live and learn. > > I assume you know "The Chaos" ? > > http://ncf.idallen.com/english.html > > Stefan > > For many years I've felt it was wrong that people apologised for their poor English. Having read the above link I feel compelled to state, please do not apologise for your poor English. -- Cheers. Mark Lawrence From rustompmody at gmail.com Sun Mar 24 11:04:04 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 24 Mar 2013 08:04:04 -0700 (PDT) Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7068f35b-4721-42a0-98c1-4c115e58292c@ou9g2000pbb.googlegroups.com> On Mar 24, 7:25?pm, Stefan Behnel wrote: > > I assume you know "The Chaos" ? > > http://ncf.idallen.com/english.html Ha! Sweet! (Or should I say suet?) From roy at panix.com Thu Mar 21 20:09:00 2013 From: roy at panix.com (Roy Smith) Date: Thu, 21 Mar 2013 20:09:00 -0400 Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Terry Reedy wrote: > On 3/21/2013 1:31 PM, Grant Edwards wrote: > > > http://en.wikipedia.org/wiki/Linking_and_intrusive_R > > > Is the Python language rhotic or non-rhotic? > > Python uses American rather that British English, which would make it > rhotic. > > I never imagined that there were people who would mix up 'tuner' and > 'tuna'. Live and learn. Remember, "You can tune a file system, but you can't tune a fish." From invalid at invalid.invalid Fri Mar 22 10:14:30 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 22 Mar 2013 14:14:30 +0000 (UTC) Subject: Vowels [was Re: "monty" < "python"] References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <514a8c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-03-21, Terry Reedy wrote: > On 3/21/2013 1:31 PM, Grant Edwards wrote: > > http://en.wikipedia.org/wiki/Linking_and_intrusive_R > >> Is the Python language rhotic or non-rhotic? > > Python uses American rather that British English, which would make it > rhotic. Well, there are parts of New England, New York and the Southeast that have historically been non-rhotic. > I never imagined that there were people who would mix up 'tuner' and > 'tuna'. Live and learn. -- Grant Edwards grant.b.edwards Yow! ... the HIGHWAY is at made out of LIME JELLO and gmail.com my HONDA is a barbequeued OYSTER! Yum! From wxjmfauth at gmail.com Sat Mar 23 05:23:21 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 23 Mar 2013 02:23:21 -0700 (PDT) Subject: "monty" < "python" References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> On 21 mar, 04:12, rusi wrote: > On Mar 21, 12:40?am, jmfauth wrote: > > > ---- > > > Courageous people can try to do something with the unicode > > collation algorithm (see unicode.org). Some time ago, for the fun, > > I wrote something (not perfect) with a reduced keys table (see > > unicode.org), only a keys subset for some scripts hold in memory. > > > It works with Py32 and Py33. In an attempt to just see the > > performance and how it "can react", I did an horrible mistake, > > I forgot Py33 is now optimized for ascii user, it is no more > > unicode compliant and I stupidely tested/sorted lists of French > > words... > > Now lets take this piece by piece? > "I did an horrible mistake" : I am sorry. Did you get bruised? Break > some bones? And is 'h' a vowel in french? > "I forgot Py33 is now optimized for ascii user" ?Ok. > "it is no more unicode compliant" I asked earlier and I ask again -- > What do you mean by (non)compliant? ------ One aspect of Unicode (note the capitalized "U"). py32 >>> timeit.repeat("'abc???'.find('a')") [0.27941279564856814, 0.26568106110789813, 0.265546366757917] >>> timeit.repeat("'abcdef'.find('a')") [0.2891812867801491, 0.26698153112010914, 0.26738994644529157] py33 timeit.repeat("'abc???'.find('a')") [0.5941777382531654, 0.5829193385634426, 0.5519412133990045] timeit.repeat("'abcdef'.find('a')") [0.44333188136533863, 0.4232506078969891, 0.4225164843046514] --- In French, depending of the word, a leading "h", behaves as a vowel or as a consonant. (From this -> this typical mistake) jmf From rosuav at gmail.com Sat Mar 23 05:45:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Mar 2013 20:45:01 +1100 Subject: "monty" < "python" In-Reply-To: <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 23, 2013 at 8:23 PM, jmfauth wrote: > One aspect of Unicode (note the capitalized "U"). > > [chomp yet another trivial microbenchmark] > > --- > > In French, depending of the word, a leading "h", behaves > as a vowel or as a consonant. > (From this -> this typical mistake) Huh? Did jmf and 88888 Dihedral just team up to make a post? ChrisA From rosuav at gmail.com Sat Mar 23 05:56:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Mar 2013 20:56:45 +1100 Subject: "monty" < "python" In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 23, 2013 at 8:45 PM, Chris Angelico wrote: > On Sat, Mar 23, 2013 at 8:23 PM, jmfauth wrote: >> One aspect of Unicode (note the capitalized "U"). >> >> [chomp yet another trivial microbenchmark] >> >> --- >> >> In French, depending of the word, a leading "h", behaves >> as a vowel or as a consonant. >> (From this -> this typical mistake) > > Huh? Did jmf and 88888 Dihedral just team up to make a post? Ohh. That's in relation to "an horrible mistake". Though I still don't see what the parenthesis is saying. Pity, that. A merger between jmf and Dihedral would have been mutually beneficial. I'm sure it would be approved by the regulatory authorities, too. ChrisA From breamoreboy at yahoo.co.uk Sat Mar 23 12:06:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 23 Mar 2013 16:06:23 +0000 Subject: "monty" < "python" In-Reply-To: <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <5241e68d-c4b8-4616-b0dd-4c5457dfe3b7@l16g2000yqe.googlegroups.com> Message-ID: On 23/03/2013 09:23, jmfauth wrote: > On 21 mar, 04:12, rusi wrote: >> On Mar 21, 12:40 am, jmfauth wrote: >> >>> ---- >> >>> Courageous people can try to do something with the unicode >>> collation algorithm (see unicode.org). Some time ago, for the fun, >>> I wrote something (not perfect) with a reduced keys table (see >>> unicode.org), only a keys subset for some scripts hold in memory. >> >>> It works with Py32 and Py33. In an attempt to just see the >>> performance and how it "can react", I did an horrible mistake, >>> I forgot Py33 is now optimized for ascii user, it is no more >>> unicode compliant and I stupidely tested/sorted lists of French >>> words... >> >> Now lets take this piece by piece? >> "I did an horrible mistake" : I am sorry. Did you get bruised? Break >> some bones? And is 'h' a vowel in french? >> "I forgot Py33 is now optimized for ascii user" Ok. >> "it is no more unicode compliant" I asked earlier and I ask again -- >> What do you mean by (non)compliant? > > ------ > > One aspect of Unicode (note the capitalized "U"). > > py32 >>>> timeit.repeat("'abc???'.find('a')") > [0.27941279564856814, 0.26568106110789813, 0.265546366757917] >>>> timeit.repeat("'abcdef'.find('a')") > [0.2891812867801491, 0.26698153112010914, 0.26738994644529157] > > py33 > timeit.repeat("'abc???'.find('a')") > [0.5941777382531654, 0.5829193385634426, 0.5519412133990045] > timeit.repeat("'abcdef'.find('a')") > [0.44333188136533863, 0.4232506078969891, 0.4225164843046514] > > jmf > Are you saying that to be compliant a unicode implementation has to perform within given time bounds? -- Cheers. Mark Lawrence From wxjmfauth at gmail.com Sat Mar 23 05:24:38 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 23 Mar 2013 02:24:38 -0700 (PDT) Subject: "monty" < "python" References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> Message-ID: <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> On 20 mar, 22:02, Tim Delaney wrote: > On 21 March 2013 06:40, jmfauth wrote: > > > ---- > > [snip usual rant from jmf] > > > It has been acknowledged as a real regression, but he keeps hijacking every > thread where strings are mentioned to harp on about it. He has shown no > inclination to attempt to *fix* the regression and is rapidly coming to be > regarded as a troll by most participants in this list. > --------- I can not help to fix it, because it is "unfixable". It is "unfixable", because this flexible string representation is wrong by design. jmf From breamoreboy at yahoo.co.uk Sat Mar 23 12:17:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 23 Mar 2013 16:17:51 +0000 Subject: "monty" < "python" In-Reply-To: <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> Message-ID: On 23/03/2013 09:24, jmfauth wrote: > On 20 mar, 22:02, Tim Delaney wrote: >> On 21 March 2013 06:40, jmfauth wrote: >> >>> ---- >>> [snip usual rant from jmf] >> > > >> >> It has been acknowledged as a real regression, but he keeps hijacking every >> thread where strings are mentioned to harp on about it. He has shown no >> inclination to attempt to *fix* the regression and is rapidly coming to be >> regarded as a troll by most participants in this list. >> > > --------- > > I can not help to fix it, because it is "unfixable". It > is "unfixable", because this flexible string representation > is wrong by design. > > jmf > Of course it's fixable. All you need do is write a PEP clearing stating what is wrong with the implementation detailed in PEP393 and your own proposed design. I'm looking forward to reading this PEP. Note that going backwards to buggier unicode implementations that existed in Python prior to version 3.3 is simply not an option. -- Cheers. Mark Lawrence From wxjmfauth at gmail.com Sun Mar 24 09:31:17 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 24 Mar 2013 06:31:17 -0700 (PDT) Subject: "monty" < "python" References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> Message-ID: On 23 mar, 17:17, Mark Lawrence wrote: > On 23/03/2013 09:24, jmfauth wrote: > > > > > > > > > > > On 20 mar, 22:02, Tim Delaney wrote: > >> On 21 March 2013 06:40, jmfauth wrote: > > >>> ---- > >>> [snip usual rant from jmf] > > >> It has been acknowledged as a real regression, but he keeps hijacking every > >> thread where strings are mentioned to harp on about it. He has shown no > >> inclination to attempt to *fix* the regression and is rapidly coming to be > >> regarded as a troll by most participants in this list. > > > --------- > > > I can not help to fix it, because it is "unfixable". It > > is "unfixable", because this flexible string representation > > is wrong by design. > > > jmf > > Of course it's fixable. ?All you need do is write a PEP clearing stating > what is wrong with the implementation detailed in PEP393 and your own > proposed design. ?I'm looking forward to reading this PEP. > > Note that going backwards to buggier unicode implementations that > existed in Python prior to version 3.3 is simply not an option. > > -- > Cheers. > > Mark Lawrence ------ The problem here is that this PEP 393 should not have been created. The first time I read it, I quickly understood, it can not work! This is illustrated by all the examples I give on this list. In all the cases, I can explain why. I never saw somebody beeing able to argue these examples are wrong and/or explaining why they are wrong, except arguing the flexible string representation exists! jmf From rosuav at gmail.com Sun Mar 24 09:44:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Mar 2013 00:44:31 +1100 Subject: "monty" < "python" In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> Message-ID: On Mon, Mar 25, 2013 at 12:31 AM, jmfauth wrote: > The problem here is that this PEP 393 should not have been > created. > The first time I read it, I quickly understood, it can > not work! I fail to understand how something can "not work" when it is clearly working, and very successfully too, in two different languages. All of your complaints have been on the basis of *timings*, which really means you're complaining about performance, not correctness. If you can show any evidence that something actually is not *working*, please do so (in a fresh thread, not in a hijacked one). ChrisA From breamoreboy at yahoo.co.uk Sun Mar 24 10:08:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Mar 2013 14:08:30 +0000 Subject: "monty" < "python" In-Reply-To: References: <987098b6-d79c-4597-b656-9b3e983740e8@z3g2000vbg.googlegroups.com> <56b80226-88d7-451c-bfd3-964def07a99d@9g2000yqy.googlegroups.com> Message-ID: On 24/03/2013 13:31, jmfauth wrote: > > The problem here is that this PEP 393 should not have been > created. > The first time I read it, I quickly understood, it can > not work! How come you couldn't pursuade the Python devs that PEP393 was so flawed? > > This is illustrated by all the examples I give on this list. > In all the cases, I can explain why. IIRC you've never said that the implementation doesn't work. You've repeatedly given micro benchmarks regarding performance and nothing else. > > I never saw somebody beeing able to argue these examples are > wrong and/or explaining why they are wrong, except arguing > the flexible string representation exists! Sheer unadultered crap. Was your education at the Dr Goebbels Institute? > > jmf > -- Cheers. Mark Lawrence From sendtomrg at gmail.com Wed Mar 20 09:52:24 2013 From: sendtomrg at gmail.com (M.gowtham M.gowtham) Date: Wed, 20 Mar 2013 06:52:24 -0700 (PDT) Subject: best .lang. python Message-ID: <6dc48c27-4993-457b-8b18-787c10b2d7fb@googlegroups.com> Any ideas on what to do? Stop attempting to negotiate. Contact your state insurance commission. Be prepared to divulge the name of your insurer. Keep detailed records of all your contacts. ----- - gpsman website--> http://www.win2job.info/ From melo.dumoulin at hotmail.com Wed Mar 20 10:05:04 2013 From: melo.dumoulin at hotmail.com (franzferdinand) Date: Wed, 20 Mar 2013 07:05:04 -0700 (PDT) Subject: join() Message-ID: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> I'm doing this "Write code that removes whitespace at the beginning and end of a string, and normalizes whitespace between words to be a single space character" I can do it using split() >>> raw = " the weather is sunny today " >>> raw.split() ['the', 'weather', 'is', 'sunny', 'today'] But how do I do it using join() ?? Thanks From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 20 10:34:55 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 20 Mar 2013 14:34:55 +0000 (UTC) Subject: join() References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> Message-ID: franzferdinand hotmail.com> writes: > > I'm doing this "Write code that removes whitespace at the beginning > and end of a string, and normalizes whitespace between words to be a > single space character" > > I can do it using split() > > >>> raw = " the weather is sunny today " > >>> raw.split() > ['the', 'weather', 'is', 'sunny', 'today'] > > But how do I do it using join() ?? Thanks > I guess you mean: how can I re-generate a string from my list of sub-strings, where each element is separated by only a single space. ' '.join(raw.split()) join is a string method that can take a list of strings to join as its argument. Best, Wolfgang From steve+comp.lang.python at pearwood.info Wed Mar 20 10:39:05 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2013 14:39:05 GMT Subject: join() References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> Message-ID: <5149ca09$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Mar 2013 07:05:04 -0700, franzferdinand wrote: > I'm doing this "Write code that removes whitespace at the beginning and > end of a string, and normalizes whitespace between words to be a single > space character" > > I can do it using split() > >>>> raw = " the weather is sunny today " >>>> raw.split() > ['the', 'weather', 'is', 'sunny', 'today'] > > But how do I do it using join() ?? Thanks First you split the string into a list of words, using the split method, just as you do above. Then you join the list of words back into a single string, using the joint method. Hint: "+".join(['the', 'quick', 'brown', 'fox']) => "the+quick+brown+fox" Does that give you enough of a hint? -- Steven From python.list at tim.thechases.com Wed Mar 20 11:54:22 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 20 Mar 2013 10:54:22 -0500 Subject: join() In-Reply-To: <5149ca09$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> <5149ca09$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130320105422.2ab4f318@bigbox.christie.dr> On 2013-03-20 14:39, Steven D'Aprano wrote: > Then you join the list of words back > into a single string, using the joint method. Sometimes when I see people make spelling errors, I wonder what they were smoking. Sometimes, it's more obvious... ;-) -tkc From steve+comp.lang.python at pearwood.info Wed Mar 20 14:44:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2013 18:44:42 GMT Subject: join() References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> <5149ca09$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514a0399$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Mar 2013 10:54:22 -0500, Tim Chase wrote: > On 2013-03-20 14:39, Steven D'Aprano wrote: >> Then you join the list of words back >> into a single string, using the joint method. > > Sometimes when I see people make spelling errors, I wonder what they > were smoking. Sometimes, it's more obvious... ;-) Oh please, I think it's quite cruel to make fun of me for making a perfectly innocent slip of the tongue here, when it's quite obvious I meant my mother. Sometimes-a-cigar-is-just-a-phallic-symbol-ly y'rs, -- Steven From breamoreboy at yahoo.co.uk Wed Mar 20 10:44:32 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 20 Mar 2013 14:44:32 +0000 Subject: join() In-Reply-To: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> Message-ID: On 20/03/2013 14:05, franzferdinand wrote: > I'm doing this "Write code that removes whitespace at the beginning > and end of a string, and normalizes whitespace between words to be a > single space character" > > I can do it using split() > >>>> raw = " the weather is sunny today " >>>> raw.split() > ['the', 'weather', 'is', 'sunny', 'today'] > > But how do I do it using join() ?? Thanks > ' '.join(raw.split()) -- Cheers. Mark Lawrence From melo.dumoulin at hotmail.com Wed Mar 20 10:46:15 2013 From: melo.dumoulin at hotmail.com (franzferdinand) Date: Wed, 20 Mar 2013 07:46:15 -0700 (PDT) Subject: join() References: <6110d82b-fce9-4146-8fcc-3276334a8f5f@14g2000vbr.googlegroups.com> Message-ID: <4c009df9-c047-4e05-85d3-fefeaebac978@z4g2000vbz.googlegroups.com> Yeah it works. Thank you everybody! From bartolome.sintes at gmail.com Wed Mar 20 10:17:08 2013 From: bartolome.sintes at gmail.com (bartolome.sintes at gmail.com) Date: Wed, 20 Mar 2013 07:17:08 -0700 (PDT) Subject: x += ... is not the same than x = x + ... if x is mutable Message-ID: Hi, I thought that x += ... was the same than x = x + ..., but today I have realized it is not true when operating with mutable objects. In Python 3.3 or 2.7 IDLE (Windows) compare: >>> a = [3] >>> b = a >>> a = a + [1] >>> b [3] and >>> a = [3] >>> b = a >>> a += [1] >>> b [3, 1] Is this behaviour explained in the Python documentation? Thanking you in advance, Bartolom? Sintes From jpiitula at ling.helsinki.fi Wed Mar 20 10:26:20 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 20 Mar 2013 16:26:20 +0200 Subject: x += ... is not the same than x = x + ... if x is mutable References: Message-ID: bartolome.sintes at gmail.com writes: > Hi, > > I thought that x += ... was the same than x = x + ..., but today I > have realized it is not true when operating with mutable objects. > > In Python 3.3 or 2.7 IDLE (Windows) compare: > >>> a = [3] > >>> b = a > >>> a = a + [1] > >>> b > [3] > > and > >>> a = [3] > >>> b = a > >>> a += [1] > >>> b > [3, 1] > > Is this behaviour explained in the Python documentation? Yes, it's documented in the language reference, specifically in the latter half of the paragraph quoted below. # An augmented assignment expression like x += 1 can be rewritten as x # = x + 1 to achieve a similar, but not exactly equal effect. In the # augmented version, x is only evaluated once. Also, when possible, # the actual operation is performed in-place, meaning that rather than # creating a new object and assigning that to the target, the old # object is modified instead. From nobody at nowhere.com Thu Mar 21 00:27:38 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 21 Mar 2013 04:27:38 +0000 Subject: x += ... is not the same than x = x + ... if x is mutable References: Message-ID: On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: > I thought that x += ... was the same than x = x + ..., but today I have > realized it is not true when operating with mutable objects. It may or may not be the same. x += y will invoke x.__iadd__(y) if x has an __iadd__ method, otherwise x + y will be evaluated and the result assigned to x. In the first case, x will always continue to refer to the same object (i.e. id(x) won't change). In the second case, x will typically (but not always) refer to a different object. From cjw at ncf.ca Thu Mar 21 08:35:26 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 21 Mar 2013 08:35:26 -0400 Subject: x += ... is not the same than x = x + ... if x is mutable In-Reply-To: References: Message-ID: On 21/03/2013 12:27 AM, Nobody wrote: > On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: > >> I thought that x += ... was the same than x = x + ..., but today I have >> realized it is not true when operating with mutable objects. > > It may or may not be the same. x += y will invoke x.__iadd__(y) if x has > an __iadd__ method, otherwise x + y will be evaluated and the result > assigned to x. > Does this depend on whether Py27 or Py32 is used? Colin W. > In the first case, x will always continue to refer to the same object > (i.e. id(x) won't change). In the second case, x will typically (but not > always) refer to a different object. > From steve+comp.lang.python at pearwood.info Thu Mar 21 08:39:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2013 12:39:04 GMT Subject: x += ... is not the same than x = x + ... if x is mutable References: Message-ID: <514aff68$0$30001$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Mar 2013 08:35:26 -0400, Colin J. Williams wrote: > On 21/03/2013 12:27 AM, Nobody wrote: >> On Wed, 20 Mar 2013 07:17:08 -0700, bartolome.sintes wrote: >> >>> I thought that x += ... was the same than x = x + ..., but today I >>> have realized it is not true when operating with mutable objects. >> >> It may or may not be the same. x += y will invoke x.__iadd__(y) if x >> has an __iadd__ method, otherwise x + y will be evaluated and the >> result assigned to x. >> > Does this depend on whether Py27 or Py32 is used? No. It is equally true for all versions of Python. -- Steven From wanderer at dialup4less.com Wed Mar 20 10:50:42 2013 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 20 Mar 2013 07:50:42 -0700 (PDT) Subject: Suppress PyDev warning for wx event variable Message-ID: I have two versions of Eclipse on two different machines; Indigo and Juno. In Indigo, the wxPython event variable in the definitions is not flagged as an unused variable even though I don't use it in the method. In Juno I keep getting the warnings. The event variable is just there to bind the method to the button event and I would like to suppress the warnings, but I can't figure out what I have set up differently between the two machines. I looked through the preferences but nothing jumps out at me. How do I suppress these warnings? Thanks From anadionisio257 at gmail.com Wed Mar 20 11:27:30 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Wed, 20 Mar 2013 08:27:30 -0700 (PDT) Subject: Lists and Decimal numbers Message-ID: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> So, I have this script that puts in a list every minute in 24 hours hour=[] i=0 t=-(1.0/60.0) while i<24*60: i = i+1 t = t+(1.0/60.0) hour.append([t]) When it is doing the cicle it can have all the decimal numbers, but I need to print the result with only 4 decimal numbers How can I define the number of decimal numbers I want to print in this case? For example with 4 decimal numbers, it would print: 0.0000 0.0167 0.0333 ... Can you help? From wanderer at dialup4less.com Wed Mar 20 11:48:20 2013 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 20 Mar 2013 08:48:20 -0700 (PDT) Subject: Lists and Decimal numbers In-Reply-To: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: <0180bf86-4d01-4840-9284-42cf4976b685@googlegroups.com> On Wednesday, March 20, 2013 11:27:30 AM UTC-4, Ana Dion?sio wrote: > So, I have this script that puts in a list every minute in 24 hours > > > > hour=[] > > i=0 > > t=-(1.0/60.0) > > while i<24*60: > > i = i+1 > > t = t+(1.0/60.0) > > hour.append([t]) > > > > When it is doing the cicle it can have all the decimal numbers, but I need to print the result with only 4 decimal numbers > > > > How can I define the number of decimal numbers I want to print in this case? For example with 4 decimal numbers, it would print: > > > > 0.0000 > > 0.0167 > > 0.0333 > > ... > > > > Can you help? You can use round. for t in hour: print round(t,4) From __peter__ at web.de Wed Mar 20 11:52:00 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Mar 2013 16:52 +0100 Subject: Lists and Decimal numbers References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: Ana Dion?sio wrote: > So, I have this script that puts in a list every minute in 24 hours > > hour=[] > i=0 > t=-(1.0/60.0) > while i<24*60: > i = i+1 > t = t+(1.0/60.0) > hour.append([t]) In many cases you can write for i in range(...): ... instead of incrementing manually. > When it is doing the cicle it can have all the decimal numbers, but I need > to print the result with only 4 decimal numbers > > How can I define the number of decimal numbers I want to print in this > case? For example with 4 decimal numbers, it would print: > > 0.0000 > 0.0167 > 0.0333 > ... > > Can you help? >>> for i in range(24*60): ... print "{:.4f}".format(i/60.0) ... 0.0000 0.0167 0.0333 0.0500 [...] 23.9500 23.9667 23.9833 >>> See also From alister.ware at ntlworld.com Wed Mar 20 15:20:57 2013 From: alister.ware at ntlworld.com (Alister) Date: Wed, 20 Mar 2013 19:20:57 GMT Subject: Lists and Decimal numbers References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: On Wed, 20 Mar 2013 16:52:00 +0100, Peter Otten wrote: > Ana Dion?sio wrote: > >> So, I have this script that puts in a list every minute in 24 hours >> >> hour=[] >> i=0 t=-(1.0/60.0) >> while i<24*60: >> i = i+1 t = t+(1.0/60.0) >> hour.append([t]) > > In many cases you can write > > for i in range(...): > ... > > instead of incrementing manually. > >> When it is doing the cicle it can have all the decimal numbers, but I >> need to print the result with only 4 decimal numbers >> >> How can I define the number of decimal numbers I want to print in this >> case? For example with 4 decimal numbers, it would print: >> >> 0.0000 0.0167 0.0333 ... >> >> Can you help? > > >>>> for i in range(24*60): > ... print "{:.4f}".format(i/60.0) > ... > 0.0000 0.0167 0.0333 0.0500 [...] > 23.9500 23.9667 23.9833 >>>> >>>> > See also > > and a list comprehension would streamline things further t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0) -- How many Zen Buddhist does it take to change a light bulb? Two. One to change it and one not to change it. From breamoreboy at yahoo.co.uk Wed Mar 20 15:53:53 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 20 Mar 2013 19:53:53 +0000 Subject: Lists and Decimal numbers In-Reply-To: References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: On 20/03/2013 19:20, Alister wrote: > On Wed, 20 Mar 2013 16:52:00 +0100, Peter Otten wrote: > >> Ana Dion?sio wrote: >> >>> So, I have this script that puts in a list every minute in 24 hours >>> >>> hour=[] >>> i=0 t=-(1.0/60.0) >>> while i<24*60: >>> i = i+1 t = t+(1.0/60.0) >>> hour.append([t]) >> >> In many cases you can write >> >> for i in range(...): >> ... >> >> instead of incrementing manually. >> >>> When it is doing the cicle it can have all the decimal numbers, but I >>> need to print the result with only 4 decimal numbers >>> >>> How can I define the number of decimal numbers I want to print in this >>> case? For example with 4 decimal numbers, it would print: >>> >>> 0.0000 0.0167 0.0333 ... >>> >>> Can you help? >> >> >>>>> for i in range(24*60): >> ... print "{:.4f}".format(i/60.0) >> ... >> 0.0000 0.0167 0.0333 0.0500 [...] >> 23.9500 23.9667 23.9833 >>>>> >>>>> >> See also >> >> language> > > > and a list comprehension would streamline things further > > t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0) > Really? c:\Users\Mark\Python>python Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0) File "", line 1 t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0) ^ SyntaxError: invalid syntax -- Cheers. Mark Lawrence From invalid at invalid.invalid Wed Mar 20 16:00:38 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 20 Mar 2013 20:00:38 +0000 (UTC) Subject: Lists and Decimal numbers References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: On 2013-03-20, Alister wrote: > and a list comprehension would streamline things further > > t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0) There's a typo in the above. It should be: t = [round((x*1.0/60),4) for x in range(1440)] -- Grant Edwards grant.b.edwards Yow! On the road, ZIPPY at is a pinhead without a gmail.com purpose, but never without a POINT. From alister.ware at ntlworld.com Wed Mar 20 16:47:28 2013 From: alister.ware at ntlworld.com (Alister) Date: Wed, 20 Mar 2013 20:47:28 GMT Subject: Lists and Decimal numbers References: <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> Message-ID: On Wed, 20 Mar 2013 20:00:38 +0000, Grant Edwards wrote: > On 2013-03-20, Alister wrote: > >> and a list comprehension would streamline things further >> >> t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & >> V3.0) > > There's a typo in the above. It should be: > > t = [round((x*1.0/60),4) for x in range(1440)] Indeed a typo Many thanks for correcting -- "MacDonald has the gift on compressing the largest amount of words into the smallest amount of thoughts." -- Winston Churchill From info at egenix.com Wed Mar 20 12:00:15 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 20 Mar 2013 17:00:15 +0100 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-10=2E04=2E201?= =?ISO-8859-1?Q?3?= Message-ID: <5149DD0F.9060308@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. Mittwoch, 10.04.2013, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden Bachstr. 145 40217 D?sseldorf WICHTIG: Neuer Veranstaltungsort ! Diese Nachricht k?nnen Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2013-04-10 ________________________________________________________________________ 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. 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, Mar 20 2013) >>> 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/ ________________________________________________________________________ 2013-03-13: Released eGenix pyOpenSSL 0.13 ... http://egenix.com/go39 ::::: 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 anadionisio257 at gmail.com Wed Mar 20 14:15:27 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Wed, 20 Mar 2013 11:15:27 -0700 (PDT) Subject: Test a list Message-ID: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> t= [3,5,6,7,10,14,17,21] Basically I want to print Test 1 when i is equal to an element of the list "t" and print Test 2 when i is not equal: while i<=25: if i==t[]: print "Test1" else: print "Test2" What is missing here for this script work? Thank you all From timothy.crosley at gmail.com Wed Mar 20 14:24:35 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Wed, 20 Mar 2013 11:24:35 -0700 (PDT) Subject: Test a list In-Reply-To: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> References: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> Message-ID: Hi Ana, if I understand your question correctly, all you have to do to test this is to write: if i in t: print "Test1" else: print "Test2" On Wednesday, March 20, 2013 2:15:27 PM UTC-4, Ana Dion?sio wrote: > t= [3,5,6,7,10,14,17,21] > > > > Basically I want to print Test 1 when i is equal to an element of the list "t" and print Test 2 when i is not equal: > > > > > > while i<=25: > > > > if i==t[]: > > > > print "Test1" > > > > else: > > > > print "Test2" > > > > What is missing here for this script work? > > > > Thank you all From joel.goldstick at gmail.com Wed Mar 20 14:26:42 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 20 Mar 2013 14:26:42 -0400 Subject: Test a list In-Reply-To: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> References: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> Message-ID: On Wed, Mar 20, 2013 at 2:15 PM, Ana Dion?sio wrote: > > t= [3,5,6,7,10,14,17,21] > > Basically I want to print Test 1 when i is equal to an element of the list > "t" and print Test 2 when i is not equal: > > > while i<=25: > You test i, but you don't set i to anything, or change it in your loop you may want to try for i in range(25) (or perhaps range(1,26) i'm guessing. Be more clear > > if i==t[]: > This isn't legal syntax. Try googling about for loops and sets. Try again and come back > > print "Test1" > > else: > > print "Test2" > > What is missing here for this script work? > > Thank you all > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Mar 20 14:36:01 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 20 Mar 2013 13:36:01 -0500 Subject: Test a list In-Reply-To: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> References: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> Message-ID: <20130320133601.0a67711f@bigbox.christie.dr> On 2013-03-20 11:15, Ana Dion?sio wrote: > t= [3,5,6,7,10,14,17,21] > > Basically I want to print Test 1 when i is equal to an element of > the list "t" and print Test 2 when i is not equal: > > while i<=25: > if i==t[]: > print "Test1" > else: > print "Test2" > > What is missing here for this script work? Well, your code never increments "i", so it will loop forever; you also don't subscript "t" with anything, so you have invalid syntax there; you also don't have any values in the list that actually match their 0-indexed offset, so even if your code was correct, it would still (correctly) return Test2 for everything. This sounds a bit like homework, but the Pythonic way would likely iterate over the data and its enumeration: for index, value in enumerate(t): if index == value: # compare index & value accordingly ... If you need to have the index start at 1 (or some other value) instead of 0, and you're running Python2.6+, you can pass the initial index to enumerate(). Otherwise, you have to do the math in your comparison. -tkc From steve+comp.lang.python at pearwood.info Wed Mar 20 14:40:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2013 18:40:36 GMT Subject: Test a list References: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> Message-ID: <514a02a4$0$30001$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Mar 2013 11:15:27 -0700, Ana Dion?sio wrote: > t= [3,5,6,7,10,14,17,21] > > Basically I want to print Test 1 when i is equal to an element of the > list "t" and print Test 2 when i is not equal: Wouldn't it make more sense to print "Equal" and "Not equal"? If all you want to do is check whether some value i can be found in the list, you can do this: if i in t: print "Found" else: print "Not found" If you want to find the index of where a value is found, use the index method: x = 10 t.index(x) # returns 4 > while i<=25: > if i==t[]: > print "Test1" > else: > print "Test2" > > What is missing here for this script work? Lots of things. What's i? Does it ever change, or is it a constant? What are you comparing it to? Taking a wild guess at what you mean, you could try this: for i in range(25): print i, "found" if i in t else "not found" Does this help? -- Steven From gordon at panix.com Wed Mar 20 16:39:15 2013 From: gordon at panix.com (John Gordon) Date: Wed, 20 Mar 2013 20:39:15 +0000 (UTC) Subject: Test a list References: <121be20a-c02a-4b0e-a86f-7c69597b9296@googlegroups.com> Message-ID: In <121be20a-c02a-4b0e-a86f-7c69597b9296 at googlegroups.com> =?ISO-8859-1?Q?Ana_Dion=EDsio?= writes: > t= [3,5,6,7,10,14,17,21] > Basically I want to print Test 1 when i is equal to an element of the > list "t" and print Test 2 when i is not equal: > while i<=25: > if i==t[]: > print "Test1" > else: > print "Test2" > What is missing here for this script work? 1. You're missing an initial value for i. 2. You never increment i, so the while loop will never exit. 3. The syntax 'if i==t[]' is wrong. 4. The way you have this code set up, you would need two loops: an outer loop for i from 1 to 25, and an inner loop for the items in t. 5. As others have said, this is a poor way to go about it. You want to use "if i in t". -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From th982a at googlemail.com Wed Mar 20 15:06:00 2013 From: th982a at googlemail.com (Tamer Higazi) Date: Wed, 20 Mar 2013 20:06:00 +0100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array Message-ID: <514A0898.4000807@googlemail.com> Hi poeple! I wrote a small script, and I am not getting smart....what is ment with this error message... Any ideas?! I got this error message: SOAPpy.Types.faultType: File "/storage/PyProjects/toolsAPP/KASUpdate.py", line 32, in KasObj = KASSystem() File "/storage/PyProjects/toolsAPP/KASUpdate.py", line 27, in __init__ 'SessionLifeTime':loginData['sess_lt'],'SessionUpdateLifeTime':'Y'}) Here is the code: from SOAPpy import WSDL from SOAPpy.Errors import HTTPError as SoapHTTPError from SOAPpy.Types import faultType import hashlib class KASSystem(object): def __init__(self): WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl' WSDL_API = 'https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl' userpass = ['login','password'] m = hashlib.sha1() m.update(userpass[1]) userpass[1] = m.hexdigest() loginData = {'user':userpass[0],'pass':userpass[1]} self.__SoapServer = WSDL.Proxy(WSDL_AUTH) try: self.__CredentialToken = self.__SoapServer.KasAuth({ 'KasUser':loginData['user'], 'KasAuthType':'sha1', 'KasPassword':loginData['pass'], 'SessionLifeTime':1800,'SessionUpdateLifeTime':'Y'}) except (SoapHTTPError), e: print "Fehlermeldung:", e.code,e.msg KasObj = KASSystem() From rosuav at gmail.com Thu Mar 21 12:21:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2013 03:21:04 +1100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: <514A0898.4000807@googlemail.com> References: <514A0898.4000807@googlemail.com> Message-ID: On Thu, Mar 21, 2013 at 6:06 AM, Tamer Higazi wrote: > SOAPpy.Types.faultType: type stdClass as array> stdClass looks like a PHP error. Check out the server's requirements; perhaps you need to provide something as a list that you're providing as a dict, or something. I'd look at that loginData, for instance. ChrisA From th982a at googlemail.com Sat Mar 23 09:33:17 2013 From: th982a at googlemail.com (Tamer Higazi) Date: Sat, 23 Mar 2013 14:33:17 +0100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: References: <514A0898.4000807@googlemail.com> Message-ID: <514DAF1D.50801@googlemail.com> Hi Chris! thanks.... But I am about of going nuts.... I did everything according their sample: http://kasapi.kasserver.com/dokumentation/?open=soap and wanted to accomplish it in python! If I pass a dict, I get the error telling me, this nonsense..... What should I do?! I even tried it in "suds" instead of soappy, and I am not getting further. Tamer Am 21.03.2013 17:21, schrieb Chris Angelico: > On Thu, Mar 21, 2013 at 6:06 AM, Tamer Higazi wrote: >> SOAPpy.Types.faultType: > type stdClass as array> > > stdClass looks like a PHP error. Check out the server's requirements; > perhaps you need to provide something as a list that you're providing > as a dict, or something. I'd look at that loginData, for instance. > > ChrisA > From davea at davea.name Sat Mar 23 09:51:33 2013 From: davea at davea.name (Dave Angel) Date: Sat, 23 Mar 2013 09:51:33 -0400 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: <514DAF1D.50801@googlemail.com> References: <514A0898.4000807@googlemail.com> <514DAF1D.50801@googlemail.com> Message-ID: <514DB365.6000702@davea.name> On 03/23/2013 09:33 AM, Tamer Higazi wrote: > Hi Chris! > thanks.... But I am about of going nuts.... I did everything according > their sample: > > http://kasapi.kasserver.com/dokumentation/?open=soap > > > and wanted to accomplish it in python! Isn't there an API on Python SOAPpy published somewhere? Wild guess, but perhaps the 1800 should have been '1800' php blurs the distinction between numbers and strings, and maybe the dict values are supposed to be all strings. > > If I pass a dict, I get the error telling me, this nonsense..... What > should I do?! > > I even tried it in "suds" instead of soappy, and I am not getting further. > > > > > Tamer > > > Am 21.03.2013 17:21, schrieb Chris Angelico: >> On Thu, Mar 21, 2013 at 6:06 AM, Tamer Higazi wrote: >>> SOAPpy.Types.faultType: >> type stdClass as array> >> >> stdClass looks like a PHP error. Check out the server's requirements; >> perhaps you need to provide something as a list that you're providing >> as a dict, or something. I'd look at that loginData, for instance. >> >> ChrisA >> > -- DaveA From rosuav at gmail.com Sat Mar 23 11:03:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 02:03:57 +1100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: <514DAF1D.50801@googlemail.com> References: <514A0898.4000807@googlemail.com> <514DAF1D.50801@googlemail.com> Message-ID: On Sun, Mar 24, 2013 at 12:33 AM, Tamer Higazi wrote: > Hi Chris! > thanks.... But I am about of going nuts.... I did everything according > their sample: > > http://kasapi.kasserver.com/dokumentation/?open=soap Since I'm not fluent in German, I'm relying on Google Translate to read of that page. (I didn't find an obvious English version of the page, but maybe I just didn't look in the right place.) One thing I've found about the PHP SOAP library is that it seems to behave quite oddly in some circumstances - my suspicion is the WSDL file (eg when it's unable to load it). Try monitoring the actual traffic - SOAP is XML carried over HTTP, so you should be able to just snoop the TCP/IP socket (easiest way might be to switch in your own server). See if you can spot a difference between the request that PHP sends and the one your Python script sends. Fortunately you're not moving megabytes of data around, here - it should be easy enough to eyeball the requests and see what's different about them :) A tip, by the way: userpass = ['login','password'] m = hashlib.sha1() m.update(userpass[1]) userpass[1] = m.hexdigest() loginData = {'user':userpass[0],'pass':userpass[1]} 'KasUser':loginData['user'], 'KasPassword':loginData['pass'], You keep packaging and repackaging the credentials. I'm assuming you won't actually have them hard-coded like that (if you do, I would recommend hard-coding the SHA1 hash, rather than the password itself), so I'll stick with the userpass list (or tuple, which would work exactly the same way). password = hashlib.sha1(userpass[1]).hexdigest() ... 'KasUser':userpass[0], 'KasPassword':password, Or even inline that completely (which is what I'd probably do). There's no need to stuff it into a dictionary, only to pull it out again. Also: A try/except that just prints out the error message usually isn't helpful. Save yourself the trouble, at least during initial testing - just let the exception terminate your script. You'll get all the same information, plus the full traceback, and it's cost you exactly zero development time :) Later on, you can add try/except if you need to do something other than terminate, but often that "later on" never even happens. ChrisA From th982a at googlemail.com Sat Mar 23 15:38:41 2013 From: th982a at googlemail.com (Tamer Higazi) Date: Sat, 23 Mar 2013 20:38:41 +0100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: References: <514A0898.4000807@googlemail.com> <514DAF1D.50801@googlemail.com> Message-ID: <514E04C1.20505@googlemail.com> Chris! I did what you said before in several ways. The last way was putting the user and password directly into the dict as parameter ALWAYS ends up telling me, that I cannot use object of standard type class as ARRAY.... I did it this time with suds. So packaging issue is now out of scope, and always the same headache. now tell me what this error might tell me: suds.WebFault: Server raised fault: 'Cannot use object of type stdClass as array' File "/storage/PyProjects/toolsAPP/python/KASUpdate2.py", line 23, in KasObj = KASSystem() File "/storage/PyProjects/toolsAPP/python/KASUpdate2.py", line 20, in __init__ 'SessionUpdateLifeTime':'Y'}) File "/storage/PyENV/lin/toolsENV/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 542, in __call__ File "/storage/PyENV/lin/toolsENV/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 602, in invoke File "/storage/PyENV/lin/toolsENV/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 649, in send File "/storage/PyENV/lin/toolsENV/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 702, in failed File "/storage/PyENV/lin/toolsENV/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 265, in get_fault and when I open the python files they hand me out only the error messages, which was sent back from Server! here is the code: import hashlib from suds.client import Client from suds import WebFault class KASSystem: def __init__(self): WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl' WSDL_API = 'https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl' m = hashlib.sha1() m.update('userpass') SoapClient = Client(WSDL_AUTH) SoapClient.service.KasAuth({ 'KasUser':'userlogin', 'KasAuthType':'sha1', 'KasPassword':m.hexdigest(), 'SessionLifeTime':1800, 'SessionUpdateLifeTime':'Y'}) KasObj = KASSystem() Tamer Am 23.03.2013 16:03, schrieb Chris Angelico: > On Sun, Mar 24, 2013 at 12:33 AM, Tamer Higazi wrote: >> Hi Chris! >> thanks.... But I am about of going nuts.... I did everything according >> their sample: >> >> http://kasapi.kasserver.com/dokumentation/?open=soap > > Since I'm not fluent in German, I'm relying on Google Translate to > read of that page. (I didn't find an obvious English version of the > page, but maybe I just didn't look in the right place.) > > One thing I've found about the PHP SOAP library is that it seems to > behave quite oddly in some circumstances - my suspicion is the WSDL > file (eg when it's unable to load it). Try monitoring the actual > traffic - SOAP is XML carried over HTTP, so you should be able to just > snoop the TCP/IP socket (easiest way might be to switch in your own > server). See if you can spot a difference between the request that PHP > sends and the one your Python script sends. Fortunately you're not > moving megabytes of data around, here - it should be easy enough to > eyeball the requests and see what's different about them :) > > A tip, by the way: > > userpass = ['login','password'] > m = hashlib.sha1() > m.update(userpass[1]) > > userpass[1] = m.hexdigest() > loginData = {'user':userpass[0],'pass':userpass[1]} > > 'KasUser':loginData['user'], > 'KasPassword':loginData['pass'], > > You keep packaging and repackaging the credentials. I'm assuming you > won't actually have them hard-coded like that (if you do, I would > recommend hard-coding the SHA1 hash, rather than the password itself), > so I'll stick with the userpass list (or tuple, which would work > exactly the same way). > > password = hashlib.sha1(userpass[1]).hexdigest() > ... > 'KasUser':userpass[0], > 'KasPassword':password, > > Or even inline that completely (which is what I'd probably do). > There's no need to stuff it into a dictionary, only to pull it out > again. > > Also: A try/except that just prints out the error message usually > isn't helpful. Save yourself the trouble, at least during initial > testing - just let the exception terminate your script. You'll get all > the same information, plus the full traceback, and it's cost you > exactly zero development time :) Later on, you can add try/except if > you need to do something other than terminate, but often that "later > on" never even happens. > > ChrisA > From rosuav at gmail.com Sat Mar 23 16:55:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 07:55:00 +1100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: <514E04C1.20505@googlemail.com> References: <514A0898.4000807@googlemail.com> <514DAF1D.50801@googlemail.com> <514E04C1.20505@googlemail.com> Message-ID: On Sun, Mar 24, 2013 at 6:38 AM, Tamer Higazi wrote: > Chris! > I did what you said before in several ways. > > The last way was putting the user and password directly into the dict as > parameter ALWAYS ends up telling me, that I cannot use object of > standard type class as ARRAY.... > > I did it this time with suds. So packaging issue is now out of scope, > and always the same headache. > > > now tell me what this error might tell me: > > > suds.WebFault: Server raised fault: 'Cannot use object of type stdClass > as array' So it's the same error this way, too. That error came back from the server, and is being quoted verbatim. That means that, ultimately, the problem is in the XML blob that you're sending it; the trick is to figure out what exactly the server isn't happy with. (Aside: The server is at least partly at fault here. It should be giving more useful error messages. But I'm assuming you don't have any control over the server.) I tried the reference PHP implementation off the web site, and it's coming back with 500 Internal Server Error with body of text/html, which is clearly buggy documentation. When I change it to use the WSDL you're using, I can actually get something plausible out of it. Modified PHP code: 1]); // url zur wsdl - Datei $CredentialToken = $SoapLogon->KasAuth( array('KasUser' => $kas_user, 'KasAuthType' => 'sha1', 'KasPassword' => sha1($kas_pass), 'SessionLifeTime' => $session_lifetime, 'SessionUpdateLifeTime' => $session_update_lifetime ) ); } // Fehler abfangen und ausgeben catch (SoapFault $fault) { echo "Request:\n".$SoapLogon->__getLastRequestHeaders()."\n".$SoapLogon->__getLastRequest()."\n"; echo "Response:\n".$SoapLogon->__getLastResponseHeaders()."\n".$SoapLogon->__getLastResponse()."\n"; trigger_error("Fehlernummer: {$fault->faultcode}, Fehlermeldung: {$fault->faultstring}, Verursacher: {$fault->faultactor}, Details: {$fault->detail}", E_USER_ERROR); } (Another aside: Until I added the two echo lines, this had a try/catch that simply triggered a fatal error. This is pointless. Just let the error happen!) Here's the packet the PHP code sends: KasUserw001234KasAuthTypesha1KasPassword2db6d21d365f544f7ca3bcfb443ac96898a7a069SessionLifeTime1800SessionUpdateLifeTimeY Here's what your original Python version sends, lifted via tcpdump as I'm not sufficiently familiar with soappy to get a full packet dump out of it: Y sha1 1800 login 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 And here's what your latest Python sends, lifted the same way for the same reason regarding suds: Ysha11800userlogin45f106ef4d5161e7aa38cf6c666607f25748b6ca The PHP version comes back with a fault string "kas_password_incorrect", which is what I would expect. The Python ones both show the PHP crash you described. I'm seeing quite a few differences between the three; figuring out what's the cause of the crash will be a matter of fiddling until you discover it. I would recommend, at least for testing, bypassing the whole SOAP library layer and putting XML data straight into HTTP requests. And maybe you'll find that's the easiest option for production code, too; I've done exactly that at work, talking to SOAP servers at eBay and other sites. Building up XML isn't difficult, and it's generally easier to have less layers to debug. Hope that's of at least some value to you. It looks likely the server's largely to blame for this. ChrisA From th982a at googlemail.com Sun Mar 24 03:39:30 2013 From: th982a at googlemail.com (Tamer Higazi) Date: Sun, 24 Mar 2013 08:39:30 +0100 Subject: SOAPpy.Types.faultType: Cannot use object of type stdClass as array In-Reply-To: References: <514A0898.4000807@googlemail.com> <514DAF1D.50801@googlemail.com> <514E04C1.20505@googlemail.com> Message-ID: <514EADB2.6040009@googlemail.com> Hi Chris! The example from the website is buggy because the WSDL urls are not correct... $WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl' $WSDL_API ='https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl' which I had replaced so far. then you will see the results, even if the login and pass do not match. I think for many python developers it might be really interesting to know, WHAT A PHP ARRAY is in python in a SOAP environment. Tamer Am 23.03.2013 21:55, schrieb Chris Angelico: > On Sun, Mar 24, 2013 at 6:38 AM, Tamer Higazi wrote: >> Chris! >> I did what you said before in several ways. >> >> The last way was putting the user and password directly into the dict as >> parameter ALWAYS ends up telling me, that I cannot use object of >> standard type class as ARRAY.... >> >> I did it this time with suds. So packaging issue is now out of scope, >> and always the same headache. >> >> >> now tell me what this error might tell me: >> >> >> suds.WebFault: Server raised fault: 'Cannot use object of type stdClass >> as array' > > So it's the same error this way, too. That error came back from the > server, and is being quoted verbatim. That means that, ultimately, the > problem is in the XML blob that you're sending it; the trick is to > figure out what exactly the server isn't happy with. > > (Aside: The server is at least partly at fault here. It should be > giving more useful error messages. But I'm assuming you don't have any > control over the server.) > > I tried the reference PHP implementation off the web site, and it's > coming back with 500 Internal Server Error with body of text/html, > which is clearly buggy documentation. When I change it to use the WSDL > you're using, I can actually get something plausible out of it. > > Modified PHP code: > > > // URIs zu den WSDL-Dateien > $WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl'; > //$WSDL_API = 'https://kasserver.com/schnittstelle/soap/wsdl/KasApi.wsdl'; > > // Logindaten > $kas_user = 'w001234'; // KAS-Logon > $kas_pass = 'xxxxxxx'; // KAS-Passwort > $session_lifetime = 1800; // G??ltigkeit des Tokens in Sek. bis zur > neuen Authentifizierung > $session_update_lifetime = 'Y'; // Soll bei jeder Aktion die > Sessionlifetime wieder auf den > // Wert in "$session_lifetime" > gesetzt werden? ('Y' / 'N') > try > { > $SoapLogon = new SoapClient($WSDL_AUTH,["trace"=>1]); // url zur wsdl - Datei > $CredentialToken = $SoapLogon->KasAuth( > array('KasUser' => $kas_user, > 'KasAuthType' => 'sha1', > 'KasPassword' => sha1($kas_pass), > 'SessionLifeTime' => $session_lifetime, > 'SessionUpdateLifeTime' => > $session_update_lifetime > ) > ); > } > > // Fehler abfangen und ausgeben > catch (SoapFault $fault) > { > echo "Request:\n".$SoapLogon->__getLastRequestHeaders()."\n".$SoapLogon->__getLastRequest()."\n"; > echo "Response:\n".$SoapLogon->__getLastResponseHeaders()."\n".$SoapLogon->__getLastResponse()."\n"; > trigger_error("Fehlernummer: {$fault->faultcode}, > Fehlermeldung: {$fault->faultstring}, > Verursacher: {$fault->faultactor}, > Details: {$fault->detail}", E_USER_ERROR); > } > > > > (Another aside: Until I added the two echo lines, this had a try/catch > that simply triggered a fatal error. This is pointless. Just let the > error happen!) > > Here's the packet the PHP code sends: > > > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:ns1="urn:xmethodsKasApiAuthentication" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:ns2="http://xml.apache.org/xml-soap" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> xsi:type="ns2:Map"> xsi:type="xsd:string">KasUser xsi:type="xsd:string">w001234 xsi:type="xsd:string">KasAuthType xsi:type="xsd:string">sha1 xsi:type="xsd:string">KasPassword xsi:type="xsd:string">2db6d21d365f544f7ca3bcfb443ac96898a7a069 xsi:type="xsd:string">SessionLifeTime xsi:type="xsd:int">1800 xsi:type="xsd:string">SessionUpdateLifeTime xsi:type="xsd:string">Y > > Here's what your original Python version sends, lifted via tcpdump as > I'm not sufficiently familiar with soappy to get a full packet dump > out of it: > > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsd="http://www.w3.org/1999/XMLSchema" >> > > > > Y > sha1 > 1800 > login > 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 > > > > > > And here's what your latest Python sends, lifted the same way for the > same reason regarding suds: > xmlns:ns3="http://www.w3.org/2001/XMLSchema" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:ns0="urn:xmethodsKasApiAuthentication" > xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:ns4="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> xsi:type="ns1:Params"> xsi:type="ns3:string">Y xsi:type="ns3:string">sha1 xsi:type="ns3:int">1800 xsi:type="ns3:string">userlogin xsi:type="ns3:string">45f106ef4d5161e7aa38cf6c666607f25748b6ca > > > The PHP version comes back with a fault string > "kas_password_incorrect", which is what I would expect. The Python > ones both show the PHP crash you described. I'm seeing quite a few > differences between the three; figuring out what's the cause of the > crash will be a matter of fiddling until you discover it. > > I would recommend, at least for testing, bypassing the whole SOAP > library layer and putting XML data straight into HTTP requests. And > maybe you'll find that's the easiest option for production code, too; > I've done exactly that at work, talking to SOAP servers at eBay and > other sites. Building up XML isn't difficult, and it's generally > easier to have less layers to debug. > > Hope that's of at least some value to you. It looks likely the > server's largely to blame for this. > > ChrisA > From amani.abdulhadi at mediu.ws Thu Mar 21 03:49:38 2013 From: amani.abdulhadi at mediu.ws (amani.abdulhadi at mediu.ws) Date: Thu, 21 Mar 2013 00:49:38 -0700 (PDT) Subject: Oracle Message-ID: Oracle In Classical Antiquity, an oracle was a person or agency considered to be a source of wise counsel or prophetic predictions or precognition of the future, inspired by the gods. As such it is a form of divination. The word oracle comes from the Latin verb ?r?re "to speak" and properly refers to the priest or priestess uttering the prediction. In extended use, oraclemay also refer to the site of the oracle, and to the oracular utterances themselves, called khr?smoi (???????) in Greek. Oracles were thought to be portals through which the gods spoke directly to people. In this sense they were different from seers (manteis, ???????) who interpreted signs sent by the gods through bird signs, animal entrails, and other various methods.[1] The most important oracles of Greek antiquity were Pythia, priestess to Apollo at Delphi, and the oracle of Dione and Zeus at Dodona in Epirus. Other temples of Apollo were located at Didyma on the coast of Asia Minor, at Corinth and Bassae in the Peloponnese, and at the islands of Delos andAegina in the Aegean Sea. Only the Delphic Oracle was a male; all others were female.[2] The Sibylline Oracles are a collection of oracular utterances written in Greek hexameters ascribed to the Sibyls, prophetesses who uttered divine revelations in a frenzied state. please visit web site http://vb.mediu.edu.my/showthread.php?t=20631 From bartolome.sintes at gmail.com Thu Mar 21 04:52:17 2013 From: bartolome.sintes at gmail.com (bartolome.sintes at gmail.com) Date: Thu, 21 Mar 2013 01:52:17 -0700 (PDT) Subject: free and nonlocal variables Message-ID: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> In Python 3, "free variable" and "nonlocal variable" are synonym terms? Or is there a difference, like "a free variable is a variable that is not a local variable, then nonlocal variables and global variables are both free variables"? Thanking you in advance, Bartolom? Sintes From dihedral88888 at googlemail.com Thu Mar 21 05:34:09 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 21 Mar 2013 02:34:09 -0700 (PDT) Subject: free and nonlocal variables In-Reply-To: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> References: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> Message-ID: <7f0df9d6-6370-478a-85fb-6e6f2ed869c5@googlegroups.com> bartolom... at gmail.com? 2013?3?21????UTC+8??4?52?17???? > In Python 3, "free variable" and "nonlocal variable" are synonym terms? Or is there a difference, like "a free variable is a variable that is not a local variable, then nonlocal variables and global variables are both free variables"? > > > > Thanking you in advance, > > Bartolom? Sintes In python the interpreter has to check 4 levels of dictionaries in the run time to perform an action. The for levels are: 1. object instance level 2. class level 3. local function level 4. global level. Objects created at level 1,2,3 can be returned to some other object in the run time. Thus a GC is available to save the trouble of tracking everything for the programmer in a complex system. From steve+comp.lang.python at pearwood.info Thu Mar 21 07:00:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2013 11:00:16 GMT Subject: free and nonlocal variables References: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> Message-ID: <514ae83f$0$30001$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Mar 2013 01:52:17 -0700, bartolome.sintes wrote: > In Python 3, "free variable" and "nonlocal variable" are synonym terms? > Or is there a difference, like "a free variable is a variable that is > not a local variable, then nonlocal variables and global variables are > both free variables"? "Free variable" is a formal term from computer science. As far as I know, Python uses it in exactly the same way. A free variable is a variable in an expression or function that is not local (which includes function parameters) to that expression. So both global and non-local variables are free variables. def spam(x): def inner(): y = x**2 - 1 return x + y + z return inner() In inner(), both x and z are free variables, but y is not, since it is local to the inner() function. -- Steven From tjreedy at udel.edu Thu Mar 21 07:55:01 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Mar 2013 07:55:01 -0400 Subject: free and nonlocal variables In-Reply-To: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> References: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> Message-ID: On 3/21/2013 4:52 AM, bartolome.sintes at gmail.com wrote: > In Python 3, "free variable" and "nonlocal variable" are synonym terms? Yes, but that is idiosyncratic to Python. > Or is there a difference, like "a free variable is a variable that is > not a local variable, then nonlocal variables and global variables are > both free variables"? I believe that is the usual definition, such as you would find on Wikipedia. -- Terry Jan Reedy From nobody at nowhere.com Thu Mar 21 15:05:37 2013 From: nobody at nowhere.com (Nobody) Date: Thu, 21 Mar 2013 19:05:37 +0000 Subject: free and nonlocal variables References: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> Message-ID: On Thu, 21 Mar 2013 01:52:17 -0700, bartolome.sintes wrote: > In Python 3, "free variable" and "nonlocal variable" are synonym terms? "Free variable" is a computer science term. A variable is free if it is not bound. E.g. x and y are free in "x+y", x is bound and y is free in "lambda x: x+y", x and y are both bound in "lambda y: lambda x: x+y". IOW, a variable is free in an expression if the expression doesn't include whatever created the variable. In Python 3, the "nonlocal" keyword indicates that a name refers to a variable created in an outer function. Names are deduced as referring to local, nonlocal (outer) or global variables at compile time. If a name is a function parameter, then it's a local variable. If a function definition doesn't include an assignment to a name, or a global or nonlocal statement for that name, the name refers to a nonlocal variable (local variable in an enclosing function) if one exists, otherwise to a global variable. By default, the presence of an assignment causes the name to be treated as a local variable. If the variable is read prior to assignment, an UnboundLocalError is raised (even if a global or nonlocal variable exists with that name; the decision is made when the function is compiled, not when the assignment is executed). However, a "global" statement causes the name to be treated as a global variable, while a "nonlocal" statement causes it to be treated as a reference to a local variable of the enclosing function. Again, it is the presence of these statements during compilation, not execution of them at run time, which causes the name to be deduced as a global or nonlocal variable. From jpiitula at ling.helsinki.fi Thu Mar 21 16:36:09 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 21 Mar 2013 22:36:09 +0200 Subject: free and nonlocal variables References: <263e910f-4cc5-4b50-bf8d-c207622170b5@googlegroups.com> Message-ID: Nobody writes: > On Thu, 21 Mar 2013 01:52:17 -0700, bartolome.sintes wrote: > > > In Python 3, "free variable" and "nonlocal variable" are synonym > > terms? > > "Free variable" is a computer science term. A variable is free if it > is not bound. E.g. x and y are free in "x+y", x is bound and y is > free in "lambda x: x+y", x and y are both bound in "lambda y: lambda > x: x+y". IOW, a variable is free in an expression if the expression > doesn't include whatever created the variable. And in (lambda x : x)(x) + x below, x occurs both free and bound. The free occurrences are bound by the outer lambda. >>> (lambda x : (lambda x : x)(x) + x)(3) 6 From mathias at koerber.org Thu Mar 21 07:36:53 2013 From: mathias at koerber.org (=?UTF-8?B?TWF0aGlhcyBLxZFyYmVy?=) Date: Thu, 21 Mar 2013 19:36:53 +0800 Subject: encoding for colon-separated hex? Message-ID: is there a built-in encoding (for encode/decode methods) that as colon-separated hex (01:02:03:04...)? 'hex' seems to encode as '01020304' and while one can postprocess that to insert the colons, if a single operation exists, I'd rather use that. From arnodel at gmail.com Thu Mar 21 10:37:12 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 21 Mar 2013 14:37:12 +0000 Subject: tkinter: invisible PanedWindow "sashes" on OS X Message-ID: Hi Python List, I'm trying to use PanedWindow on OS X (10.8.3). I've started with the effbot docs example (http://effbot.org/tkinterbook/panedwindow.htm), namely: ---------- from Tkinter import * m = PanedWindow(orient=VERTICAL) m.pack(fill=BOTH, expand=1) top = Label(m, text="top pane") m.add(top) bottom = Label(m, text="bottom pane") m.add(bottom) mainloop() ---------- I can see two panes alright, but no handle to resize them (or 'sash' as they seem to be called in tkinter). Is there something else that I should be doing? TIA, -- Arnaud From auriocus at gmx.de Thu Mar 21 14:42:27 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 21 Mar 2013 19:42:27 +0100 Subject: tkinter: invisible PanedWindow "sashes" on OS X In-Reply-To: References: Message-ID: Am 21.03.13 15:37, schrieb Arnaud Delobelle: > Hi Python List, > > I'm trying to use PanedWindow on OS X (10.8.3). I've started with the > effbot docs example (http://effbot.org/tkinterbook/panedwindow.htm), > namely: > > ---------- > from Tkinter import * > > m = PanedWindow(orient=VERTICAL) > m.pack(fill=BOTH, expand=1) > > top = Label(m, text="top pane") > m.add(top) > > bottom = Label(m, text="bottom pane") > m.add(bottom) > > mainloop() > ---------- > > I can see two panes alright, but no handle to resize them (or 'sash' > as they seem to be called in tkinter). Is there something else that I > should be doing? This is, unfortunately, the platform standard on both OSX and Windows7. You can still resize the windows: Just grab the space between the two labels. There should be at least a cursor change. With you example it doesn't work particularly well, because the labels are small and have no visible border. Try using e.g. a text widget instead (or maybe relief=SUNKEN) Christian From arnodel at gmail.com Thu Mar 21 16:59:05 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 21 Mar 2013 20:59:05 +0000 Subject: tkinter: invisible PanedWindow "sashes" on OS X In-Reply-To: References: Message-ID: On 21 March 2013 18:42, Christian Gollwitzer wrote: > Am 21.03.13 15:37, schrieb Arnaud Delobelle: > >> Hi Python List, >> >> I'm trying to use PanedWindow on OS X (10.8.3). I've started with the >> effbot docs example (http://effbot.org/tkinterbook/panedwindow.htm), >> namely: >> >> ---------- >> from Tkinter import * >> >> m = PanedWindow(orient=VERTICAL) >> m.pack(fill=BOTH, expand=1) >> >> top = Label(m, text="top pane") >> m.add(top) >> >> bottom = Label(m, text="bottom pane") >> m.add(bottom) >> >> mainloop() >> ---------- >> >> I can see two panes alright, but no handle to resize them (or 'sash' >> as they seem to be called in tkinter). Is there something else that I >> should be doing? > > > This is, unfortunately, the platform standard on both OSX and Windows7. You > can still resize the windows: Just grab the space between the two labels. > There should be at least a cursor change. I cannot effect a cursor change with the example above. > With you example it doesn't work particularly well, because the labels are > small and have no visible border. Try using e.g. a text widget instead (or > maybe relief=SUNKEN) If I use text widgets for the top and bottom panes, then I can get a resize cursor and I am able to drag the 'sash' up and down. That's good enough for me to get started. Thanks for the suggestion, -- Arnaud From l.selmi at icloud.com Thu Mar 21 14:31:47 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Thu, 21 Mar 2013 19:31:47 +0100 Subject: problem with function Message-ID: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> hi all, i wrote the following code: def find(word, letter): index = 0 while index < len(word): if word[index] == letter: return index index = index + 1 return -1 if i run the program i get this error: name 'word' is not defined. how can i solve it? thanks! From rosuav at gmail.com Thu Mar 21 15:40:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2013 06:40:35 +1100 Subject: problem with function In-Reply-To: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Message-ID: On Fri, Mar 22, 2013 at 5:31 AM, leonardo selmi wrote: > hi all, > > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 > > if i run the program i get this error: name 'word' is not defined. how can i solve it? You'll need to post the whole code of your program. That function works fine for me. (Though it's somewhat unPythonic code, and in any case already exists in the standard library.) Tip: Look at the full traceback from the error. Chances are you'll find the cause of the error on one of the lines near the end of the trace. ChrisA From davea at davea.name Thu Mar 21 15:48:23 2013 From: davea at davea.name (Dave Angel) Date: Thu, 21 Mar 2013 15:48:23 -0400 Subject: problem with function In-Reply-To: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Message-ID: <514B6407.2000204@davea.name> On 03/21/2013 02:31 PM, leonardo selmi wrote: > hi all, > > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 > > if i run the program i get this error: name 'word' is not defined. how can i solve it? > If I run it, I get nothing at all, since there's no call to find()). And when I add lines that print the results of calling the function, I get reasonable results. How about if you do the following: 1) tell us Python version and OS. 2) show us the whole code, copy/pasted into your message 3) show us the whole error message (traceback), copy/pasted into your message And if you're running it from somewhere other than a terminal window, tell us how you're running it. Or better, run it from a terminal, and show us the whole sequence, by copy/pasting from the terminal to the message. -- DaveA From foo at email.invalid Thu Mar 21 16:11:06 2013 From: foo at email.invalid (Alex) Date: Thu, 21 Mar 2013 20:11:06 +0000 (UTC) Subject: problem with function References: Message-ID: leonardo selmi wrote: > hi all, > > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 > > if i run the program i get this error: name 'word' is not defined. > how can i solve it? > What does your call to find look like? I called it with: find("word", 'd') and it returned 3, as expected. If I call find with find(word, 'd') I get an error, as expected, since I have not assigned a string to the name word. From ian.g.kelly at gmail.com Thu Mar 21 18:04:26 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 21 Mar 2013 16:04:26 -0600 Subject: problem with function In-Reply-To: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Message-ID: On Mar 21, 2013 1:35 PM, "leonardo selmi" wrote: > > hi all, > > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 > More efficient: def find(word, letter): return word.find(letter) Or even: find = str.find Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Mar 21 19:20:49 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Mar 2013 19:20:49 -0400 Subject: problem with function In-Reply-To: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Message-ID: On 3/21/2013 2:31 PM, leonardo selmi wrote: > i wrote the following code: > > def find(word, letter): > index = 0 > while index < len(word): > if word[index] == letter: > return index > index = index + 1 > return -1 Since this is a learning exercise, consider the following. def find(word, letter): for index, let in enumerate(word): if let == letter: return index return -1 for w, l, n in (('abc', 'a', 0), ('abc', 'c', 2), ('abc', 'd', -1)): assert find(w, l) == n print("no news is good news") I copied the code, wrote the test, ran it, and it passed. I then re-wrote until syntax errors were gone and the new version passed. For loops are specialized, easier-to-write version of while loops that scan the items of a collection (iterable). Learn them and use them well. Learn to write automated tests as soon as possible. -- Terry Jan Reedy From tampucciolina at libero.it Fri Mar 22 03:04:23 2013 From: tampucciolina at libero.it (leonardo) Date: Fri, 22 Mar 2013 08:04:23 +0100 Subject: problem with function In-Reply-To: References: <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> Message-ID: <7998B590-1ED3-4FDA-A8BA-668D9A1CA0DE@libero.it> thank you all Il giorno 22/mar/2013, alle ore 00:20, Terry Reedy ha scritto: > On 3/21/2013 2:31 PM, leonardo selmi wrote: > >> i wrote the following code: >> >> def find(word, letter): >> index = 0 >> while index < len(word): >> if word[index] == letter: >> return index >> index = index + 1 >> return -1 > > Since this is a learning exercise, consider the following. > > def find(word, letter): > for index, let in enumerate(word): > if let == letter: > return index > return -1 > > for w, l, n in (('abc', 'a', 0), ('abc', 'c', 2), ('abc', 'd', -1)): > assert find(w, l) == n > print("no news is good news") > > I copied the code, wrote the test, ran it, and it passed. I then re-wrote until syntax errors were gone and the new version passed. For loops are specialized, easier-to-write version of while loops that scan the items of a collection (iterable). Learn them and use them well. Learn to write automated tests as soon as possible. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From cjw at ncf.ca Thu Mar 21 15:40:03 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 21 Mar 2013 15:40:03 -0400 Subject: Binary for numpy 1.7.0 with Python 2.7.3 Message-ID: How do I find the binaries on Source Forge? I'm trying to update to both 2.7.3 and Numpy 1.7.0. Colin W From davea at davea.name Thu Mar 21 16:00:56 2013 From: davea at davea.name (Dave Angel) Date: Thu, 21 Mar 2013 16:00:56 -0400 Subject: Binary for numpy 1.7.0 with Python 2.7.3 In-Reply-To: References: Message-ID: <514B66F8.8030707@davea.name> On 03/21/2013 03:40 PM, Colin J. Williams wrote: > How do I find the binaries on Source Forge? > > I'm trying to update to both 2.7.3 and Numpy 1.7.0. > > Colin W Best answer might depend on what OS you're running, and what implementation of Python you're after. Why would you look on SourceForge for Python; get it from Python.org http://www.python.org/getit/ or you may want the one from ActiveState, also linked from that page. or you may just want to get it from your Linux distro, perhaps from the Synaptic Package Manager. For numpy, try: http://www.scipy.org/Download -- DaveA From kwpolska at gmail.com Thu Mar 21 16:05:23 2013 From: kwpolska at gmail.com (Kwpolska) Date: Thu, 21 Mar 2013 21:05:23 +0100 Subject: Binary for numpy 1.7.0 with Python 2.7.3 In-Reply-To: References: Message-ID: On Thu, Mar 21, 2013 at 8:40 PM, Colin J. Williams wrote: > How do I find the binaries on Source Forge? > > I'm trying to update to both 2.7.3 and Numpy 1.7.0. > > Colin W > -- > http://mail.python.org/mailman/listinfo/python-list You don?t. First off, nobody really likes nor uses SourceForge today. Python can be found on the website, http://www.python.org/getit/ and numpy is in the PyPI: https://pypi.python.org/pypi/numpy . Both links have Windows binaries, which I assume you want. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From cjw at ncf.ca Thu Mar 21 18:16:55 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 21 Mar 2013 18:16:55 -0400 Subject: Binary for numpy 1.7.0 with Python 2.7.3 In-Reply-To: References: Message-ID: <514B86D7.1000505@ncf.ca> On 21/03/2013 4:00 PM, Dave Angel wrote: > On 03/21/2013 03:40 PM, Colin J. Williams wrote: >> How do I find the binaries on Source Forge? >> >> I'm trying to update to both 2.7.3 and Numpy 1.7.0. >> >> Colin W > > Best answer might depend on what OS you're running, and what > implementation of Python you're after. > > Why would you look on SourceForge for Python; get it from Python.org > > http://www.python.org/getit/ > > or you may want the one from ActiveState, also linked from that page. > > or you may just want to get it from your Linux distro, perhaps from the > Synaptic Package Manager. > > For numpy, try: > > http://www.scipy.org/Download > > > I'm not trying to get the Python, that's clearly available from python.org. The SciPy/Numpy page refers to sourceforge. KWPolska referred me to PyPi., using that is a smooth job to retrieve Numpy.. Thanks to both. Colin W. From cjw at ncf.ca Thu Mar 21 18:16:55 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Thu, 21 Mar 2013 18:16:55 -0400 Subject: Binary for numpy 1.7.0 with Python 2.7.3 In-Reply-To: References: Message-ID: <514B86D7.1000505@ncf.ca> On 21/03/2013 4:00 PM, Dave Angel wrote: > On 03/21/2013 03:40 PM, Colin J. Williams wrote: >> How do I find the binaries on Source Forge? >> >> I'm trying to update to both 2.7.3 and Numpy 1.7.0. >> >> Colin W > > Best answer might depend on what OS you're running, and what > implementation of Python you're after. > > Why would you look on SourceForge for Python; get it from Python.org > > http://www.python.org/getit/ > > or you may want the one from ActiveState, also linked from that page. > > or you may just want to get it from your Linux distro, perhaps from the > Synaptic Package Manager. > > For numpy, try: > > http://www.scipy.org/Download > > > I'm not trying to get the Python, that's clearly available from python.org. The SciPy/Numpy page refers to sourceforge. KWPolska referred me to PyPi., using that is a smooth job to retrieve Numpy.. Thanks to both. Colin W. From miki.tebeka at gmail.com Thu Mar 21 21:49:13 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 21 Mar 2013 18:49:13 -0700 (PDT) Subject: Binary for numpy 1.7.0 with Python 2.7.3 In-Reply-To: References: Message-ID: > I'm trying to update to both 2.7.3 and Numpy 1.7.0. Updating Python is from python.org If you're on 64bit windows, see http://www.lfd.uci.edu/~gohlke/pythonlibs/ From awilliam at whitemice.org Thu Mar 21 16:14:29 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 21 Mar 2013 16:14:29 -0400 Subject: Windows Deployment Of Python Modules Message-ID: <1363896869.1738.30.camel@linux-86wr.site> Python itself is easy to deploy on Windows; just toss the MSI in your local update server and away it goes. That's slick; LSUS is awesome. But that gives you Python with no pip, easy_install, etc... And *that* is not packaged appropriately. Is there some trick to getting modules installed on Windows workstations en masse [in an automated fashion]? It seems like I must be missing something. For example, I want Python installed, and the iniparse module. -- Adam Tauno Williams GPG D95ED383 Systems Administrator, Python Developer, LPI / NCLA From awilliam at whitemice.org Thu Mar 21 18:23:56 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 21 Mar 2013 18:23:56 -0400 Subject: Windows Deployment Of Python Modules In-Reply-To: References: <1363896869.1738.30.camel@linux-86wr.site> Message-ID: <6a5de268-22bd-414a-bacc-8beb7e6b49bd@email.android.com> David Robinow wrote: >On Thu, Mar 21, 2013 at 4:14 PM, Adam Tauno Williams > wrote: >> >> Python itself is easy to deploy on Windows; just toss the MSI in >your >> local update server and away it goes. >> >> That's slick; LSUS is awesome. >> >> >> But that gives you Python with no pip, easy_install, etc... And >*that* >> is not packaged appropriately. Is there some trick to getting >modules >> installed on Windows workstations en masse [in an automated fashion]? >> It seems like I must be missing something. >> For example, I want Python installed, and the iniparse module. >python setup.py install >Am I missing something? Yes! That does not get the package to the workstation. It also is not conducive to automation (or success auditing). -- Adam Tauno Williams From drobinow at gmail.com Thu Mar 21 18:40:25 2013 From: drobinow at gmail.com (David Robinow) Date: Thu, 21 Mar 2013 18:40:25 -0400 Subject: Windows Deployment Of Python Modules In-Reply-To: <6a5de268-22bd-414a-bacc-8beb7e6b49bd@email.android.com> References: <1363896869.1738.30.camel@linux-86wr.site> <6a5de268-22bd-414a-bacc-8beb7e6b49bd@email.android.com> Message-ID: On Thu, Mar 21, 2013 at 6:23 PM, Adam Tauno Williams wrote: > David Robinow wrote: >>On Thu, Mar 21, 2013 at 4:14 PM, Adam Tauno Williams >> wrote: >>> >>> Python itself is easy to deploy on Windows; just toss the MSI in >>your >>> local update server and away it goes. >>> >>> That's slick; LSUS is awesome. >>> >>> >>> But that gives you Python with no pip, easy_install, etc... And >>*that* >>> is not packaged appropriately. Is there some trick to getting >>modules >>> installed on Windows workstations en masse [in an automated fashion]? >>> It seems like I must be missing something. >>> For example, I want Python installed, and the iniparse module. >>python setup.py install >>Am I missing something? > > > Yes! > > That does not get the package to the workstation. It also is not conducive to automation (or success auditing). OK, I have no idea what you're talking about. Clearly you want something more than installing packages. From will at willmcgugan.com Thu Mar 21 18:44:52 2013 From: will at willmcgugan.com (Will McGugan) Date: Thu, 21 Mar 2013 17:44:52 -0500 Subject: How can I wrap a binary file-like object with an IO stream? Message-ID: Hi, I am looking in to improving Python 3.X support for PyFilesystem (https:// code.google.com/p/pyfilesystem/). There is provisional Python 3 support in there, but a stumbling block is that I would like the open method to work like io.open in Py3 -- specifically returning text mode streams that handle the unicode encoding/ decoding. At the moment, the 'open' method of PyFilesystem objects just returns a Python 2 style file-like object. What I could use is a way of taking a Python 2.X file-like object together with the mode, encoding and buffering etc. and return an appropriate IO stream that handles the encoding/decoding. I'm sure I could implement the logic myself by looking at the mode/ encoding and return the appropriate IO interface, but I was hoping there was something in the stdlib to do this, or some pre-existing code I can lift? Thanks in advance, Will McGugan -- http://www.willmcgugan.com From sengokubasarafever at gmail.com Thu Mar 21 19:43:48 2013 From: sengokubasarafever at gmail.com (maiden129) Date: Thu, 21 Mar 2013 16:43:48 -0700 (PDT) Subject: Global NameError Fix? Message-ID: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> Hello, I'm using the version 3.2.3 of Python and I am having an issue in my program and I don't know how to fix it: counterLabel["text"] = str(counter) NameError: global name 'counterLabel' is not defined Here is my program: from tkinter import * class CounterButton(Button): def __init__(self, window): super(CounterButton,self).__init__(window, text = "0", command=self.startCounter) def startCounter(self): counter = int(self["text"]) counter +=1 counterLabel["text"] = str(counter) window = Tk() window.title("counter") counterButton1 = CounterButton(window) counterButton2 = CounterButton(window) counterButton1.pack() counterButton1.pack() window.mainloop() From davea at davea.name Thu Mar 21 20:24:17 2013 From: davea at davea.name (Dave Angel) Date: Thu, 21 Mar 2013 20:24:17 -0400 Subject: Global NameError Fix? In-Reply-To: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> References: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> Message-ID: <514BA4B1.9050306@davea.name> On 03/21/2013 07:43 PM, maiden129 wrote: > Hello, > > I'm using the version 3.2.3 of Python and I am having an issue in my program and I don't know how to fix it: > > counterLabel["text"] = str(counter) > NameError: global name 'counterLabel' is not defined > Please include the entire traceback when reporting an exception. In this case, we can figure it out, but frequently we can't. > Here is my program: > > from tkinter import * > > > class CounterButton(Button): > > def __init__(self, window): > > > super(CounterButton,self).__init__(window, text = "0", command=self.startCounter) > > > def startCounter(self): > counter = int(self["text"]) > counter +=1 > counterLabel["text"] = str(counter) Where did you think counterLabel was defined? It needs to be a dict or equivalent, in order for you to use the ["text"] notation on it. If it's supposed to be an attribute of the CounterButton, then you should create it in the __init__() method, as self.counterLabel = {} And if it's supposed to be inherited from Button (unlikely, with that name), presumably it's initialized there. In either case, if it's supposed to be specific to this instance of CounterButton, you need the self. prefix: self.counterLabel["text"] = ... I don't use tkinter, and it's not installed in my Python, but I suspect that it is in the Button object, and it's called something else, like text. Based on a quick internet search, I might try something like: self.config(text= str(counter)) This is assuming you actually wanted to change the text on the button itself. You may well want to change something else in your GUI. > > window = Tk() > window.title("counter") > > > counterButton1 = CounterButton(window) > counterButton2 = CounterButton(window) > > > counterButton1.pack() > counterButton1.pack() > > > window.mainloop() > -- DaveA From drobinow at gmail.com Thu Mar 21 21:04:14 2013 From: drobinow at gmail.com (David Robinow) Date: Thu, 21 Mar 2013 21:04:14 -0400 Subject: Global NameError Fix? In-Reply-To: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> References: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> Message-ID: On Thu, Mar 21, 2013 at 7:43 PM, maiden129 wrote: > Hello, > > I'm using the version 3.2.3 of Python and I am having an issue in my program and I don't know how to fix it: > > counterLabel["text"] = str(counter) > NameError: global name 'counterLabel' is not defined > > Here is my program: > > from tkinter import * > class CounterButton(Button): > def __init__(self, window): > super(CounterButton,self).__init__(window, text = "0", command=self.startCounter) > > def startCounter(self): > counter = int(self["text"]) > counter +=1 > counterLabel["text"] = str(counter) This should be: self["text"] = str(counter) > > window = Tk() > window.title("counter") ... From rantingrickjohnson at gmail.com Fri Mar 22 13:21:08 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 22 Mar 2013 10:21:08 -0700 (PDT) Subject: Global NameError Fix? In-Reply-To: References: <44451203-05be-4336-9325-c956b0ee2116@googlegroups.com> Message-ID: On Thursday, March 21, 2013 7:24:17 PM UTC-5, Dave Angel wrote: > On 03/21/2013 07:43 PM, maiden129 wrote: > > Hello, > > > I'm using the version 3.2.3 of Python and I am having an > > issue in my program and I don't know how to fix it: > > > counterLabel["text"] = str(counter) > > NameError: global name 'counterLabel' is not defined > > [...] > > Where did you think counterLabel was defined? It needs to > be a dict or equivalent, in order for you to use the > ["text"] notation on it. If it's supposed to be an > attribute of the CounterButton, then you should create it > in the __init__() method, as > > self.counterLabel = {} The decision by the Tkinter designer to allow the syntactic sugar of "__setitem__" for configuring a Tkinter widget is unfortunate. And it's not unfortunate /solely/ because of it's detrimental propagation of a well established "sugar" for "list indexing" and "dict key resolution", but compounded by the fact that misunderstands will abound from having more than one way (and preferably only one way!) of doing something. widget.configure(key=value) widget['key'] = value ...and then, when you thought the API could not get any worse, they went and created an alias for "configure": widget.config(key=value) ...are three tiny little letters really enough to justify injecting multiplicity into your API? REALLY? Same foolishness goes for fetching values: value = widget['key'] value = widget.cget(key) And whilst they spared us the multiplicity of a short and long form, their choice of "cget" does not play well with "configure" or "config". Here's a free tutorial for all you "API designers" out there: If you want to be concise, whilst simultaneously maintain consistency between getters and setters, and you're an enemy of multiplicity, then you would want to create this API: value = widget.cget(key) widget.cset(key=value) ... where "cget" is short for "configuration_get" and "cset" is short for...oh gawd! DO I REALLY NEED TO TYPE THIS OUT FOR YOU PEOPLE!!! *school-bell* From jtindbaek at gmail.com Fri Mar 22 10:10:28 2013 From: jtindbaek at gmail.com (jtindbaek at gmail.com) Date: Fri, 22 Mar 2013 07:10:28 -0700 (PDT) Subject: how to implement HTML block page Message-ID: <65772a3e-1ad4-4bff-af97-0b093a77c452@googlegroups.com> Hi, I am currently creating a Web proxy in python. I need to implement an URL blacklist. Once the user requests an URL on the blacklist I need to return a HTML blockpage in the browser. Any suggestions on how to implement that ?. Regards, Jens From bv4bv4bv4 at gmail.com Fri Mar 22 10:38:29 2013 From: bv4bv4bv4 at gmail.com (BV BV) Date: Fri, 22 Mar 2013 07:38:29 -0700 (PDT) Subject: The Qur'an Leads The Way To Science Message-ID: The Qur'an Leads The Way To Science http://www.youtube.com/watch?v=TpwPBd9dmpk thank you From roy at panix.com Fri Mar 22 12:01:08 2013 From: roy at panix.com (Roy Smith) Date: 22 Mar 2013 12:01:08 -0400 Subject: MySQL database schema discovery Message-ID: What are my options for MySQL schema discovery? I want to be able to find all the tables in a database, and discover the names and types of each column (i.e. the standard schema discovery stuff). PEP 249 doesn't seem to have any discovery methods. Nor does MySQLdb appear to have any non-standard extentions for this. I could probably do this with SQLAlchemy, but I'm trying to avoid that because it's so heavyweight. Is there anything else I should be considering? From mail at timgolden.me.uk Fri Mar 22 12:09:59 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 22 Mar 2013 16:09:59 +0000 Subject: MySQL database schema discovery In-Reply-To: References: Message-ID: <514C8257.7010307@timgolden.me.uk> On 22/03/2013 16:01, Roy Smith wrote: > What are my options for MySQL schema discovery? I want to be able to > find all the tables in a database, and discover the names and types of > each column (i.e. the standard schema discovery stuff). > > PEP 249 doesn't seem to have any discovery methods. Nor does MySQLdb > appear to have any non-standard extentions for this. I could probably > do this with SQLAlchemy, but I'm trying to avoid that because it's so > heavyweight. > MySQL appears to support the standard(ish) INFORMATION_SCHEMA schema: http://dev.mysql.com/doc/refman/5.0/en/information-schema.html TJG From l.selmi at icloud.com Fri Mar 22 13:06:18 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Fri, 22 Mar 2013 18:06:18 +0100 Subject: how does the % work? Message-ID: <759DD1C4-83A8-4501-9C32-53A5C89D5D49@icloud.com> hi guys i wrote this example : name = raw_input("What is your name?") quest = raw_input("What is your quest?") color = raw_input("What is your favorite color?") print """Ah, so your name is %s, your quest is %s, and your favorite color is %s.""" % (name, quest, color) but i get this error: Traceback (most recent call last): File "/Users/leonardo/print.py", line 5, in favourite color is %s.''') % (name, quest, color) TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' how can i solve it? thanks! From gordon at panix.com Fri Mar 22 13:14:42 2013 From: gordon at panix.com (John Gordon) Date: Fri, 22 Mar 2013 17:14:42 +0000 (UTC) Subject: how does the % work? References: Message-ID: In leonardo selmi writes: > hi guys > i wrote this example : > name = raw_input("What is your name?") > quest = raw_input("What is your quest?") > color = raw_input("What is your favorite color?") > print """Ah, so your name is %s, your quest is %s, > and your favorite color is %s.""" % (name, quest, color) > but i get this error: Traceback (most recent call last): > File "/Users/leonardo/print.py", line 5, in > favourite color is %s.''') % (name, quest, color) > TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' > how can i solve it? Are you sure you've given us the exact code? The printed text doesn't exactly match. ("favorite" vs. "favourite", three double-quotes vs three single-quotes, etc.) The error message also says that the print statement has a close-parenthesis after the string and before the arguments, which may be real problem. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From rantingrickjohnson at gmail.com Fri Mar 22 14:06:26 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 22 Mar 2013 11:06:26 -0700 (PDT) Subject: how does the % work? In-Reply-To: References: Message-ID: <6a09ed34-7c73-4ea1-82da-f6bc99d47e8a@googlegroups.com> On Friday, March 22, 2013 12:06:18 PM UTC-5, leonardo selmi wrote: > hi guys > > i wrote this example : > > name = raw_input("What is your name?") > quest = raw_input("What is your quest?") > color = raw_input("What is your favorite color?") > > print """Ah, so your name is %s, your quest is %s, > and your favorite color is %s.""" % (name, quest, color) > > but i get this error: Traceback (most recent call last): > File "/Users/leonardo/print.py", line 5, in > favourite color is %s.''') % (name, quest, color) > TypeError: unsupported operand type(s) for %: 'NoneType' > and 'tuple' > > how can i solve it? I would advise as your first course of action to invoke your own problem solving skills. Let's break your code down into two distinct parts. 1. ask the user three questions 2. pass the three responses into a string formatting operation. Anytime you have inputs that are breaking some functionality (and I'm not sure if these inputs ARE breaking anything), then you need to *test* those inputs before just *blindly* passing them off to other code. This means you need to do two tests. 1. Find out what possible responses could be a result of raw_input. This is difficult, because the user could enter anything, even NOTHING. Remember: "Fools are too cleaver!". Normally user input requires some sort of validation. If you just echoing the input, probably not, but in the real world you will need to verify that you are not dealing with a loony. 2. Inject some known values into the string format operation to insure your syntax and expectations are correct. But most importantly, run the code and observe the Exception message. The exception was a gift from the creators of Python, just as pain is a gift from your creator. From timr at probo.com Sat Mar 23 00:29:48 2013 From: timr at probo.com (Tim Roberts) Date: Fri, 22 Mar 2013 21:29:48 -0700 Subject: how does the % work? References: Message-ID: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> leonardo selmi wrote: > >i wrote this example : > >name = raw_input("What is your name?") >quest = raw_input("What is your quest?") >color = raw_input("What is your favorite color?") > >print """Ah, so your name is %s, your quest is %s, >and your favorite color is %s.""" % (name, quest, color) No, you didn't. You wrote: print('''Ah, so your name is %s, your quest is %s, and your favorite color is %s.''') % (name, quest, color) >but i get this error: Traceback (most recent call last): > File "/Users/leonardo/print.py", line 5, in > favourite color is %s.''') % (name, quest, color) >TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' > >how can i solve it? You are using Python 3. In Python 3, "print" is a function that returns None. So, the error is exactly correct. To fix it, you need to have the % operator operate on the string, not on the result of the "print" function: print('''Ah, so your name is %s, your quest is %s, and your favorite color is %s.''' % (name, quest, color)) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rantingrickjohnson at gmail.com Sat Mar 23 03:04:07 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 23 Mar 2013 00:04:07 -0700 (PDT) Subject: how does the % work? In-Reply-To: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> Message-ID: <638fe2c5-0b77-4236-9592-b8c0d76ce5da@googlegroups.com> On Friday, March 22, 2013 11:29:48 PM UTC-5, Tim Roberts wrote: > You are using Python 3. In Python 3, "print" is a function that returns > None. So, the error is exactly correct. Wait a second... if he is in-fact using Python 3, then why did the call to a non-existent function named "raw_input" not throw an error first? Not to mention THREE calls to a non-existent function named "raw_input"! Hmm, my guess is that the python interpreter was too busy gossiping about that overblown sexual harassment BS at PyCon to even notice. From steve+comp.lang.python at pearwood.info Sat Mar 23 03:38:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2013 07:38:23 GMT Subject: how does the % work? References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> Message-ID: <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Mar 2013 21:29:48 -0700, Tim Roberts wrote: > leonardo selmi wrote: >> >>i wrote this example : >> >>name = raw_input("What is your name?") >>quest = raw_input("What is your quest?") >>color = raw_input("What is your favorite color?") >> >>print """Ah, so your name is %s, your quest is %s, and your favorite >>color is %s.""" % (name, quest, color) > > No, you didn't. You wrote: > > print('''Ah, so your name is %s, your quest is %s, and your > favorite color is %s.''') % (name, quest, color) The difference between those two statements may not be entirely clear to someone not experienced in reading code carefully. Consider the difference between: print(a % b) print(a) % b In the first example, the round brackets group the "a % b", which is calculated first, then printed. In the second example, in Python 3, the "print(a)" is called first, which returns None, and then "None % b" is calculated, which raises an exception. Just to add confusion, the two lines are exactly the same in Python 2, where Print is not a function! > You are using Python 3. In Python 3, "print" is a function that returns > None. So, the error is exactly correct. To fix it, you need to have > the % operator operate on the string, not on the result of the "print" > function: > > print('''Ah, so your name is %s, your quest is %s, and your > favorite color is %s.''' % (name, quest, color)) Exactly correct. -- Steven From rantingrickjohnson at gmail.com Sat Mar 23 03:57:19 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 23 Mar 2013 00:57:19 -0700 (PDT) Subject: how does the % work? In-Reply-To: <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <45a8f2c2-a9e6-4388-96a9-c0a17a25bb7b@googlegroups.com> On Saturday, March 23, 2013 2:38:23 AM UTC-5, Steven D'Aprano wrote: > On Fri, 22 Mar 2013 21:29:48 -0700, Tim Roberts wrote: > > print('''Ah, so your name is %s, your quest is %s, and your > > favorite color is %s.''') % (name, quest, color) > > The difference between those two statements may not be entirely clear to > someone not experienced in reading code carefully. I think the main problem with the code the OP presented is his attempt to stuff a long string literal into the print function. He should have separated the format string from the format operation: py> fmtstr = '''Ah, so your name is %s, your quest is %s, and your favorite color is %s.''' py> print(fmtstr%(1,2,3)) Ah, so your name is 1, your quest is 2, and your favorite color is 3. Sorry but i was too lazy to type out three string literal arguments, and instead, I reached for the low hanging syntactical sweetness of the integer peach. Mmm peaches! From torriem at gmail.com Sat Mar 23 11:57:48 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Mar 2013 09:57:48 -0600 Subject: how does the % work? In-Reply-To: <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514DD0FC.2090104@gmail.com> On 03/23/2013 01:38 AM, Steven D'Aprano wrote: > Just to add confusion, the two lines are exactly the same in Python 2, > where Print is not a function! Perhaps this is a good reason use the slightly more complicated but easier to get right format method. print ("{0}, {1}, {2}".format(1,2,3)) And it's worth noting that using the string formatter or the old % operator on a string works anywhere where there're strings, not just in the print function. b = "The answer was %d" % answer or b = "The answer was {0}".format(answer) On the topic of print, I can see the logic in print being a function now, but I have always preferred it as a print statement; it just looked cleaner. That was one of the things that initially attracted me to python. But the reality is print isn't used for much in real programs other than console debug messages. From tampucciolina at libero.it Sat Mar 23 13:05:20 2013 From: tampucciolina at libero.it (leonardo) Date: Sat, 23 Mar 2013 18:05:20 +0100 Subject: how does the % work? In-Reply-To: <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514DE0D0.3060504@libero.it> thank you all! Il 23/03/2013 8.38, Steven D'Aprano ha scritto: > On Fri, 22 Mar 2013 21:29:48 -0700, Tim Roberts wrote: > >> leonardo selmi wrote: >>> i wrote this example : >>> >>> name = raw_input("What is your name?") >>> quest = raw_input("What is your quest?") >>> color = raw_input("What is your favorite color?") >>> >>> print """Ah, so your name is %s, your quest is %s, and your favorite >>> color is %s.""" % (name, quest, color) >> No, you didn't. You wrote: >> >> print('''Ah, so your name is %s, your quest is %s, and your >> favorite color is %s.''') % (name, quest, color) > > The difference between those two statements may not be entirely clear to > someone not experienced in reading code carefully. > > Consider the difference between: > > print(a % b) > > print(a) % b > > In the first example, the round brackets group the "a % b", which is > calculated first, then printed. > > In the second example, in Python 3, the "print(a)" is called first, which > returns None, and then "None % b" is calculated, which raises an > exception. > > Just to add confusion, the two lines are exactly the same in Python 2, > where Print is not a function! > > >> You are using Python 3. In Python 3, "print" is a function that returns >> None. So, the error is exactly correct. To fix it, you need to have >> the % operator operate on the string, not on the result of the "print" >> function: >> >> print('''Ah, so your name is %s, your quest is %s, and your >> favorite color is %s.''' % (name, quest, color)) > Exactly correct. > > > From steve+comp.lang.python at pearwood.info Sat Mar 23 19:53:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2013 23:53:00 GMT Subject: how does the % work? References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514e405c$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Mar 2013 09:57:48 -0600, Michael Torrie wrote: > On 03/23/2013 01:38 AM, Steven D'Aprano wrote: >> Just to add confusion, the two lines are exactly the same in Python 2, >> where Print is not a function! > > Perhaps this is a good reason use the slightly more complicated but > easier to get right format method. > > print ("{0}, {1}, {2}".format(1,2,3)) Misplaced parentheses are possible either way. print ("{0}, {1}, {2}".format(1,2,3)) print ("{0}, {1}, {2}").format(1,2,3) > And it's worth noting that using the string formatter or the old % > operator on a string works anywhere where there're strings, not just in > the print function. Very true. -- Steven From timr at probo.com Sun Mar 24 19:35:08 2013 From: timr at probo.com (Tim Roberts) Date: Sun, 24 Mar 2013 16:35:08 -0700 Subject: how does the % work? References: <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5d3vk8h6tvh0dh22f8ejk570gptdgho7tg@4ax.com> leonardo wrote: > >thank you all! So, what was the problem? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bgailer at gmail.com Fri Mar 22 13:31:49 2013 From: bgailer at gmail.com (bob gailer) Date: Fri, 22 Mar 2013 13:31:49 -0400 Subject: [Python-Help] how does the % work? In-Reply-To: <759DD1C4-83A8-4501-9C32-53A5C89D5D49@icloud.com> References: <759DD1C4-83A8-4501-9C32-53A5C89D5D49@icloud.com> Message-ID: <514C9585.9020504@gmail.com> It is better to post to just one list at a time. On 3/22/2013 1:06 PM, leonardo selmi wrote: > name = raw_input("What is your name?") > quest = raw_input("What is your quest?") > color = raw_input("What is your favorite color?") > > print """Ah, so your name is %s, your quest is %s, > and your favorite color is %s.""" % (name, quest, color) Runs OK for me! The traceback does not match the code. Please post the code that actually generated this: File "/Users/leonardo/print.py", line 5, in favourite color is %s.''') % (name, quest, color) TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' -- Bob Gailer 919-636-4239 Chapel Hill NC From steve at danda.com.mt Fri Mar 22 13:11:32 2013 From: steve at danda.com.mt (Steve DeMicoli) Date: Fri, 22 Mar 2013 18:11:32 +0100 Subject: Python IDLE Message-ID: <411B28C85C3FD5459B63AE9F79125EE802A86405100E@astun.danda.local> Dear Sir, Madame, I am having trouble starting up IDLE. I have found threads with similar stories, however I haven't managed to solve mine. basically: I have installed both python 2.7 and python 3 on windows 7 both IDLEs used to work tried running program in command bar and still nothing tried making exception from anti-virus computer. ( i am using AVG) no errors come up, program just doesn't start. Your help would be greatly appreciated. Kind regards, Steve The information in this email and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient please notify the sender immediately using the sender email address and delete this email. You should not read or copy this e-mail, use it for any purpose, disseminate it or disclose its contents to any other person. Note that any possible personal views or opinions presented in this email are solely those of the author and do not necessarily represent those of DeMicoli & Associates as this may be contrary to the firm policy and outside the scope of the employment of the individual concerned. DeMicoli & Associates will not accept any liability in respect of such communication. Although DeMicoli & Associates has taken reasonable precautions to ensure no viruses are present in this email, the firm cannot accept responsibility for any loss or damage arising from the use of this email or attachments. Moreover, communication via email over the internet is not secure and messages may be read, manipulated or otherwise compromised by unknown third parties. DeMicoli & Associates does not accept any responsibility for the correctness and completeness of the transfer of information contained in such communication nor for any delay of receipt. From rantingrickjohnson at gmail.com Fri Mar 22 13:42:47 2013 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 22 Mar 2013 10:42:47 -0700 (PDT) Subject: Python IDLE In-Reply-To: References: Message-ID: On Friday, March 22, 2013 12:11:32 PM UTC-5, Steve DeMicoli wrote: > Dear Sir, Madame, > > [...message body removed for fear of legal reprisals...] > > The information in this email and any attachments are > confidential and intended solely for the use of the > individual or entity to whom they are addressed. If you > are not the intended recipient please notify the sender > immediately using the sender email address and delete this > email. You should not read or copy this e-mail, use it > for any purpose, disseminate it or disclose its contents > to any other person. Note that any possible personal > views or opinions presented in this email are solely those > of the author and do not necessarily represent those of > DeMicoli & Associates as this may be contrary to the firm > policy and outside the scope of the employment of the > individual concerned. DeMicoli & Associates will not > accept any liability in respect of such communication. > > Although DeMicoli & Associates has taken reasonable > precautions to ensure no viruses are present in this > email, the firm cannot accept responsibility for any loss > or damage arising from the use of this email or > attachments. Moreover, communication via email over the > internet is not secure and messages may be read, > manipulated or otherwise compromised by unknown third > parties. DeMicoli & Associates does not accept any > responsibility for the correctness and completeness of the > transfer of information contained in such communication > nor for any delay of receipt. I just love when people send "private" messages to *public* newsgroups, and then have the audacity to include a legal statement asking us to keep the message private. You folks really have a sense of humor. From steve+comp.lang.python at pearwood.info Fri Mar 22 20:08:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2013 00:08:33 GMT Subject: Python IDLE References: Message-ID: <514cf280$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Mar 2013 18:11:32 +0100, Steve DeMicoli wrote: > Dear Sir, Madame, > > I am having trouble starting up IDLE. You say below that "both" IDLE's used to work. So what have you done to change the situation? What's different? > I have found threads with similar stories, however I haven't managed to > solve mine. > > basically: > > I have installed both python 2.7 and python 3 on windows 7 both IDLEs > used to work Great! Then you know that you can have both Python 2.7 and Python 3 running IDLE on Windows 7 successfully. > tried running program in command bar and still nothing What do you mean? Can you explain *precisely* what you did, and what happened? E.g. "I clicked on the Start Menu, then clicked on X, then clicked on Y, then the computer went dark and turned off" ... or something. I see from your email disclaimer that you are emailing from a company. Does your company have a Windows system administrator? If so, perhaps he or she could shed some light on what's going on? (I don't use Windows, so I'm a little lost myself.) Good luck! -- Steven From rolandrog at comcast.net Fri Mar 22 13:34:08 2013 From: rolandrog at comcast.net (Roger Cox) Date: Fri, 22 Mar 2013 12:34:08 -0500 Subject: INSTRUCTOR SOLUTIONS MANUAL Message-ID: <001101ce2723$75d9f500$618ddf00$@comcast.net> Do you have the Instructor Solutions Manual for these two text books? Fundamentals of Fluid Mechanics, 5th Edtion, Munson, young, Okiishi Chemical Engineering Fluid Mechanics, 2nd Edition, Ron Darby Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan-A at T-prox.be Fri Mar 22 14:13:50 2013 From: jan-A at T-prox.be (Jan) Date: Fri, 22 Mar 2013 19:13:50 +0100 Subject: How to use multiple instances of the same COM object at the same time Message-ID: Dear Usenet readers, Our company wants to implement about 40 biometric access control devices which have a proprietary DLL with a COM object in it. I've done some research about COM objects and how to use them. Now, I need to connect to every device separately and register for real time events. So, I need about 40 instances of the COM object simultaneously connected and registered to catch all events of all devices. I assumed I needed threading for this, and I have done a simple implementation. All I want to ask is: Does anybody see something that I could have done in a better way? I'm new to COM objects in Python! The program runs fine, it is very basic and I tested it with 3 devices connected at the same time. In production this will be 40! Thanks in advance Jan Source code: # Based on eventappartmentthreading from the win32com demo import sys, os, time import win32com.client import win32api import win32event # sys.coinit_flags not set, so pythoncom initializes apartment-threaded. import pythoncom from threading import Thread threadlist = dict() # this stores the device ids # using the threadid as the key field class ZkEvents: def __init__(self): self.event = win32event.CreateEvent(None, 0, 0, None) thread = win32api.GetCurrentThreadId() print "thread %s " % thread self.dev_id = threadlist[thread] print "Thread Connected For ID %s " % self.dev_id def OnFinger(self): print self.dev_id, print "OnFinger" def OnVerify(self, iUserID=pythoncom.Empty): print self.dev_id, print "OnVerify: %s" % iUserID def OnKeyPress(self, iKey=pythoncom.Empty): print self.dev_id, print "KeyPress: %s" % iKey def WaitWhileProcessingMessages(event, timeout = 60): start = time.clock() while True: # Wake 4 times a second - we can't just specify the # full timeout here, as then it would reset for every # message we process. rc = win32event.MsgWaitForMultipleObjects( (event,), 0, 250, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: # event signalled - stop now! return True if (time.clock() - start) > timeout: # Timeout expired. return False # must be a message. pythoncom.PumpWaitingMessages() def TestZkEvents(ip, dev_id): thread = win32api.GetCurrentThreadId() print 'TestZkEvents created ZK object on thread %d'%thread threadlist[thread] = dev_id pythoncom.CoInitialize() zk = win32com.client.DispatchWithEvents("zkemkeeper.ZKEM", ZkEvents) if zk.Connect_Net(ip, 4370): print "Connect %s OK" % ip else: print "Connect %s Failed" % ip try: if zk.RegEvent(1, 65535): # 65535 = register for all events print "RegEvent %s, %s OK" % (ip, dev_id) else: print "RegEvent %s, %s Failed" % (ip, dev_id) except pythoncom.com_error, details: print "Warning - could not open the test HTML file", details # Wait for the event to be signaled while pumping messages. while True: if not WaitWhileProcessingMessages(zk.event): print "No Events From %s During Last Minute" % dev_id zk = None if __name__=='__main__': # this should be a for loop with database fields... t1 = Thread(target=TestZkEvents, args=('192.168.1.211',40)) t1.start() t2 = Thread(target=TestZkEvents, args=('192.168.1.212',45)) t2.start() t3 = Thread(target=TestZkEvents, args=('192.168.1.213',49)) t3.start() From fogleman at gmail.com Fri Mar 22 15:22:13 2013 From: fogleman at gmail.com (Michael Fogleman) Date: Fri, 22 Mar 2013 12:22:13 -0700 (PDT) Subject: Grouping items by a key? Message-ID: <159cc8e9-f381-42c5-b6cd-8e63bfe78575@googlegroups.com> I feel like Python ought to have a built-in to do this. Take a list of items and turn them into a dictionary mapping keys to a list of items with that key in common. It's easy enough to do: # using defaultdict lookup = collections.defaultdict(list) for item in items: lookup[key(item)].append(item) # or, using plain dict lookup = {} for item in items: lookup.setdefault(key(item), []).append(item) But this is frequent enough of a use case that a built-in function would be nice. I could implement it myself, as such: def grouped(iterable, key): result = {} for item in iterable: result.setdefault(key(item), []).append(item) return result lookup = grouped(items, key) This is different than `itertools.groupby` in a few important ways. To get the same result from `groupby`, you'd have to do this, which is a little ugly: lookup = dict((k, list(v)) for k, v in groupby(sorted(items, key=key), key)) Some examples: >>> items = range(10) >>> grouped(items, lambda x: x % 2) {0: [0, 2, 4, 6, 8], 1: [1, 3, 5, 7, 9]} >>> items = 'hello stack overflow how are you'.split() >>> grouped(items, len) {8: ['overflow'], 3: ['how', 'are', 'you'], 5: ['hello', 'stack']} Is there a better way? From steve+comp.lang.python at pearwood.info Fri Mar 22 20:27:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2013 00:27:00 GMT Subject: Grouping items by a key? References: <159cc8e9-f381-42c5-b6cd-8e63bfe78575@googlegroups.com> Message-ID: <514cf6d4$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Mar 2013 12:22:13 -0700, Michael Fogleman wrote: > I feel like Python ought to have a built-in to do this. Take a list of > items and turn them into a dictionary mapping keys to a list of items > with that key in common. > > It's easy enough to do: > > # using defaultdict > lookup = collections.defaultdict(list) > for item in items: > lookup[key(item)].append(item) > > # or, using plain dict > lookup = {} > for item in items: > lookup.setdefault(key(item), []).append(item) That's pretty much the reason setdefault was invented. So, in a sense, there is a built-in for this. > But this is frequent enough of a use case that a built-in function would > be nice. I'm not so sure I agree it's a frequent use-case. I don't think I've ever needed to do it, or if I did, it was so rare and so long ago that I've forgotten it. > I could implement it myself, as such: > > def grouped(iterable, key): > result = {} > for item in iterable: > result.setdefault(key(item), []).append(item) > return result > > lookup = grouped(items, key) > > This is different than `itertools.groupby` in a few important ways. Why do you care about itertools.groupby? That does something completely different. It groups items that occur in *contiguous* groups, e.g. [1, 2, 3, 2, 2, 2, 3, 3, 4, 5, 5, 2, 2, 5] will be grouped into three separate groups of two: [1], [2], [3], [2, 2, 2], [3, 3], [4], [5, 5], [2, 2], [5] This is a feature of groupby. If you want to accumulate items regardless of where they occur, e.g. for the above: [1], [2, 2, 2, 2, 2, 2], [3, 3, 3], [4], [5, 5, 5] then there's no need to use groupby. > Some examples: > > > >>> items = range(10) > >>> grouped(items, lambda x: x % 2) > {0: [0, 2, 4, 6, 8], 1: [1, 3, 5, 7, 9]} > > >>> items = 'hello stack overflow how are you'.split() > >>> grouped(items, len) > {8: ['overflow'], 3: ['how', 'are', 'you'], 5: ['hello', 'stack']} > > Is there a better way? Looks perfectly fine to me. It's a five line helper function, it's readable and simple and clear. The only improvements I would make would be to give it a doc string describing what it does and showing some examples: def grouped(items, key): """Return a dict with items accumulated by key. >>> items = range(10) >>> grouped(items, lambda x: x % 2) {0: [0, 2, 4, 6, 8], 1: [1, 3, 5, 7, 9]} >>> items = 'hello stack overflow how are you'.split() >>> grouped(items, len) {8: ['overflow'], 3: ['how', 'are', 'you'], 5: ['hello', 'stack']} """ result = {} for item in iterable: result.setdefault(key(item), []).append(item) return result Now you have a nice, descriptive help string for when you call help(grouped). -- Steven From wanderer at dialup4less.com Fri Mar 22 16:26:31 2013 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 22 Mar 2013 13:26:31 -0700 (PDT) Subject: LiClipse Message-ID: I just updated PyDev and I got this message that they are looking for funding for a new flavor of Eclipse called LiClipse. The description of what LiClipse will be is kind of sketchy. No offense intended, but why? There is already a bunch of downloads at Eclipse and there is also Easy Eclipse. The only reason for a redesign of Eclipse, I would want would be change it from being Java based. Oracle is losing money and I wonder what their next business model will be for Java. Anyway, does anyone know what this LiClipse is all about? Thanks From steve+comp.lang.python at pearwood.info Fri Mar 22 19:57:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2013 23:57:21 GMT Subject: LiClipse References: Message-ID: <514cefe0$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Mar 2013 13:26:31 -0700, Wanderer wrote: > I just updated PyDev and I got this message that they are looking for > funding for a new flavor of Eclipse called LiClipse. The description of > what LiClipse will be is kind of sketchy. No offense intended, but why? > There is already a bunch of downloads at Eclipse and there is also Easy > Eclipse. The only reason for a redesign of Eclipse, I would want would > be change it from being Java based. Oracle is losing money and I wonder > what their next business model will be for Java. Anyway, does anyone > know what this LiClipse is all about? No idea. Who did you get the message from? Perhaps you should ask them. Or ask on an Eclipse forum. Or try googling for "Liclipse", which brings me to this: http://www.indiegogo.com/projects/pydev-and-liclipse-for-a-fast-sexy-and- dark-eclipse -- Steven From tdldev at gmail.com Fri Mar 22 21:01:14 2013 From: tdldev at gmail.com (Verde Denim) Date: Fri, 22 Mar 2013 21:01:14 -0400 Subject: LiClipse In-Reply-To: References: Message-ID: <514CFEDA.4030903@gmail.com> On 03/22/2013 04:26 PM, Wanderer wrote: > I just updated PyDev and I got this message that they are looking for funding for a new flavor of Eclipse called LiClipse. The description of what LiClipse will be is kind of sketchy. No offense intended, but why? There is already a bunch of downloads at Eclipse and there is also Easy Eclipse. The only reason for a redesign of Eclipse, I would want would be change it from being Java based. Oracle is losing money and I wonder what their next business model will be for Java. Anyway, does anyone know what this LiClipse is all about? > > Thanks Check this - http://www.indiegogo.com/projects/pydev-and-liclipse-for-a-fast-sexy-and-dark-eclipse described as a toolchain with plugins and a sleek UI for Eclipse; sounds like a fork... -- Regards Jack Boston Tea Party, Coercive Acts, Powder Alarm, Revolution Lessons (mistakes) not learned are bound to be repeated. From fabiofz at gmail.com Fri Mar 22 22:58:56 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 22 Mar 2013 23:58:56 -0300 Subject: LiClipse In-Reply-To: <514CFEDA.4030903@gmail.com> References: <514CFEDA.4030903@gmail.com> Message-ID: Hello there, As I've proposed it, let me try to explain it a bit better (if you have doubts, I should probably rephrase the proposal). There are 2 main targets there: keeping PyDev properly supported (which hopefully doesn't need more explanation) and creating LiClipse. The idea for LiClipse is definitely not making a fork, but having an easier way to add a basic editor inside Eclipse (while developing PyDev, I do get many requests for adding support for editors related to Python, such as Django templates, Mako, Restructured text, Cython, etc), so, this will provide me with a basis to do that (and with the basis in place, the idea is having the possibility of creating an editor without knowledge of Eclipse and in a very fast way -- current technologies for that such as DLTK or XText aim much higher and are not trivial. I really want to have a way to have a basic editor inside Eclipse just specifying the language very 'loosely' -- say, something that'd take you 15-30 minutes and almost no special knowledge of Eclipse internals -- and which would need more knowledge of Eclipse internals only for more advanced stuff). As for the dark theme, it's something that annoys me a lot (so, I was hoping it was also something interesting for other people -- right now, it's not possible to have a professional dark theme in Eclipse, there are many loose ends -- so, for those that would like to work with a dark theme -- as myself -- it may be very annoying -- although yes, it may not be applicable if you're happy with the current non-dark UI). As for distributions, yes, I plan to do an Eclipse distribution with LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as it is NOT supported (it has an ancient version of PyDev which only serves to confuse users and Eclipse.org does not have a Python version with PyDev). I'd hardly call that a fork thought (and it should be possible to install it as a separate plugin anyways, so, you can use the Eclipse you got from anywhere and just use the update site to get those plugins). Cheers, Fabio On Fri, Mar 22, 2013 at 10:01 PM, Verde Denim wrote: > On 03/22/2013 04:26 PM, Wanderer wrote: > > I just updated PyDev and I got this message that they are looking for > funding for a new flavor of Eclipse called LiClipse. The description of > what LiClipse will be is kind of sketchy. No offense intended, but why? > There is already a bunch of downloads at Eclipse and there is also Easy > Eclipse. The only reason for a redesign of Eclipse, I would want would be > change it from being Java based. Oracle is losing money and I wonder what > their next business model will be for Java. Anyway, does anyone know what > this LiClipse is all about? > > > > Thanks > Check this - > > http://www.indiegogo.com/projects/pydev-and-liclipse-for-a-fast-sexy-and-dark-eclipse > described as a toolchain with plugins and a sleek UI for Eclipse; sounds > like a fork... > > -- > Regards > > Jack > Boston Tea Party, Coercive Acts, Powder Alarm, Revolution > Lessons (mistakes) not learned are bound to be repeated. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Mar 22 23:38:34 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 22 Mar 2013 20:38:34 -0700 (PDT) Subject: LiClipse References: <514CFEDA.4030903@gmail.com> Message-ID: <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> On Mar 23, 7:58?am, Fabio Zadrozny wrote: > Hello there, > > As I've proposed it, let me try to explain it a bit better (if you have > doubts, I should probably rephrase the proposal). > > There are 2 main targets there: keeping PyDev properly supported (which > hopefully doesn't need more explanation) and creating LiClipse. > > The idea for LiClipse is definitely not making a fork, but having an easier > way to add a basic editor inside Eclipse (while developing PyDev, I do get > many requests for adding support for editors related to Python, such as > Django templates, Mako, Restructured text, Cython, etc), so, this will > provide me with a basis to do that (and with the basis in place, the idea > is having the possibility of creating an editor without knowledge of > Eclipse and in a very fast way -- current technologies for that such as > DLTK or XText aim much higher and are not trivial. I really want to have a > way to have a basic editor inside Eclipse just specifying the language very > 'loosely' -- say, something that'd take you 15-30 minutes and almost no > special knowledge of Eclipse internals -- and which would need more > knowledge of Eclipse internals only for more advanced stuff). > > As for the dark theme, it's something that annoys me a lot (so, I was > hoping it was also something interesting for other people -- right now, > it's not possible to have a professional dark theme in Eclipse, there are > many loose ends -- so, for those that would like to work with a dark theme > -- as myself -- it may be very annoying -- although yes, it may not be > applicable if you're happy with the current non-dark UI). > > As for distributions, yes, I plan to do an Eclipse distribution with > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as it > is NOT supported (it has an ancient version of PyDev which only serves to > confuse users and Eclipse.org does not have a Python version with PyDev). > I'd hardly call that a fork thought (and it should be possible to install > it as a separate plugin anyways, so, you can use the Eclipse you got from > anywhere and just use the update site to get those plugins). > > Cheers, > > Fabio I am interested in the new eclipse plugin capabilities. Where does liclipse stand with respect to this? ie Eclipse-4 claims to have made plugin development (for new custom languages) easier. What is the relation of liclipse to eclipse 3<->4 plugin architecture? From fabiofz at gmail.com Sat Mar 23 07:11:10 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sat, 23 Mar 2013 08:11:10 -0300 Subject: LiClipse In-Reply-To: <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> Message-ID: On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > On Mar 23, 7:58 am, Fabio Zadrozny wrote: > > Hello there, > > > > As I've proposed it, let me try to explain it a bit better (if you have > > doubts, I should probably rephrase the proposal). > > > > There are 2 main targets there: keeping PyDev properly supported (which > > hopefully doesn't need more explanation) and creating LiClipse. > > > > The idea for LiClipse is definitely not making a fork, but having an > easier > > way to add a basic editor inside Eclipse (while developing PyDev, I do > get > > many requests for adding support for editors related to Python, such as > > Django templates, Mako, Restructured text, Cython, etc), so, this will > > provide me with a basis to do that (and with the basis in place, the idea > > is having the possibility of creating an editor without knowledge of > > Eclipse and in a very fast way -- current technologies for that such as > > DLTK or XText aim much higher and are not trivial. I really want to have > a > > way to have a basic editor inside Eclipse just specifying the language > very > > 'loosely' -- say, something that'd take you 15-30 minutes and almost no > > special knowledge of Eclipse internals -- and which would need more > > knowledge of Eclipse internals only for more advanced stuff). > > > > As for the dark theme, it's something that annoys me a lot (so, I was > > hoping it was also something interesting for other people -- right now, > > it's not possible to have a professional dark theme in Eclipse, there are > > many loose ends -- so, for those that would like to work with a dark > theme > > -- as myself -- it may be very annoying -- although yes, it may not be > > applicable if you're happy with the current non-dark UI). > > > > As for distributions, yes, I plan to do an Eclipse distribution with > > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as > it > > is NOT supported (it has an ancient version of PyDev which only serves to > > confuse users and Eclipse.org does not have a Python version with PyDev). > > I'd hardly call that a fork thought (and it should be possible to install > > it as a separate plugin anyways, so, you can use the Eclipse you got from > > anywhere and just use the update site to get those plugins). > > > > Cheers, > > > > Fabio > > I am interested in the new eclipse plugin capabilities. > Where does liclipse stand with respect to this? > The idea is providing a way to add a language just by saying things like keywords, elements (such as function or class -- if your language has that), indenting words and it'll provide you an editor that has all the common functions you'd expect, such as syntax highlighting, outline, indenting, template completion, etc. So, in LiClipse, you shouldn't need to create a plugin at this level, just one configuration file (which you should be able to fill in 15-30 minutes). After that, if you want more things (such as code analysis or a semantic aware code completion), then you'd have to go the route of actually creating an Eclipse plugin. > ie Eclipse-4 claims to have made plugin development (for new custom > languages) easier. > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > Well, it may have become a bit easier (with dltk and xtext), but it's still far from trivial (you still have to know at least java, how plugins work, eclipse internals, creating a grammar, etc.). The editors structure for LiClipse should work in both Eclipse 3 or 4, although the theming enhancements will require Eclipse 4 (as it'll need some features only available there). Cheers, Fabio -------------- next part -------------- An HTML attachment was scrubbed... URL: From wanderer at dialup4less.com Sat Mar 23 11:07:07 2013 From: wanderer at dialup4less.com (Wanderer) Date: Sat, 23 Mar 2013 08:07:07 -0700 (PDT) Subject: LiClipse In-Reply-To: References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> Message-ID: On Saturday, March 23, 2013 7:11:10 AM UTC-4, Fabio Zadrozny wrote: > On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > > > > > On Mar 23, 7:58?am, Fabio Zadrozny wrote: > > > > > Hello there, > > > > > > As I've proposed it, let me try to explain it a bit better (if you have > > > doubts, I should probably rephrase the proposal). > > > > > > There are 2 main targets there: keeping PyDev properly supported (which > > > hopefully doesn't need more explanation) and creating LiClipse. > > > > > > The idea for LiClipse is definitely not making a fork, but having an easier > > > way to add a basic editor inside Eclipse (while developing PyDev, I do get > > > many requests for adding support for editors related to Python, such as > > > Django templates, Mako, Restructured text, Cython, etc), so, this will > > > provide me with a basis to do that (and with the basis in place, the idea > > > is having the possibility of creating an editor without knowledge of > > > Eclipse and in a very fast way -- current technologies for that such as > > > DLTK or XText aim much higher and are not trivial. I really want to have a > > > way to have a basic editor inside Eclipse just specifying the language very > > > 'loosely' -- say, something that'd take you 15-30 minutes and almost no > > > special knowledge of Eclipse internals -- and which would need more > > > knowledge of Eclipse internals only for more advanced stuff). > > > > > > As for the dark theme, it's something that annoys me a lot (so, I was > > > hoping it was also something interesting for other people -- right now, > > > it's not possible to have a professional dark theme in Eclipse, there are > > > many loose ends -- so, for those that would like to work with a dark theme > > > -- as myself -- it may be very annoying -- although yes, it may not be > > > applicable if you're happy with the current non-dark UI). > > > > > > As for distributions, yes, I plan to do an Eclipse distribution with > > > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as it > > > is NOT supported (it has an ancient version of PyDev which only serves to > > > confuse users and Eclipse.org does not have a Python version with PyDev). > > > I'd hardly call that a fork thought (and it should be possible to install > > > it as a separate plugin anyways, so, you can use the Eclipse you got from > > > anywhere and just use the update site to get those plugins). > > > > > > Cheers, > > > > > > Fabio > > > > I am interested in the new eclipse plugin capabilities. > > Where does liclipse stand with respect to this? > > > > The idea is providing a way to add a language just by saying things like keywords, elements (such as function or class -- if your language has that), indenting words and it'll provide you an editor that has all the common functions you'd expect, such as syntax highlighting, outline, indenting, template completion, etc. So, in LiClipse, you shouldn't need to create a plugin at this level, just one configuration file (which you should be able to fill in 15-30 minutes). > > > > > After that, if you want more things (such as code analysis or a semantic aware code completion), then you'd have to go the route of actually creating an Eclipse plugin. > ? > > > ie Eclipse-4 claims to have made plugin development (for new custom > > languages) easier. > > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > > > > Well, it may have become a bit easier (with dltk and xtext), but it's still far from trivial (you still have to know at least java, how plugins work, eclipse internals, creating a grammar, etc.). > > > > > The editors structure for LiClipse should work in both Eclipse 3 or 4, although the theming enhancements will require Eclipse 4 (as it'll need some features only available there). > > > > > Cheers, > > > Fabio Thanks for the response. Now I understand better what you're trying to do. Eclipse can be something of a pain to get basic support to use new languages. I never was able to get it to work with Vpascal. I would also like the bundle, since I can't get the version in the lab to work like the version on my desk. I've never been one for dark themes. My pet peeve is the battle over negative numbers between PyDev and pep8.py. PyDev put the space in and pep8.py gives me a warning. Anyway, PyDev deserves my support and thank you for all your hard work. From fabiofz at gmail.com Sat Mar 23 11:39:03 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sat, 23 Mar 2013 12:39:03 -0300 Subject: LiClipse In-Reply-To: References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> Message-ID: On Sat, Mar 23, 2013 at 12:07 PM, Wanderer wrote: > On Saturday, March 23, 2013 7:11:10 AM UTC-4, Fabio Zadrozny wrote: > > On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > > > > > > > > > > On Mar 23, 7:58 am, Fabio Zadrozny wrote: > > > > > > > > > Hello there, > > > > > > > > > > As I've proposed it, let me try to explain it a bit better (if you have > > > > > doubts, I should probably rephrase the proposal). > > > > > > > > > > There are 2 main targets there: keeping PyDev properly supported (which > > > > > hopefully doesn't need more explanation) and creating LiClipse. > > > > > > > > > > The idea for LiClipse is definitely not making a fork, but having an > easier > > > > > way to add a basic editor inside Eclipse (while developing PyDev, I do > get > > > > > many requests for adding support for editors related to Python, such as > > > > > Django templates, Mako, Restructured text, Cython, etc), so, this will > > > > > provide me with a basis to do that (and with the basis in place, the > idea > > > > > is having the possibility of creating an editor without knowledge of > > > > > Eclipse and in a very fast way -- current technologies for that such as > > > > > DLTK or XText aim much higher and are not trivial. I really want to > have a > > > > > way to have a basic editor inside Eclipse just specifying the language > very > > > > > 'loosely' -- say, something that'd take you 15-30 minutes and almost no > > > > > special knowledge of Eclipse internals -- and which would need more > > > > > knowledge of Eclipse internals only for more advanced stuff). > > > > > > > > > > As for the dark theme, it's something that annoys me a lot (so, I was > > > > > hoping it was also something interesting for other people -- right now, > > > > > it's not possible to have a professional dark theme in Eclipse, there > are > > > > > many loose ends -- so, for those that would like to work with a dark > theme > > > > > -- as myself -- it may be very annoying -- although yes, it may not be > > > > > applicable if you're happy with the current non-dark UI). > > > > > > > > > > As for distributions, yes, I plan to do an Eclipse distribution with > > > > > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution > as it > > > > > is NOT supported (it has an ancient version of PyDev which only serves > to > > > > > confuse users and Eclipse.org does not have a Python version with > PyDev). > > > > > I'd hardly call that a fork thought (and it should be possible to > install > > > > > it as a separate plugin anyways, so, you can use the Eclipse you got > from > > > > > anywhere and just use the update site to get those plugins). > > > > > > > > > > Cheers, > > > > > > > > > > Fabio > > > > > > > > I am interested in the new eclipse plugin capabilities. > > > > Where does liclipse stand with respect to this? > > > > > > > > The idea is providing a way to add a language just by saying things like > keywords, elements (such as function or class -- if your language has > that), indenting words and it'll provide you an editor that has all the > common functions you'd expect, such as syntax highlighting, outline, > indenting, template completion, etc. So, in LiClipse, you shouldn't need to > create a plugin at this level, just one configuration file (which you > should be able to fill in 15-30 minutes). > > > > > > > > > > After that, if you want more things (such as code analysis or a semantic > aware code completion), then you'd have to go the route of actually > creating an Eclipse plugin. > > > > > > > > ie Eclipse-4 claims to have made plugin development (for new custom > > > > languages) easier. > > > > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > > > > > > > > Well, it may have become a bit easier (with dltk and xtext), but it's > still far from trivial (you still have to know at least java, how plugins > work, eclipse internals, creating a grammar, etc.). > > > > > > > > > > The editors structure for LiClipse should work in both Eclipse 3 or 4, > although the theming enhancements will require Eclipse 4 (as it'll need > some features only available there). > > > > > > > > > > Cheers, > > > > > > Fabio > > Thanks for the response. Now I understand better what you're trying to do. > Eclipse can be something of a pain to get basic support to use new > languages. I never was able to get it to work with Vpascal. I would also > like the bundle, since I can't get the version in the lab to work like the > version on my desk. I've never been one for dark themes. My pet peeve is > the battle over negative numbers between PyDev and pep8.py. PyDev put the > space in and pep8.py gives me a warning. > I remember report like that, unfortunately, in the last months working at Appcelerator, it was very difficult to actually work on PyDev (as it wasn't a priority for them), but if the funding succeeds, I hope to fix those annoyances (formatting should definitely respect pep8). > Anyway, PyDev deserves my support and thank you for all your hard work. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wanderer at dialup4less.com Sat Mar 23 11:07:07 2013 From: wanderer at dialup4less.com (Wanderer) Date: Sat, 23 Mar 2013 08:07:07 -0700 (PDT) Subject: LiClipse In-Reply-To: References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> Message-ID: On Saturday, March 23, 2013 7:11:10 AM UTC-4, Fabio Zadrozny wrote: > On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > > > > > On Mar 23, 7:58?am, Fabio Zadrozny wrote: > > > > > Hello there, > > > > > > As I've proposed it, let me try to explain it a bit better (if you have > > > doubts, I should probably rephrase the proposal). > > > > > > There are 2 main targets there: keeping PyDev properly supported (which > > > hopefully doesn't need more explanation) and creating LiClipse. > > > > > > The idea for LiClipse is definitely not making a fork, but having an easier > > > way to add a basic editor inside Eclipse (while developing PyDev, I do get > > > many requests for adding support for editors related to Python, such as > > > Django templates, Mako, Restructured text, Cython, etc), so, this will > > > provide me with a basis to do that (and with the basis in place, the idea > > > is having the possibility of creating an editor without knowledge of > > > Eclipse and in a very fast way -- current technologies for that such as > > > DLTK or XText aim much higher and are not trivial. I really want to have a > > > way to have a basic editor inside Eclipse just specifying the language very > > > 'loosely' -- say, something that'd take you 15-30 minutes and almost no > > > special knowledge of Eclipse internals -- and which would need more > > > knowledge of Eclipse internals only for more advanced stuff). > > > > > > As for the dark theme, it's something that annoys me a lot (so, I was > > > hoping it was also something interesting for other people -- right now, > > > it's not possible to have a professional dark theme in Eclipse, there are > > > many loose ends -- so, for those that would like to work with a dark theme > > > -- as myself -- it may be very annoying -- although yes, it may not be > > > applicable if you're happy with the current non-dark UI). > > > > > > As for distributions, yes, I plan to do an Eclipse distribution with > > > LiClipse / PyDev bundled -- Easy Eclipse is definitely not a solution as it > > > is NOT supported (it has an ancient version of PyDev which only serves to > > > confuse users and Eclipse.org does not have a Python version with PyDev). > > > I'd hardly call that a fork thought (and it should be possible to install > > > it as a separate plugin anyways, so, you can use the Eclipse you got from > > > anywhere and just use the update site to get those plugins). > > > > > > Cheers, > > > > > > Fabio > > > > I am interested in the new eclipse plugin capabilities. > > Where does liclipse stand with respect to this? > > > > The idea is providing a way to add a language just by saying things like keywords, elements (such as function or class -- if your language has that), indenting words and it'll provide you an editor that has all the common functions you'd expect, such as syntax highlighting, outline, indenting, template completion, etc. So, in LiClipse, you shouldn't need to create a plugin at this level, just one configuration file (which you should be able to fill in 15-30 minutes). > > > > > After that, if you want more things (such as code analysis or a semantic aware code completion), then you'd have to go the route of actually creating an Eclipse plugin. > ? > > > ie Eclipse-4 claims to have made plugin development (for new custom > > languages) easier. > > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > > > > Well, it may have become a bit easier (with dltk and xtext), but it's still far from trivial (you still have to know at least java, how plugins work, eclipse internals, creating a grammar, etc.). > > > > > The editors structure for LiClipse should work in both Eclipse 3 or 4, although the theming enhancements will require Eclipse 4 (as it'll need some features only available there). > > > > > Cheers, > > > Fabio Thanks for the response. Now I understand better what you're trying to do. Eclipse can be something of a pain to get basic support to use new languages. I never was able to get it to work with Vpascal. I would also like the bundle, since I can't get the version in the lab to work like the version on my desk. I've never been one for dark themes. My pet peeve is the battle over negative numbers between PyDev and pep8.py. PyDev put the space in and pep8.py gives me a warning. Anyway, PyDev deserves my support and thank you for all your hard work. From rustompmody at gmail.com Sat Mar 23 13:27:28 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 23 Mar 2013 10:27:28 -0700 (PDT) Subject: LiClipse References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> Message-ID: <7771f4de-c135-446f-b4e8-14ad426c29a3@m9g2000pby.googlegroups.com> On Mar 23, 4:11?pm, Fabio Zadrozny wrote: > On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > > > > ie Eclipse-4 claims to have made plugin development (for new custom > > languages) easier. > > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > > Well, it may have become a bit easier (with dltk and xtext), but it's still > far from trivial (you still have to know at least java, how plugins work, > eclipse internals, creating a grammar, etc.). I still have one (quite general) question: When eclipse 'does' pydev, is it mostly in java or in python? Using python's native parser etc makes the analysis more reliable at the cost of more fragile, non-portable(?) etc plumbing between java and python. Whereas rewriting python's parsing etc in java, makes the basic architecture easier but will always keep you behind target when say python changes/adds to its syntax/feature set etc. Which do you choose? And are the new facilities in Juno easier for cross-language feature-sets? From fabiofz at gmail.com Sat Mar 23 13:56:34 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sat, 23 Mar 2013 14:56:34 -0300 Subject: LiClipse In-Reply-To: <7771f4de-c135-446f-b4e8-14ad426c29a3@m9g2000pby.googlegroups.com> References: <514CFEDA.4030903@gmail.com> <8b1e5da2-7f80-4f68-a4f1-b4d1f36dd198@y7g2000pbu.googlegroups.com> <7771f4de-c135-446f-b4e8-14ad426c29a3@m9g2000pby.googlegroups.com> Message-ID: On Sat, Mar 23, 2013 at 2:27 PM, rusi wrote: > On Mar 23, 4:11 pm, Fabio Zadrozny wrote: > > On Sat, Mar 23, 2013 at 12:38 AM, rusi wrote: > > > > > > ie Eclipse-4 claims to have made plugin development (for new custom > > > languages) easier. > > > What is the relation of liclipse to eclipse 3<->4 plugin architecture? > > > > Well, it may have become a bit easier (with dltk and xtext), but it's > still > > far from trivial (you still have to know at least java, how plugins work, > > eclipse internals, creating a grammar, etc.). > > I still have one (quite general) question: > When eclipse 'does' pydev, is it mostly in java or in python? > > Using python's native parser etc makes the analysis more reliable at > the cost of more fragile, non-portable(?) etc plumbing between java > and python. > > Whereas rewriting python's parsing etc in java, makes the basic > architecture easier but will always keep you behind target when say > python changes/adds to its syntax/feature set etc. > Parsing in PyDev is done at java (so, yes, I have to update it when Python itself goes forward). Still, note that even if I was in Python and could use the Python parser, I don't think that using the internal Python parser would be a good choice (because it ends up being too fragile for me -- i.e.: if the IDE is done using Python 2.x it wouldn't be able to analyze a Python 3 codebase -- unless it spawned scripts based on the configured Python you're developing against, but things as a proper code analysis would prove very difficult to do that way). Also, the feature set from the PyDev grammar is different from the Python grammar: For example: - it has to be fault tolerant (because you'll still want to see the outline and get code completion even if you don't have the complete file correct) - it may need to store more information in case a pretty-printing is needed later on (so, the Python grammar can get something as "a = (1)" and remove the parenthesis as they don't make part of the AST, as that's the same as "a = 1" but in case you were pretty-printing the AST you may not want to throw that away). > > Which do you choose? And are the new facilities in Juno easier for > cross-language feature-sets? > As for easier cross-language feature sets, not sure what exactly are you referring to... (but I don't think Eclipse 4 itself changed much from the existing status quo... it's may difference in the programming model is on the dependency injection, so some APIs are cleaner now -- besides the UI changes). Cheers, Fabio > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Fri Mar 22 17:57:42 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Fri, 22 Mar 2013 17:57:42 -0400 Subject: Change in Python 3.3 with the treatment of sys.argv Message-ID: Below is an extract from some code to run on Python 2.7.3, 3.2.3 and 3.3.0 to compare speeds, both between versions and machines: if __name__ == '__main__': # Text string for initial test - Modify for your own machine or # delete it and and answer the input statement with your own machine # characteristics. sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB Disk Free space', ) main() def main(): if len(sys.argv) > 1: idMachine= ' '.join(sys.argv[1:]) ... oFile= open('FP' + now + '.log', 'w') oFile.writelines(idM + '\n' + sys.version + '\n') For 2.7, the result is: Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] for 3.2, the result is: Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] For 3.3, the result is: I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] The full test result, for random matrices of increasing order is available here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) Colin W. From rosuav at gmail.com Fri Mar 22 18:13:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Mar 2013 09:13:37 +1100 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: On Sat, Mar 23, 2013 at 8:57 AM, Colin J. Williams wrote: > Below is an extract from some code to run on Python 2.7.3, 3.2.3 and 3.3.0 > to compare speeds, both between versions and machines: Can you post the actual code in question, please? There are several problems with the code as posted: main() isn't defined when it gets called up top, idM vs idMachine, and now isn't defined. I'm guessing that the difference is somewhere in idM vs idMachine, but that may be completely off the mark. ChrisA From ethan at stoneleaf.us Fri Mar 22 18:11:51 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 22 Mar 2013 15:11:51 -0700 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: <514CD727.4020408@stoneleaf.us> On 03/22/2013 02:57 PM, Colin J. Williams wrote: > Below is an extract from some code to run on Python 2.7.3, 3.2.3 and 3.3.0 to compare speeds, both between versions and > machines: > > if __name__ == '__main__': > # Text string for initial test - Modify for your own machine or > # delete it and and answer the input statement with your own machine > # characteristics. > sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB Disk Free space', ) > main() > > > def main(): > if len(sys.argv) > 1: > idMachine= ' '.join(sys.argv[1:]) > ... > oFile= open('FP' + now + '.log', 'w') > oFile.writelines(idM + '\n' + sys.version + '\n') > > For 2.7, the result is: > Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space > 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] > > for 3.2, the result is: > Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space > 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] > > For 3.3, the result is: > I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e > > 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] > > The full test result, for random matrices of increasing order is available > here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) First, this is what I get with 3.3: Python 3.3.0 (default, Sep 29 2012, 17:14:58) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. --> import sys --> sys.argv [''] --> sys.argv[1:] = ('this is a test!', ) --> sys.argv ['', 'this is a test!'] --> ' '.join(sys.argv[1:]) 'this is a test!' Second, your code doesn't show being joined by an underscore. -- ~Ethan~ From __peter__ at web.de Fri Mar 22 18:33:13 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Mar 2013 23:33:13 +0100 Subject: Change in Python 3.3 with the treatment of sys.argv References: Message-ID: Colin J. Williams wrote: > Below is an extract from some code to run on Python 2.7.3, 3.2.3 and > 3.3.0 to compare speeds, both between versions and machines: > > if __name__ == '__main__': > # Text string for initial test - Modify for your own machine or > # delete it and and answer the input statement with your own machine > # characteristics. > sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB > Disk Free space', ) > main() > > > def main(): > if len(sys.argv) > 1: > idMachine= ' '.join(sys.argv[1:]) > ... > oFile= open('FP' + now + '.log', 'w') > oFile.writelines(idM + '\n' + sys.version + '\n') > > For 2.7, the result is: > Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space > 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] > > for 3.2, the result is: > Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space > 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] > > For 3.3, the result is: > I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e > 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit > (Intel)] > > The full test result, for random matrices of increasing order is > available > here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) You may have run Python 3.3 with a slightly different script, one where you forgot a trailing comma: >>> argv = ["foo"] >>> argv[1:] = ("bar",) # with comma >>> print("-".join(argv[1:])) bar >>> argv = ["foo"] >>> argv[1:] = ("bar") # without comma >>> print("-".join(argv[1:])) b-a-r From steve+comp.lang.python at pearwood.info Fri Mar 22 19:45:13 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2013 23:45:13 GMT Subject: Change in Python 3.3 with the treatment of sys.argv References: Message-ID: <514ced08$0$30001$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Mar 2013 17:57:42 -0400, Colin J. Williams wrote: > Below is an extract from some code to run on Python 2.7.3, 3.2.3 and > 3.3.0 to compare speeds, both between versions and machines: Do you have an actual question? I don't see the point. You've given us an "extract", which means the rest of your code could be doing anything, and the code you have provided doesn't actually run. What question are we supposed to be answering? Is there a problem here that needs to be solved? I appreciate the fact that you didn't dump a huge blob of code on us, truly I do, but please read this page: http://sscce.org/ for ideas on how to effectively write example code. By the way, if you suspect a difference in sys.argv, the easiest way to compare the two is to *look at sys.argv alone*, with as little other confounding code as possible. E.g. write this tiny two-line script: import sys print(sys.argv) Then call it from the command line with something like this (tested under Linux, may be a little different under Windows): python2.7 myscript.py "hello world" fe fi fo fum python3.2 myscript.py "hello world" fe fi fo fum python3.3 myscript.py "hello world" fe fi fo fum In all three cases, you should get the exact same result: ['hello world', 'fe', 'fi', 'fo', 'fum'] which strongly suggests that whatever problem you are experiencing, it is not caused by changes in sys.argv. (There is no change in sys.argv, it's just a list of strings, the same as it always was.) P.S. it's remarkably, and deceptively, difficult to correctly benchmark code. The best way is to take your actual application, give it some real world data to process, and time how long it takes. -- Steven From cjw at ncf.ca Sat Mar 23 06:43:30 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 23 Mar 2013 06:43:30 -0400 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: <514D8752.50309@ncf.ca> On 22/03/2013 6:11 PM, Ethan Furman wrote: > On 03/22/2013 02:57 PM, Colin J. Williams wrote: >> Below is an extract from some code to run on Python 2.7.3, 3.2.3 and >> 3.3.0 to compare speeds, both between versions and >> machines: >> >> if __name__ == '__main__': >> # Text string for initial test - Modify for your own machine or >> # delete it and and answer the input statement with your own machine >> # characteristics. >> sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB >> Disk Free space', ) >> main() >> >> >> def main(): >> if len(sys.argv) > 1: >> idMachine= ' '.join(sys.argv[1:]) >> ... >> oFile= open('FP' + now + '.log', 'w') >> oFile.writelines(idM + '\n' + sys.version + '\n') >> >> For 2.7, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] >> >> for 3.2, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] >> >> For 3.3, the result is: >> I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e >> >> >> 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit >> (Intel)] >> >> The full test result, for random matrices of increasing order is >> available >> here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) > > First, this is what I get with 3.3: > > Python 3.3.0 (default, Sep 29 2012, 17:14:58) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > --> import sys > --> sys.argv > [''] > --> sys.argv[1:] = ('this is a test!', ) > --> sys.argv > ['', 'this is a test!'] > --> ' '.join(sys.argv[1:]) > 'this is a test!' > > > Second, your code doesn't show being joined by an underscore. > > -- > ~Ethan~ No, the same program ran against each of the three versions. I assume that 3.3 behaves differently. Colin W. From cjw at ncf.ca Sat Mar 23 06:43:30 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 23 Mar 2013 06:43:30 -0400 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: <514D8752.50309@ncf.ca> On 22/03/2013 6:11 PM, Ethan Furman wrote: > On 03/22/2013 02:57 PM, Colin J. Williams wrote: >> Below is an extract from some code to run on Python 2.7.3, 3.2.3 and >> 3.3.0 to compare speeds, both between versions and >> machines: >> >> if __name__ == '__main__': >> # Text string for initial test - Modify for your own machine or >> # delete it and and answer the input statement with your own machine >> # characteristics. >> sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB >> Disk Free space', ) >> main() >> >> >> def main(): >> if len(sys.argv) > 1: >> idMachine= ' '.join(sys.argv[1:]) >> ... >> oFile= open('FP' + now + '.log', 'w') >> oFile.writelines(idM + '\n' + sys.version + '\n') >> >> For 2.7, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] >> >> for 3.2, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] >> >> For 3.3, the result is: >> I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e >> >> >> 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit >> (Intel)] >> >> The full test result, for random matrices of increasing order is >> available >> here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) > > First, this is what I get with 3.3: > > Python 3.3.0 (default, Sep 29 2012, 17:14:58) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > --> import sys > --> sys.argv > [''] > --> sys.argv[1:] = ('this is a test!', ) > --> sys.argv > ['', 'this is a test!'] > --> ' '.join(sys.argv[1:]) > 'this is a test!' > > > Second, your code doesn't show being joined by an underscore. > > -- > ~Ethan~ No, the same program ran against each of the three versions. I assume that 3.3 behaves differently. Colin W. From __peter__ at web.de Sat Mar 23 06:59:36 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Mar 2013 11:59:36 +0100 Subject: Change in Python 3.3 with the treatment of sys.argv References: <514D8752.50309@ncf.ca> Message-ID: Colin J. Williams wrote: > No, the same program ran against each of the three versions. I assume > that 3.3 behaves differently. Please show some cooperation -- post actual code that shows the behaviour. Cut and paste instead of paraphrasing. Make it as small as you can. In your case that should be easy -- just rip out the actual benchmark and keep in only the tiny part that processes and prints sys.argv. From cjw at ncf.ca Sat Mar 23 08:27:28 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 23 Mar 2013 08:27:28 -0400 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: <514D9FB0.3070608@ncf.ca> On 22/03/2013 6:11 PM, Ethan Furman wrote: > On 03/22/2013 02:57 PM, Colin J. Williams wrote: >> Below is an extract from some code to run on Python 2.7.3, 3.2.3 and >> 3.3.0 to compare speeds, both between versions and >> machines: >> >> if __name__ == '__main__': >> # Text string for initial test - Modify for your own machine or >> # delete it and and answer the input statement with your own machine >> # characteristics. >> sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB >> Disk Free space', ) >> main() >> >> >> def main(): >> if len(sys.argv) > 1: >> idMachine= ' '.join(sys.argv[1:]) >> ... >> oFile= open('FP' + now + '.log', 'w') >> oFile.writelines(idM + '\n' + sys.version + '\n') >> >> For 2.7, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] >> >> for 3.2, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] >> >> For 3.3, the result is: >> I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e >> >> >> 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit >> (Intel)] >> >> The full test result, for random matrices of increasing order is >> available >> here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) > > First, this is what I get with 3.3: > > Python 3.3.0 (default, Sep 29 2012, 17:14:58) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > --> import sys > --> sys.argv > [''] > --> sys.argv[1:] = ('this is a test!', ) > --> sys.argv > ['', 'this is a test!'] > --> ' '.join(sys.argv[1:]) > 'this is a test!' > > > Second, your code doesn't show being joined by an underscore. > > -- > ~Ethan~ APOLOGIES to those who responded. It seems that a change was made in the program between the 3.3 run and the other runs. Each produces the same heading now. Yes, I should have posted the test code. But, in these circumstances, there is no point in doing that. Colin W. Colin W. From cjw at ncf.ca Sat Mar 23 08:27:28 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 23 Mar 2013 08:27:28 -0400 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: References: Message-ID: <514D9FB0.3070608@ncf.ca> On 22/03/2013 6:11 PM, Ethan Furman wrote: > On 03/22/2013 02:57 PM, Colin J. Williams wrote: >> Below is an extract from some code to run on Python 2.7.3, 3.2.3 and >> 3.3.0 to compare speeds, both between versions and >> machines: >> >> if __name__ == '__main__': >> # Text string for initial test - Modify for your own machine or >> # delete it and and answer the input statement with your own machine >> # characteristics. >> sys.argv[1:]= ('Intel Pentium D CPU 3.0GHz 1.99 GB of RAM 221GB >> Disk Free space', ) >> main() >> >> >> def main(): >> if len(sys.argv) > 1: >> idMachine= ' '.join(sys.argv[1:]) >> ... >> oFile= open('FP' + now + '.log', 'w') >> oFile.writelines(idM + '\n' + sys.version + '\n') >> >> For 2.7, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] >> >> for 3.2, the result is: >> Intel_Pentium_D_CPU_3.0GHz_1.99_GB_of_RAM_221GB_Disk_Free_space >> 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] >> >> For 3.3, the result is: >> I_n_t_e_l___P_e_n_t_i_u_m___D___C_P_U___3_._0_G_H_z___1_._9_9___G_B___o_f___R_A_M___2_2_1_G_B___D_i_s_k___F_r_e_e___s_p_a_c_e >> >> >> 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit >> (Intel)] >> >> The full test result, for random matrices of increasing order is >> available >> here(http://web.ncf.ca/cjw/FP%20Summary%20over%20273-323-330.txt) > > First, this is what I get with 3.3: > > Python 3.3.0 (default, Sep 29 2012, 17:14:58) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > --> import sys > --> sys.argv > [''] > --> sys.argv[1:] = ('this is a test!', ) > --> sys.argv > ['', 'this is a test!'] > --> ' '.join(sys.argv[1:]) > 'this is a test!' > > > Second, your code doesn't show being joined by an underscore. > > -- > ~Ethan~ APOLOGIES to those who responded. It seems that a change was made in the program between the 3.3 run and the other runs. Each produces the same heading now. Yes, I should have posted the test code. But, in these circumstances, there is no point in doing that. Colin W. Colin W. From rosuav at gmail.com Sat Mar 23 08:34:29 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Mar 2013 23:34:29 +1100 Subject: Change in Python 3.3 with the treatment of sys.argv In-Reply-To: <514D9FB0.3070608@ncf.ca> References: <514D9FB0.3070608@ncf.ca> Message-ID: On Sat, Mar 23, 2013 at 11:27 PM, Colin J. Williams wrote: > It seems that a change was made in the program between the 3.3 run and the > other runs. > > Each produces the same heading now. Yep, this is why the simple testcase is so valuable :) Check out http://sscce.org/ (which Steven also pointed you to) - note the points made under "Short". Glad it's solved, anyhow! ChrisA From jmellander at lbl.gov Fri Mar 22 18:11:26 2013 From: jmellander at lbl.gov (Jim Mellander) Date: Fri, 22 Mar 2013 15:11:26 -0700 Subject: Faking TCP Sessions with Scapy Message-ID: Hi all: For various reasons, I want to take apache logs, and create actual pcap packets that could plausibly have created those logs. Obviously, a lot of the info would need to be faked, such as the actual page contents that were served (we have a byte count), the ports, and a few other details. Is there a library built on top of scapy (or other pcap library) that can generate both parts of this transaction, if I feed in the text to encapsulate? Or am I going to need to craft each packet individually (which shouldn't be a big deal anyway, really)? Thanks in advance From rocky at gnu.org Fri Mar 22 23:34:59 2013 From: rocky at gnu.org (rocky) Date: Fri, 22 Mar 2013 20:34:59 -0700 (PDT) Subject: Can I reflect to get arguments exec()? Message-ID: <4d872ab4-9002-4822-9181-4e16990f47fc@googlegroups.com> I have been porting my Python debugger pydbgr to Python3. See [1] or [2]. Inside the debugger, when there is an exec() somewhere in the call stack, I'd like to be able to retrieve the string parameter. With this, the debugger can show part of the string in a call stack. Or it can show the text when the frame is set to that exec() frame. Going further, the debugger could write the exec string out to a temporary file. And when reporting locations, it could report not just something like " line 4", but also give that temporary file name which a front-end could use as well. So consider this code using inspect.getargvalues() and inspect.currentframe(): import inspect def my_exec(string): show_args(inspect.currentframe()) # simulate exec(string) def show_args(frame): print(inspect.getargvalues(frame)) my_exec("show_args(inspect.currentframe())") exec("show_args(inspect.currentframe())") When run this is the output: python3 exec-args.py ArgInfo(args=['string'], varargs=None, keywords=None, locals={'string': 'show_args(inspect.currentframe())'}) ArgInfo(args=[], varargs=None, keywords=None, locals={'my_exec': ,, ... In a different setting, CPython byte-code assembly that gets generated for running exec() is: 25 88 LOAD_GLOBAL 10 (exec) 91 LOAD_CONST 4 ('show_args(inspect.currentframe())') --> 94 CALL_FUNCTION 1 97 POP_TOP What's going on? Also, I have the same question for CPython 2.6 or Python 2.7. Thanks! [1] http://code.google.com/p/pydbgr/ [2] http://code.google.com/p/python3-trepan/ From th982a at googlemail.com Sat Mar 23 05:17:14 2013 From: th982a at googlemail.com (Tamer Higazi) Date: Sat, 23 Mar 2013 10:17:14 +0100 Subject: Soappy: "Fault SOAP-ENV:Client: session_lifetime_syntax_incorrect" Message-ID: <514D731A.10200@googlemail.com> Hi people! I try to access the service of my provider through SOAP, with the credentials I received from my provider once before. Hier ist der 33 lines of code: from SOAPpy import WSDL from SOAPpy.Errors import HTTPError as SoapHTTPError from SOAPpy.Types import faultType import hashlib class KASSystem: def __init__(self): WSDL_AUTH = 'https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl' WSDL_API = 'https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl' userpass = ['mylogin','mypassword'] m = hashlib.sha1() m.update(userpass[1]) userpass[1] = m.hexdigest() loginData = {'user':userpass[0],'pass':userpass[1]} self.__SoapClient = WSDL.Proxy(WSDL_AUTH) try: self.__CredentialToken = self.__SoapClient.KasAuth('authAnfrage',{ 'KasUser':loginData['user'], 'KasAuthType':'sha1', 'KasPassword':loginData['pass'], 'SessionLifeTime':1800, 'SessionUpdateLifeTime':'Y'}) except (SoapHTTPError), e: print "Fehlermeldung:", e.code,e.msg KasObj = KASSystem() Here is the error message: Traceback (most recent call last): File "/storage/PyProjects/toolsAPP/KASUpdate.py", line 38, in KasObj = KASSystem() File "/storage/PyProjects/toolsAPP/KASUpdate.py", line 32, in __init__ 'SessionUpdateLifeTime':'Y'}) File "build/bdist.linux-x86_64/egg/SOAPpy/Client.py", line 540, in __call__ File "build/bdist.linux-x86_64/egg/SOAPpy/Client.py", line 562, in __r_call File "build/bdist.linux-x86_64/egg/SOAPpy/Client.py", line 475, in __call SOAPpy.Types.faultType: I really don't know what I did wrong for any help, I am grateful! Tamer From premiumtelco.com at gmail.com Sat Mar 23 06:07:30 2013 From: premiumtelco.com at gmail.com (premiumtelco) Date: Sat, 23 Mar 2013 03:07:30 -0700 (PDT) Subject: Communication between C++ server and Python app In-Reply-To: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> References: <108cb846-6bb9-4600-a984-2fded0c919bd@er9g2000vbb.googlegroups.com> Message-ID: <1364033250514-5011431.post@n6.nabble.com> I normally wouldn?t be able to find such great content as this on other sites. You have done a great job with each unique point made on this topic. Thank you for your hard work. ----- premium rate numbers Click Here premiumtelco -- View this message in context: http://python.6.n6.nabble.com/Communication-between-C-server-and-Python-app-tp4937660p5011431.html Sent from the Python - python-list mailing list archive at Nabble.com. From avnesh.nitk at gmail.com Sat Mar 23 10:15:38 2013 From: avnesh.nitk at gmail.com (Avnesh Shakya) Date: Sat, 23 Mar 2013 07:15:38 -0700 (PDT) Subject: how to install indico software? Message-ID: please tell me someone, how to install indico software? I have link-- http://indico-software.org/wiki/Admin/Installation0.98 but i have problem, i have no sites-available folder inside apache, i m using window 7, please help me.. Thanks in advance From breamoreboy at yahoo.co.uk Sat Mar 23 10:38:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 23 Mar 2013 14:38:52 +0000 Subject: how to install indico software? In-Reply-To: References: Message-ID: On 23/03/2013 14:15, Avnesh Shakya wrote: > please tell me someone, how to install indico software? I have link-- > http://indico-software.org/wiki/Admin/Installation0.98 > but i have problem, i have no sites-available folder inside apache, i m using window 7, please help me.. > > Thanks in advance > Please help us to help you. "i have a problem, i have no sites-available folder inside apache..." tells me that you have a problem with apache. Or have you tried "easy_install indico" from the command line and that's failed? Or are both these problems? Or neither? If you are specific about what you tried and what went wrong you are far more likely to get answers that will take you forward. -- Cheers. Mark Lawrence From davea at davea.name Sat Mar 23 10:56:32 2013 From: davea at davea.name (Dave Angel) Date: Sat, 23 Mar 2013 10:56:32 -0400 Subject: how to install indico software? In-Reply-To: References: Message-ID: <514DC2A0.3060100@davea.name> On 03/23/2013 10:38 AM, Mark Lawrence wrote: > On 23/03/2013 14:15, Avnesh Shakya wrote: >> please tell me someone, how to install indico software? I have link-- >> http://indico-software.org/wiki/Admin/Installation0.98 http://indico-software.org/wiki/Releases/Indico0.99 is the link pointed to by: https://pypi.python.org/pypi/indico/ I'd start with pypi if I'm looking for the latest release. As for your other three problems, I have no idea. -- DaveA From yanimanuel at hotmail.nl Sat Mar 23 11:22:09 2013 From: yanimanuel at hotmail.nl (Yann Manuel) Date: Sat, 23 Mar 2013 16:22:09 +0100 Subject: No subject Message-ID: Dear Mr/Mrs, I'm reading this book called dive into python 3, and the author does not describe everything, but he gives a link to a blog: (http://adam.gomaa.us/blog/2008/aug/11/t ... y-builtin/). The blog is gone and i cant find it. Does anyone knows where i can find the information of this blog or at least something similar to it? The blog is called the python property built in, by adam gomaaSincerly yours, Yann Manuel from Holland. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 23 11:33:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 02:33:12 +1100 Subject: No subject In-Reply-To: References: Message-ID: On Sun, Mar 24, 2013 at 2:22 AM, Yann Manuel wrote: > Dear Mr/Mrs, > > I'm reading this book called dive into python 3, and the author does not > describe everything, but he gives a link to a blog: > (http://adam.gomaa.us/blog/2008/aug/11/t ... y-builtin/). > The blog is gone and i cant find it. Does anyone knows where i can find the > information of this blog or at least something similar to it? > The blog is called the python property built in, by adam gomaa > Sincerly yours, Not a Python-specific answer, but this may help you: http://web.archive.org/web/20120718070139/http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/ The Wayback Machine has the blog archived. ChrisA From joel.goldstick at gmail.com Sat Mar 23 15:12:16 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 23 Mar 2013 15:12:16 -0400 Subject: No subject In-Reply-To: References: Message-ID: On Sat, Mar 23, 2013 at 11:33 AM, Chris Angelico wrote: > On Sun, Mar 24, 2013 at 2:22 AM, Yann Manuel > wrote: > > Dear Mr/Mrs, > > > > I'm reading this book called dive into python 3, and the author does not > > describe everything, but he gives a link to a blog: > > (http://adam.gomaa.us/blog/2008/aug/11/t ... y-builtin/). > > The blog is gone and i cant find it. Does anyone knows where i can find > the > > information of this blog or at least something similar to it? > > The blog is called the python property built in, by adam gomaa > > Sincerly yours, > I just googled him. He has several repositories and also a facebook page. Why not see if you can contact him directly > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.b at gmail.com Sat Mar 23 12:04:03 2013 From: m.b at gmail.com (Marco) Date: Sat, 23 Mar 2013 17:04:03 +0100 Subject: Required arguments in argparse: at least one of a group Message-ID: Is there the possibility using the argparse module to group two or more arguments in order to have at least one of them required? For instance, I would like to have not an error only in the following cases: python finder.py --file myfile --dir mydir python finder.py --pattern mypattern --dir mydir python finder.py --file myfile --pattern mypattern --dir mydir where --dir is required, and --file _or_ --parser have to be specified. In other words, I want the parser prints an error message just in this case: python finder.py --dir mydir Thanks in advance, Marco -- Marco From robert.day at merton.oxon.org Sat Mar 23 12:27:53 2013 From: robert.day at merton.oxon.org (Rob Day) Date: Sat, 23 Mar 2013 16:27:53 +0000 Subject: Required arguments in argparse: at least one of a group In-Reply-To: References: Message-ID: I don't know about argparse, but if you use docopt (http://docopt.org/) then this is easy to do with something like: """Usage: finder.py --file --dir finder.py --pattern --dir finder.py --file --pattern --dir """ On 23 March 2013 16:04, Marco wrote: > Is there the possibility using the argparse module to group two or more > arguments in order to have at least one of them required? For instance, I > would like to have not an error only in the following cases: > > python finder.py --file myfile --dir mydir > python finder.py --pattern mypattern --dir mydir > python finder.py --file myfile --pattern mypattern --dir mydir > > where --dir is required, and --file _or_ --parser have to be specified. In > other words, I want the parser prints an error message just in this case: > > python finder.py --dir mydir > > Thanks in advance, Marco > -- > Marco > -- > http://mail.python.org/mailman/listinfo/python-list -- Robert K. Day robert.day at merton.oxon.org From m.b at gmail.com Sun Mar 24 16:02:12 2013 From: m.b at gmail.com (Marco) Date: Sun, 24 Mar 2013 21:02:12 +0100 Subject: Required arguments in argparse: at least one of a group References: Message-ID: On 03/23/2013 05:27 PM, Rob Day wrote: > I don't know about argparse, but if you use docopt > (http://docopt.org/) then this is easy to do with something like: > > """Usage: > > finder.py --file --dir > finder.py --pattern --dir > finder.py --file --pattern --dir > """ Thanks Rob, but I was looking for a solution in the stdlib -- Marco From rurpy at yahoo.com Sun Mar 24 17:41:45 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 24 Mar 2013 14:41:45 -0700 (PDT) Subject: Required arguments in argparse: at least one of a group In-Reply-To: References: Message-ID: <8ef40685-bcd1-4f5f-900c-2cb8d31c0950@googlegroups.com> On 03/23/2013 10:04 AM, Marco wrote: > Is there the possibility using the argparse module to group two or more > arguments in order to have at least one of them required? For instance, > I would like to have not an error only in the following cases: > > python finder.py --file myfile --dir mydir > python finder.py --pattern mypattern --dir mydir > python finder.py --file myfile --pattern mypattern --dir mydir > > where --dir is required, and --file _or_ --parser have to be specified. > In other words, I want the parser prints an error message just in this case: > > python finder.py --dir mydir How about something like: p = argparse.ArgumentParser (description="...") p.add_argument ('--dir', help="A dir (required).", required=True) p.add_argument ('--pattern', help="A pattern. If not given, --file is required.") p.add_argument ('--file', help="A filename. If not given, --pattern is required.") args = p.parse_args() if not args.file and not args.pattern: p.error ('Either --pattern or --file is required.') From amirouche.boubekki at gmail.com Sat Mar 23 12:10:43 2013 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Sat, 23 Mar 2013 17:10:43 +0100 Subject: Welcome PythonScript: Python to Javascript translator in 350 lines of Python Message-ID: H?llo, I'm happy to announce the immediate avaibility of PythonScript a Python -> Javascript translator written in Python. So far it works... Break it online @ http://apppyjs.appspot.com How it works ? Similarly to PyPy, it use a restricted version of Python called PythonJS. Along side this translator there is two other components PythonToPythonJS which translates (more) Python to PythonJS and a runtime library written in PythonJS that creates javascript objects to emulate classes, objects and methods. It's not compliant. Other Python in the browser solutions are written in Javascript (skulpt, brython) or both (pyjaco, pyjs) and are difficult to work with. This implementation is fully written in Python with small snippets of Javascript. Creating bindings is very easy, jQuery bindings are available. All the thing is not much tested. Also if you are interested in this topic, you might be interested by the avaibility of asm.js in Firefox nightly. asm.js is a subset of JS, that can be compiled by the browser, thus making solutions such as emscripten and PyPy with an asm.js backend more interesting. Cheers, Amirouche -------------- next part -------------- An HTML attachment was scrubbed... URL: From fromberg100 at hotmail.com Sat Mar 23 20:37:35 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Sat, 23 Mar 2013 19:37:35 -0500 Subject: addressof object with id() Message-ID: Hi, I have a single questions regarding id() built-in function. example 1: var1 = "some string" var2 = "some string" if use the id() function on both, it returns exactly the same address. example 2: data = "some string" var1 = data var2 = data if use the id() function on var1 and var2, it returns exactly the same address. can anyone explain me please why does this happens? Is this correct? Thanks in advance and regards, Fabian From davea at davea.name Sat Mar 23 20:49:53 2013 From: davea at davea.name (Dave Angel) Date: Sat, 23 Mar 2013 20:49:53 -0400 Subject: addressof object with id() In-Reply-To: References: Message-ID: <514E4DB1.3060600@davea.name> On 03/23/2013 08:37 PM, Fabian von Romberg wrote: > Hi, > > I have a single questions regarding id() built-in function. > > example 1: > > var1 = "some string" > var2 = "some string" > > if use the id() function on both, it returns exactly the same address. > > > example 2: > > data = "some string" > var1 = data > var2 = data > > if use the id() function on var1 and var2, it returns exactly the same address. > > > can anyone explain me please why does this happens? Is this correct? > > The Python system may decide to optimize new objects by reusing old ones, IF the type is immutable. This ends up saving a good bit of space. Three places that come to mind are strings, small ints, and booleans. In fact for booleans, it's required behavior. There is exactly one True object, and one False object. You can assume that if the id's are equal, the objects are equal. But you can't assume the inverse or the converse. So it also turns out to save some time. When two objects are being compared for equal, and it turns out they have the same id, there's no need to actually look at the contents. -- DaveA From rosuav at gmail.com Sat Mar 23 20:56:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 11:56:50 +1100 Subject: addressof object with id() In-Reply-To: <514E4DB1.3060600@davea.name> References: <514E4DB1.3060600@davea.name> Message-ID: On Sun, Mar 24, 2013 at 11:49 AM, Dave Angel wrote: > You can assume that if the id's are equal, the objects are equal. But you > can't assume the inverse or the converse. To be more specific: If the ids are equal, the objects are identical. Doesn't mean they'll compare equal - for instance, float("nan") isn't equal to itself. But for most situations, you can assume that identical objects compare equal. ChrisA From roy at panix.com Sat Mar 23 21:20:05 2013 From: roy at panix.com (Roy Smith) Date: Sat, 23 Mar 2013 21:20:05 -0400 Subject: addressof object with id() References: <514E4DB1.3060600@davea.name> Message-ID: In article , Chris Angelico wrote: > On Sun, Mar 24, 2013 at 11:49 AM, Dave Angel wrote: > > You can assume that if the id's are equal, the objects are equal. But you > > can't assume the inverse or the converse. > > To be more specific: If the ids are equal, the objects are identical. > Doesn't mean they'll compare equal - for instance, float("nan") isn't > equal to itself. But for most situations, you can assume that > identical objects compare equal. >>> n = float("nan") # No real surprise here >>> n == n False # But this is kind of weird >>> [n] == [n] True In fact, that's actually a bug (or at least, contrary to the documented behavior). The docs (http://docs.python.org/2/library/stdtypes.html) say: > In particular, tuples and lists are compared lexicographically by comparing > corresponding elements. This means that to compare equal, every element must > compare equal and the two sequences must be of the same type and have the > same length and that's not what's happening here: >>> l1 = [n] >>> l2 = [n] >>> l1 == l2 True >>> l1[0] == l2[0] False From steve+comp.lang.python at pearwood.info Sat Mar 23 22:04:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2013 02:04:15 GMT Subject: addressof object with id() References: <514E4DB1.3060600@davea.name> Message-ID: <514e5f1f$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Mar 2013 11:56:50 +1100, Chris Angelico wrote: > On Sun, Mar 24, 2013 at 11:49 AM, Dave Angel wrote: >> You can assume that if the id's are equal, the objects are equal. But >> you can't assume the inverse or the converse. > > To be more specific: If the ids are equal, the objects are identical. > Doesn't mean they'll compare equal - for instance, float("nan") isn't > equal to itself. But for most situations, you can assume that identical > objects compare equal. Also note that containers are permitted to assume reflexivity, that is, that x == x. That sometimes means that they don't play well with non- reflexive values such as NANs. e.g. x = [float('nan')] x == x even though x[0] != x[0] This has been discussed repeatedly on the Python-Dev mailing list, and the consensus is that there is no real consensus. Those who don't do serious floating point work hate NANs, those who do are split between loving NANs and merely tolerating them because the IEEE standard requires them, but pretty much everyone agrees that containers should be free to assume identity implies equality. -- Steven From roy at panix.com Sat Mar 23 22:19:31 2013 From: roy at panix.com (Roy Smith) Date: Sat, 23 Mar 2013 22:19:31 -0400 Subject: addressof object with id() References: <514E4DB1.3060600@davea.name> <514e5f1f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <514e5f1f$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Those who don't do serious floating point work hate NANs This kind of thing doesn't just come up in floating point work. SQL folks have much the same issue with NULL. From rosuav at gmail.com Sat Mar 23 23:33:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 14:33:26 +1100 Subject: addressof object with id() In-Reply-To: References: <514E4DB1.3060600@davea.name> <514e5f1f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 24, 2013 at 1:19 PM, Roy Smith wrote: > In article <514e5f1f$0$30001$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Those who don't do serious floating point work hate NANs > > This kind of thing doesn't just come up in floating point work. SQL > folks have much the same issue with NULL. Oh, NULL is easy to deal with. It's the magic value that isn't a value, except when it's a value, because it's the only value that you can use when you need a value that's not a value. Of course, sometimes it breaks that rule. ChrisA From rustompmody at gmail.com Sun Mar 24 00:13:10 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 23 Mar 2013 21:13:10 -0700 (PDT) Subject: addressof object with id() References: <514E4DB1.3060600@davea.name> <514e5f1f$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 24, 8:33?am, Chris Angelico wrote: > On Sun, Mar 24, 2013 at 1:19 PM, Roy Smith wrote: > > In article <514e5f1f$0$30001$c3e8da3$54964... at news.astraweb.com>, > > ?Steven D'Aprano wrote: > > >> Those who don't do serious floating point work hate NANs > > > This kind of thing doesn't just come up in floating point work. ?SQL > > folks have much the same issue with NULL. > > Oh, NULL is easy to deal with. It's the magic value that isn't a > value, except when it's a value, because it's the only value that you > can use when you need a value that's not a value. Of course, sometimes > it breaks that rule. > > ChrisA Which is an elaboration of NAN: (A number that is) Not A Number. All these are different variants of ? (or _|_ if that does not print) in denotational semantics. That is when a function is partial, we make it artificially total by adding an explicit bogus value to the range and mapping all undefined points to that point. The problem is that when this is carried over from partial functions to infinite program loops, it can never work (in full generality) because loops are not detectable. From roy at panix.com Sat Mar 23 21:00:07 2013 From: roy at panix.com (Roy Smith) Date: Sat, 23 Mar 2013 21:00:07 -0400 Subject: addressof object with id() References: Message-ID: In article , Fabian von Romberg wrote: > Hi, > > I have a single questions regarding id() built-in function. > > example 1: > > var1 = "some string" > var2 = "some string" > > if use the id() function on both, it returns exactly the same address. Yup. This is because (in some implementations, but not guaranteed), Python interns strings. That means, when you create a string literal (i.e. something in quotes), the system looks to see if it's seen that exact same string before and if so, gives you a reference to the same string in memory, instead of creating a new one. Also, be careful about saying things like, "the id() function [...] returns [an] address. It's only in some implementations (and, again, not guaranteed), that id() returns the address of an object. All the docs say is, "an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime". An implementation is free to number objects consecutively from 1, or from 23000, or pick random numbers, anything else it wants, as long as it meets that requirement. BTW, I tried this: >>> x = "foo" >>> y = "foo" >>> id(x) 3810944 >>> id(y) 3810944 which is, of course, the result I expected. Then I tried: >>> z = "f" + "oo" >>> id(z) 3810944 which actually surprised me. I had thought interning only affected string literals, but apparently it works for all strings! This works too: >>> a = "b" + "ar" >>> b = "ba" + "r" >>> id(a) 3810152 >>> id(b) 3810152 but, again, none of this is guaranteed. From rosuav at gmail.com Sat Mar 23 21:31:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Mar 2013 12:31:35 +1100 Subject: addressof object with id() In-Reply-To: References: Message-ID: On Sun, Mar 24, 2013 at 12:00 PM, Roy Smith wrote: > I had thought interning only affected > string literals, but apparently it works for all strings! This works > too: > >>>> a = "b" + "ar" >>>> b = "ba" + "r" >>>> id(a) > 3810152 >>>> id(b) > 3810152 > > but, again, none of this is guaranteed. No, what that proves is that concatenation of literals is treated as a literal. >>> a="foo" >>> b="fo" >>> b+="o" >>> id(a) 14870112 >>> id(b) 15985760 >>> c="fo"+"o" >>> id(c) 14870112 However, you can of course force the matter. >>> a=sys.intern(a) >>> b=sys.intern(b) >>> c=sys.intern(c) >>> id(a),id(b),id(c) (14870112, 14870112, 14870112) (In Python 2, use intern() rather than sys.intern().) It seems that in CPython 3.3.0 on Windows 32-bit (and yes, I do need to be that specific, though this probably applies to a broad range of CPython versions), string literals are interned. But that's an implementation detail. ChrisA From steve+comp.lang.python at pearwood.info Sat Mar 23 22:01:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2013 02:01:22 GMT Subject: addressof object with id() References: Message-ID: <514e5e71$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Mar 2013 21:00:07 -0400, Roy Smith wrote: > In article , > Fabian von Romberg wrote: > >> Hi, >> >> I have a single questions regarding id() built-in function. >> >> example 1: >> >> var1 = "some string" >> var2 = "some string" >> >> if use the id() function on both, it returns exactly the same address. > > Yup. Nope. Did you actually try it? As far as I know, there is no Python implementation that automatically interns strings which are not valid identifiers. "some string" is not a valid identifier, due to the space. [...] > which is, of course, the result I expected. Then I tried: > >>>> z = "f" + "oo" >>>> id(z) > 3810944 > > which actually surprised me. I had thought interning only affected > string literals, but apparently it works for all strings! This works > too: > >>>> a = "b" + "ar" >>>> b = "ba" + "r" >>>> id(a) > 3810152 >>>> id(b) > 3810152 You're not actually testing what you think you're testing. In Cpython, which I assume you are using, there is a keyhole optimizer that runs when code is compiled to byte-code, and it folds some constant expressions like `a = "b" + "ar"` to `a = "bar"`. To defeat the keyhole optimizer, you need something like this: a = "bar" b = "".join(["b", "a", "r"]) although of course a sufficiently smart keyhole optimizer could recognise that as a constant as well. This, on the other hand, will defeat it: b = str("ba") + str("r") because the keyhole optimizer cannot tell whether str() is still the built-in function or has been replaced by something else. > but, again, none of this is guaranteed. Correct. -- Steven From roy at panix.com Sat Mar 23 22:11:24 2013 From: roy at panix.com (Roy Smith) Date: Sat, 23 Mar 2013 22:11:24 -0400 Subject: addressof object with id() References: <514e5e71$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <514e5e71$0$30001$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > As far as I know, there is no Python implementation that automatically > interns strings which are not valid identifiers. "some string" is not a > valid identifier, due to the space. I stand corrected. And somewhat humbled. From __peter__ at web.de Sun Mar 24 03:57:28 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 24 Mar 2013 08:57:28 +0100 Subject: addressof object with id() References: <514e5e71$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 23 Mar 2013 21:00:07 -0400, Roy Smith wrote: > >> In article , >> Fabian von Romberg wrote: >> >>> Hi, >>> >>> I have a single questions regarding id() built-in function. >>> >>> example 1: >>> >>> var1 = "some string" >>> var2 = "some string" >>> >>> if use the id() function on both, it returns exactly the same address. >> >> Yup. > > Nope. Did you actually try it? > > > As far as I know, there is no Python implementation that automatically > interns strings which are not valid identifiers. "some string" is not a > valid identifier, due to the space. I don't know about other implementations, but in CPython two equal strings in the *same* *compilation* will end up with the same id as a result of constant folding. In the interpreter: >>> a = "some string" >>> b = "some string" >>> a is b False >>> a = "some string"; b = "some string"; a is b True In a script: $ cat tmp.py a = "some string" b = "some string" print a is b $ python tmp.py True From steve+comp.lang.python at pearwood.info Sat Mar 23 21:52:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2013 01:52:30 GMT Subject: addressof object with id() References: Message-ID: <514e5c5e$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Mar 2013 19:37:35 -0500, Fabian von Romberg wrote: > Hi, > > I have a single questions regarding id() built-in function. > > example 1: > > var1 = "some string" > var2 = "some string" > > if use the id() function on both, it returns exactly the same address. The id() function does not return an address. Scrub that from your mind. See below for further details. In any case, when I try the above, I do *not* get the same ID. py> var1 = "some string" py> var2 = "some string" py> id(var1), id(var2) (3082752384L, 3082752960L) I get two distinct IDs. > example 2: > > data = "some string" > var1 = data > var2 = data In this case, id(var1) and id(var2) is *guaranteed* to return the same value, because both names are bound to the same object. The first line creates a string object and binds it to the name "data". The second line binds the same object to the name "var1", and the third line does the same to the name "var2". So now you have three names all referring to the same object. Since all three names refer to the same object, it doesn't matter whether you call id(data), id(var1) or id(var2), they return the same ID. Objects in Python are like people -- they can have more than one name, or no name at all. Depending on who is doing the talking, all of the following could refer to the same person: "Barrack" "Obama" "Dad" "Son" "Mr. President" "POTUS" "Renegade" > if use the id() function on var1 and var2, it returns exactly the same > address. The id() function does not return an address. It returns an arbitrary identification number, an ID. In Jython, IDs start at 1, and are never re- used. In CPython, IDs look like addresses[1], and may be re-used. The only promises that Python makes about IDs are: - they are integers; - they are constant for the life-time of the object; - they are unique for the life-time of the object. That means that they *may* or *may not* be re-used. Jython does not re- use them, CPython does. Python does not make many promises about object identity. Creating a new object using a literal expression may or may not create a new object. Python makes no promises either way. For example: py> a = 42 py> b = 42 py> id(a) == id(b) # a and b are the same object True but: py> a = 420000 py> b = 420000 py> id(a) == id(b) # a and b are different objects False but: py> x = id(420000) py> y = id(420000) py> x == y # x and y get the same ID True However all of these examples are implementation dependent and may vary according to the Python implementation and version. In particular, the third example is specific to CPython. In Jython, for example, the IDs will be unequal. id() is one of the most pointless functions in Python. There is almost never any need to care about the id of an object. I wish that it were moved into the inspect module instead of a built-in function, because in practice id() is only useful for confusing beginners. [1] They look like addresses because the CPython implementation uses the address of the object, as returned by the C compiler, as the ID. But since there is no way to dereference an id, or lookup the object found at an id, it is not an address. It merely has the same numeric value as what the C compiler sees as the address. -- Steven From nobody at nowhere.com Sun Mar 24 02:54:08 2013 From: nobody at nowhere.com (Nobody) Date: Sun, 24 Mar 2013 06:54:08 +0000 Subject: addressof object with id() References: Message-ID: On Sat, 23 Mar 2013 19:37:35 -0500, Fabian von Romberg wrote: > I have a single questions regarding id() built-in function. > > example 1: > > var1 = "some string" > var2 = "some string" > > if use the id() function on both, it returns exactly the same address. I'm assuming that you used something other than "some string" for your tests (e.g. something without a space). Python *may* intern strings. The CPython implementation *does* intern strings which are valid identifiers (a sequence of letters, digits and underscores not starting with a digit), in order to optimise attribute lookups. FWIW, it also does this for integers between -5 <= n <= 256: > var1 = 256 > var2 = 255 + 1 > id(var1) 21499520 > id(var2) 21499520 > var3 = var1 + 1 > var4 = 257 > id(var3) 21541752 > id(var4) 21541584 In this case, it just saves on memory. More generally, an implementation *may* intern any immutable value, although it's not guaranteed to do so for anything except (IIRC) False, True and None. From steve+comp.lang.python at pearwood.info Sun Mar 24 05:35:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2013 09:35:50 GMT Subject: addressof object with id() References: Message-ID: <514ec8f6$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Mar 2013 06:54:08 +0000, Nobody wrote: > More generally, an implementation *may* intern any immutable value, > although it's not guaranteed to do so for anything except (IIRC) False, > True and None. I believe the same also applies to NotImplemented and Ellipsis, although I'm too lazy to look them up to check for sure. -- Steven From jiewei24 at gmail.com Sun Mar 24 01:20:29 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sat, 23 Mar 2013 22:20:29 -0700 (PDT) Subject: Separate Rows in reader Message-ID: Hi all, Currently create a simple text-based database of information about people I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: Name Address Telephone Birthday John Konon Ministry of Moon Walks 4567882 27-Feb Stacy Kisha Ministry of Man Power 1234567 17-Jan My codes are : import csv original = file('friends.csv', 'rU') reader = csv.reader(original) for row in reader: print row and the output is : ['Name', ' Address', 'Telephone', 'Birthday'] ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] But i wanted to make it [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] can someone show me guidance to this issue Thanks all From davea at davea.name Sun Mar 24 01:46:49 2013 From: davea at davea.name (Dave Angel) Date: Sun, 24 Mar 2013 01:46:49 -0400 Subject: Separate Rows in reader In-Reply-To: References: Message-ID: <514E9349.7050205@davea.name> On 03/24/2013 01:20 AM, Jiewei Huang wrote: > Hi all, > > Currently create a simple text-based database of information about people > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > Name Address Telephone Birthday > John Konon Ministry of Moon Walks 4567882 27-Feb > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > My codes are : > import csv > original = file('friends.csv', 'rU') > reader = csv.reader(original) > > for row in reader: > > print row > > > and the output is : > ['Name', ' Address', 'Telephone', 'Birthday'] > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > But i wanted to make it > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > can someone show me guidance to this issue > > Thanks all > There are at least 3 differences to the printouts. Which difference are you concerned with? 1) Moon --> Silly 2) square and round brackets in slightly different places 3) row 0 suppressed Explain which one, or specify a fourth, and also what you have tried to address the question. -- DaveA From rustompmody at gmail.com Sun Mar 24 03:34:03 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 24 Mar 2013 00:34:03 -0700 (PDT) Subject: Separate Rows in reader References: Message-ID: On Mar 24, 10:46?am, Dave Angel wrote: > On 03/24/2013 01:20 AM, Jiewei Huang wrote: > > > > > > > > > > > Hi all, > > > Currently create a simple text-based database of information about people > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > Name ? ? ? ?Address ? ? ? ?Telephone ? ? ? Birthday > > John Konon Ministry of Moon Walks ?4567882 27-Feb > > Stacy Kisha ? ? ? ?Ministry of Man Power ? 1234567 17-Jan > > > My codes are : > > import csv > > original = file('friends.csv', 'rU') > > reader = csv.reader(original) > > > for row in reader: > > > ? ? ?print row > > > and the output is : > > ['Name', ' Address', 'Telephone', 'Birthday'] > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > But i wanted to make it > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > can someone show me guidance to this issue > > > Thanks all > > There are at least 3 differences to the printouts. ?Which difference are > you concerned with? > > 1) Moon --> Silly > 2) square and round brackets in slightly different places > 3) row 0 suppressed > > Explain which one, or specify a fourth, and also what you have tried to > address the question. > > -- > DaveA Besides does it work as you are describing? ie your input appears to be tab delimited, whereas the default is ',' From jiewei24 at gmail.com Sun Mar 24 04:18:39 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sun, 24 Mar 2013 01:18:39 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: On Sunday, March 24, 2013 5:34:03 PM UTC+10, rusi wrote: > On Mar 24, 10:46?am, Dave Angel wrote: > > > On 03/24/2013 01:20 AM, Jiewei Huang wrote: > > > > > > > > > > > >this is the data in csv file http://imgur.com/L4qUkGQ and this is the correct output that i need to get: [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] sorry for the confusion > > > > > > > > > > > > > > > > > > > Hi all, > > > > > > > Currently create a simple text-based database of information about people > > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > > Name ? ? ? ?Address ? ? ? ?Telephone ? ? ? Birthday > > > > John Konon Ministry of Moon Walks ?4567882 27-Feb > > > > Stacy Kisha ? ? ? ?Ministry of Man Power ? 1234567 17-Jan > > > > > > > My codes are : > > > > import csv > > > > original = file('friends.csv', 'rU') > > > > reader = csv.reader(original) > > > > > > > for row in reader: > > > > > > > ? ? ?print row > > > > > > > and the output is : > > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > > > > But i wanted to make it > > > > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > > > > can someone show me guidance to this issue > > > > > > > Thanks all > > > > > > There are at least 3 differences to the printouts. ?Which difference are > > > you concerned with? > > > > > > 1) Moon --> Silly > > > 2) square and round brackets in slightly different places > > > 3) row 0 suppressed > > > > > > Explain which one, or specify a fourth, and also what you have tried to > > > address the question. > > > > > > -- > > > DaveA > > > > Besides does it work as you are describing? > > ie your input appears to be tab delimited, whereas the default is ',' From jiewei24 at gmail.com Sun Mar 24 04:11:58 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sun, 24 Mar 2013 01:11:58 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> On Sunday, March 24, 2013 3:46:49 PM UTC+10, Dave Angel wrote: > On 03/24/2013 01:20 AM, Jiewei Huang wrote: > > > Hi all, > > > > > > Currently create a simple text-based database of information about people > > > > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > Name Address Telephone Birthday > > > John Konon Ministry of Moon Walks 4567882 27-Feb > > > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > > > > > > > My codes are : > > > import csv > > > original = file('friends.csv', 'rU') > > > reader = csv.reader(original) > > > > > > for row in reader: > > > > > > print row > > > > > > > > > and the output is : > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > > > But i wanted to make it > > > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > > > can someone show me guidance to this issue > > > > > > Thanks all > > > > > > > There are at least 3 differences to the printouts. Which difference are > > you concerned with? > > > > 1) Moon --> Silly > > 2) square and round brackets in slightly different places > > 3) row 0 suppressed > > > > Explain which one, or specify a fourth, and also what you have tried to > > address the question. > > > > > > -- > > DaveA Sorry my typo in the output here is the correct output that i need : [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] the difference is that i need a [(row two), (row three), (row fouth)] . I do not want to display row one which is ['Name', ' Address', 'Telephone', 'Birthday'] From jiewei24 at gmail.com Sun Mar 24 04:11:58 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sun, 24 Mar 2013 01:11:58 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> On Sunday, March 24, 2013 3:46:49 PM UTC+10, Dave Angel wrote: > On 03/24/2013 01:20 AM, Jiewei Huang wrote: > > > Hi all, > > > > > > Currently create a simple text-based database of information about people > > > > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > Name Address Telephone Birthday > > > John Konon Ministry of Moon Walks 4567882 27-Feb > > > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > > > > > > > My codes are : > > > import csv > > > original = file('friends.csv', 'rU') > > > reader = csv.reader(original) > > > > > > for row in reader: > > > > > > print row > > > > > > > > > and the output is : > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > > > But i wanted to make it > > > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > > > can someone show me guidance to this issue > > > > > > Thanks all > > > > > > > There are at least 3 differences to the printouts. Which difference are > > you concerned with? > > > > 1) Moon --> Silly > > 2) square and round brackets in slightly different places > > 3) row 0 suppressed > > > > Explain which one, or specify a fourth, and also what you have tried to > > address the question. > > > > > > -- > > DaveA Sorry my typo in the output here is the correct output that i need : [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] the difference is that i need a [(row two), (row three), (row fouth)] . I do not want to display row one which is ['Name', ' Address', 'Telephone', 'Birthday'] From davea at davea.name Sun Mar 24 09:03:31 2013 From: davea at davea.name (Dave Angel) Date: Sun, 24 Mar 2013 09:03:31 -0400 Subject: Separate Rows in reader In-Reply-To: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> Message-ID: <514EF9A3.2000603@davea.name> On 03/24/2013 04:11 AM, Jiewei Huang wrote: > >> >> > > Sorry my typo in the output here is the correct output that i need : > > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > the difference is that i need a [(row two), (row three), (row fouth)] . I do not want to display row one which is ['Name', ' Address', 'Telephone', 'Birthday'] > I had to add a delimiter= to accomodate the fact that your data is tab- separated. The first two code sections address the dropping of row-zero. The third section changes the square brackets to parens, if that's what you really wanted. The fourth section goes all around the barn to get the linefeeds in the right place. There's still one extra space on the first line, but that's an exercise for the reader. run with CPython 2.7.3 import csv original = [ "Name Address Telephone Birthday ", "John Konon Ministry of Moon Walks 4567882 27-Feb", "Stacy Kisha Ministry of Man Power 1234567 17-Jan" ] #original = file('friends.csv', 'rU') reader = csv.reader(original, delimiter="\t") for index, row in enumerate(reader): if index: print row print "-----------" reader = csv.reader(original, delimiter="\t") data = list(reader)[1:] print data print "-----------" reader = csv.reader(original, delimiter="\t") data = [tuple(row) for row in list(reader)[1:]] print data print "-----------" reader = csv.reader(original, delimiter="\t") data = [tuple(row) for row in list(reader)[1:]] print "[", for row in data[:-1]: print str(row) + "," print str(data[-1]) +"]" print "-----------" -- DaveA From python.list at tim.thechases.com Sun Mar 24 09:49:22 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 24 Mar 2013 08:49:22 -0500 Subject: Separate Rows in reader In-Reply-To: <514EF9A3.2000603@davea.name> References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> <514EF9A3.2000603@davea.name> Message-ID: <20130324084922.4e764021@bigbox.christie.dr> On 2013-03-24 09:03, Dave Angel wrote: > >> [THANK YOU!] > > Sorry my typo in the output here is the correct output that i > > need : > > > > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > the difference is that i need a [(row two), (row three), (row > > fouth)] . I do not want to display row one which is ['Name', ' > > Address', 'Telephone', 'Birthday'] > > I had to add a delimiter= to accomodate the fact that your data is > tab- separated. Since it has headers, it might make more sense for readability to use a DictReader: f = file("source.txt", "rb") r = csv.DictReader(f, delimiter='\t') for row in r: print row["Name"], row["Address"], ... However, if it's just stripping off the first row and operating directly on the resulting data, then I'd just be tempted to do r = csv.reader(f, delimiter='\t') r.next() # discard the headers, or optionally store them for row in r: ... -tkc From rustompmody at gmail.com Sun Mar 24 11:57:12 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 24 Mar 2013 08:57:12 -0700 (PDT) Subject: Separate Rows in reader References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> <514EF9A3.2000603@davea.name> Message-ID: On Mar 24, 6:49?pm, Tim Chase wrote: > On 2013-03-24 09:03, Dave Angel wrote: > > > >> > > [THANK YOU!] > > > > Sorry my typo in the output here is the correct output that i > > > need : > > > > [('John Konon', 'Ministry of moon Walks', '4567882', '27-Feb'), > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > the difference is that i need a [(row two), (row three), (row > > > fouth)] . I do not want to display row one which is ['Name', ' > > > Address', 'Telephone', 'Birthday'] > > > I had to add a delimiter= to accomodate the fact that your data is > > tab- separated. > > Since it has headers, it might make more sense for readability to use > a DictReader: > > ? f = file("source.txt", "rb") > ? r = csv.DictReader(f, delimiter='\t') > ? for row in r: > ? ? print row["Name"], row["Address"], ... > > However, if it's just stripping off the first row and operating > directly on the resulting data, then I'd just be tempted to do > > ? r = csv.reader(f, delimiter='\t') > ? r.next() # discard the headers, or optionally store them > ? for row in r: > ? ? ... > > -tkc After doing: >>> import csv >>> original = file('friends.csv', 'rU') >>> reader = csv.reader(original, delimiter='\t') Stripping of the first line is: >>> list(reader)[1:] If for some reason you want to tuplify each row do either: >>> [tuple(row) for row in list(reader)[1:]] Or else >>> map(tuple,list(reader)[1:]) I usually prefer comprehensions to maps. Here though, the map is shorter. Your choice Then you can of course make your code more performant thus: >>> reader.next() >>> (tuple(row) for row in reader) In the majority of cases this optimization is not worth it In any case, strewing prints all over the code is a bad habit (except for debugging). From python.list at tim.thechases.com Sun Mar 24 14:28:44 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 24 Mar 2013 13:28:44 -0500 Subject: Separate Rows in reader In-Reply-To: References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> <514EF9A3.2000603@davea.name> Message-ID: <20130324132844.036ccc5c@bigbox.christie.dr> On 2013-03-24 08:57, rusi wrote: > On Mar 24, 6:49?pm, Tim Chase wrote: > After doing: > > >>> import csv > >>> original = file('friends.csv', 'rU') > >>> reader = csv.reader(original, delimiter='\t') > > > Stripping of the first line is: > >>> list(reader)[1:] > >>> [tuple(row) for row in list(reader)[1:]] > >>> map(tuple,list(reader)[1:]) This works for small sources, but slurps all the data into memory. Because csv.reader is an iterator/generator, it can process huge CSV files that wouldn't otherwise fit in memory. By using either r.next() (or "next(r)" in newer versions), it fetches one record from the generator, to be discarded/stored as appropriate. > Then you can of course make your code more performant thus: > >>> reader.next() > >>> (tuple(row) for row in reader) > > In the majority of cases this optimization is not worth it If the CSV file is large, using the iterator version is usually worth the small performance penalty, as you don't have to keep the whole file in memory. As somebody who regularly deals with 0.5-1GB CSV files from cellular providers, I speak from experience of having my machine choke when reading the whole thing in. > In any case, strewing prints all over the code is a bad habit > (except for debugging). Sorry if my print-statements were misinterpreted--I meant them as a "do what you want with the data here" stand-in (thus the ellipsis). -tkc From rustompmody at gmail.com Sun Mar 24 22:08:06 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 24 Mar 2013 19:08:06 -0700 (PDT) Subject: Separate Rows in reader References: <5a1660c3-ca17-452c-ae0f-ee61f4319a8f@googlegroups.com> <514EF9A3.2000603@davea.name> Message-ID: <85038974-11c7-49ba-9112-556b767d8062@ve4g2000pbc.googlegroups.com> On Mar 24, 11:28?pm, Tim Chase wrote: > > Sorry if my print-statements were misinterpreted--I meant them as a > "do what you want with the data here" stand-in (thus the ellipsis). Heh! I assumed the OP was a noob to whom this was directed (and whose original had the print statements in loops). > As somebody who regularly deals with 0.5-1GB CSV > files from cellular providers, I speak from experience of having my > machine choke when reading the whole thing in. If the 'friends.csv' of the OP goes up to 1GB... Now thats gregarious! From winter0128 at gmail.com Sun Mar 24 06:58:48 2013 From: winter0128 at gmail.com (ypsun) Date: Sun, 24 Mar 2013 03:58:48 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: Jiewei Huang? 2013?3?24????UTC+1??6?20?29???? > Hi all, > > > > Currently create a simple text-based database of information about people > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > Name Address Telephone Birthday > > John Konon Ministry of Moon Walks 4567882 27-Feb > > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > > > > My codes are : > > import csv > > original = file('friends.csv', 'rU') > > reader = csv.reader(original) > > > > for row in reader: > > > > print row > > > > > > and the output is : > > ['Name', ' Address', 'Telephone', 'Birthday'] > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > But i wanted to make it > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > can someone show me guidance to this issue > > > > Thanks all import csv original = file('friends.csv', 'rU') reader = csv.reader(original) result = [] for row in reader: result.append(tuple(row)) else: print result[1:] Is this what you need? but this allocates memory and will be a trouble when you have a big table :P Note that I assume your csv file content are comma seperated. From winter0128 at gmail.com Sun Mar 24 07:10:45 2013 From: winter0128 at gmail.com (ypsun) Date: Sun, 24 Mar 2013 04:10:45 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: Jiewei Huang? 2013?3?24????UTC+1??6?20?29???? > Hi all, > > > > Currently create a simple text-based database of information about people > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > Name Address Telephone Birthday > > John Konon Ministry of Moon Walks 4567882 27-Feb > > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > > > > My codes are : > > import csv > > original = file('friends.csv', 'rU') > > reader = csv.reader(original) > > > > for row in reader: > > > > print row > > > > > > and the output is : > > ['Name', ' Address', 'Telephone', 'Birthday'] > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > But i wanted to make it > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > can someone show me guidance to this issue > > > > Thanks all import csv original = file('friends.csv', 'rU') reader = csv.reader(original) print [tuple(row) for row in reader][1:] is this you want? Note that: 1) I assume your csv file content are seperated by comma 2) this way allocates your memory, will be a trouble when a big table :P From jiewei24 at gmail.com Mon Mar 25 02:52:50 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sun, 24 Mar 2013 23:52:50 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> On Sunday, March 24, 2013 9:10:45 PM UTC+10, ypsun wrote: > Jiewei Huang? 2013?3?24????UTC+1??6?20?29???? > > > Hi all, > > > > > > > > > > > > Currently create a simple text-based database of information about people > > > > > > > > > > > > > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > > > > Name Address Telephone Birthday > > > > > > John Konon Ministry of Moon Walks 4567882 27-Feb > > > > > > Stacy Kisha Ministry of Man Power 1234567 17-Jan > > > > > > > > > > > > > > > > > > My codes are : > > > > > > import csv > > > > > > original = file('friends.csv', 'rU') > > > > > > reader = csv.reader(original) > > > > > > > > > > > > for row in reader: > > > > > > > > > > > > print row > > > > > > > > > > > > > > > > > > and the output is : > > > > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > > > > > > > > > But i wanted to make it > > > > > > > > > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > > > > > > > > > can someone show me guidance to this issue > > > > > > > > > > > > Thanks all > > > > import csv > > original = file('friends.csv', 'rU') > > reader = csv.reader(original) > > print [tuple(row) for row in reader][1:] > > > > is this you want? > > Note that: > > 1) I assume your csv file content are seperated by comma > > 2) this way allocates your memory, will be a trouble when a big table :P Hi guys, i got into another situation i was told not to use csv library and currently my code is : f = open('friends.csv', 'rU') for row in f: print [row for (row) in f] output : ['John Cleese,Ministry of Silly Walks,5555421,27-Oct\n', 'Stacy Kisha,Ministry of Man Power,1234567,17-Jan\n'] i need it to become : [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan')] guide me please From rustompmody at gmail.com Mon Mar 25 09:51:51 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 25 Mar 2013 06:51:51 -0700 (PDT) Subject: Separate Rows in reader References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> Message-ID: On Mar 25, 11:52?am, Jiewei Huang wrote: > On Sunday, March 24, 2013 9:10:45 PM UTC+10, ypsun wrote: > > Jiewei Huang? 2013?3?24????UTC+1??6?20?29???? > > > > Hi all, > > > > Currently create a simple text-based database of information about people > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > > Name ? Address ? ? ? ?Telephone ? ? ? Birthday > > > > John Konon ? ?Ministry of Moon Walks ?4567882 27-Feb > > > > Stacy Kisha ? Ministry of Man Power ? 1234567 17-Jan > > > > My codes are : > > > > import csv > > > > original = file('friends.csv', 'rU') > > > > reader = csv.reader(original) > > > > for row in reader: > > > > ? ? print row > > > > and the output is : > > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > But i wanted to make it > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > can someone show me guidance to this issue > > > > Thanks all > > > import csv > > > original = file('friends.csv', 'rU') > > > reader = csv.reader(original) > > > print [tuple(row) for row in reader][1:] > > > is this you want? > > > Note that: > > > ? ? 1) I assume your csv file content are seperated by comma > > > ? ? 2) this way allocates your memory, will be a trouble when a big table :P > > Hi guys, i got into another situation i was told not to use csv library and currently my code is : > > f = open('friends.csv', 'rU') > for row in f: > > ? ? ? ? print [row for (row) in f] > > output : > ['John Cleese,Ministry of Silly Walks,5555421,27-Oct\n', 'Stacy Kisha,Ministry of Man Power,1234567,17-Jan\n'] > > i need it to become : > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan')] > > guide me please Have you tried the split (and perhaps strip) methods from http://docs.python.org/2/library/stdtypes.html#string-methods ? From jiewei24 at gmail.com Mon Mar 25 21:05:12 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Mon, 25 Mar 2013 18:05:12 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> Message-ID: <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > On Mar 25, 11:52?am, Jiewei Huang wrote: > > > On Sunday, March 24, 2013 9:10:45 PM UTC+10, ypsun wrote: > > > > Jiewei Huang? 2013?3?24????UTC+1??6?20?29???? > > > > > > > > Hi all, > > > > > > > > Currently create a simple text-based database of information about people > > > > > > > > I have a csv file which consist of 3 rows , row 1 2 and 3 is as such: > > > > > > > > Name ? Address ? ? ? ?Telephone ? ? ? Birthday > > > > > > > > John Konon ? ?Ministry of Moon Walks ?4567882 27-Feb > > > > > > > > Stacy Kisha ? Ministry of Man Power ? 1234567 17-Jan > > > > > > > > My codes are : > > > > > > > > import csv > > > > > > > > original = file('friends.csv', 'rU') > > > > > > > > reader = csv.reader(original) > > > > > > > > for row in reader: > > > > > > > > ? ? print row > > > > > > > > and the output is : > > > > > > > > ['Name', ' Address', 'Telephone', 'Birthday'] > > > > > > > > ['John Konon', 'Ministry of Moon Walks', '4567882', '27-Feb'] > > > > > > > > ['Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan'] > > > > > > > > But i wanted to make it > > > > > > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Feb'), > > > > > > > > ( 'Stacy Kisha', 'Ministry of Man Power', '1234567', 17-Jan')] > > > > > > > > can someone show me guidance to this issue > > > > > > > > Thanks all > > > > > > > import csv > > > > > > > original = file('friends.csv', 'rU') > > > > > > > reader = csv.reader(original) > > > > > > > print [tuple(row) for row in reader][1:] > > > > > > > is this you want? > > > > > > > Note that: > > > > > > > ? ? 1) I assume your csv file content are seperated by comma > > > > > > > ? ? 2) this way allocates your memory, will be a trouble when a big table :P > > > > > > Hi guys, i got into another situation i was told not to use csv library and currently my code is : > > > > > > f = open('friends.csv', 'rU') > > > for row in f: > > > > > > ? ? ? ? print [row for (row) in f] > > > > > > output : > > > ['John Cleese,Ministry of Silly Walks,5555421,27-Oct\n', 'Stacy Kisha,Ministry of Man Power,1234567,17-Jan\n'] > > > > > > i need it to become : > > > [('John Cleese', 'Ministry of Silly Walks', '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567', '17-Jan')] > > > > > > guide me please > > > > Have you tried the split (and perhaps strip) methods from > > http://docs.python.org/2/library/stdtypes.html#string-methods > > ? can show me one line of how to implement it base on my problem? From davea at davea.name Mon Mar 25 21:40:51 2013 From: davea at davea.name (Dave Angel) Date: Mon, 25 Mar 2013 21:40:51 -0400 Subject: Separate Rows in reader In-Reply-To: <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <5150FCA3.2010809@davea.name> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: If you insist on using GoogleGroups, then make sure you keep your quotes small. I'm about to stop reading messages that are double-spaced by buggy software. >>> >> >> >> >> Have you tried the split (and perhaps strip) methods from >> >> http://docs.python.org/2/library/stdtypes.html#string-methods >> >> ? You got lots of specific advice from your previous thread. So which version did you end up using? It'd make a good starting place for this "problem." > can show me one line of how to implement it base on my problem? > As long as the input data is constrained not to have any embedded commas, just use: mylist = line.split(",") instead of print, send your output to a list. Then for each line in the list, fix the bracket problem to your strange specs. outline = outline.replace("[", "(") -- -- DaveA From jiewei24 at gmail.com Mon Mar 25 23:33:03 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Mon, 25 Mar 2013 20:33:03 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > > If you insist on using GoogleGroups, then make sure you keep your quotes > > small. I'm about to stop reading messages that are double-spaced by > > buggy software. > > > > >>> > > >> > > > > >> > > >> > > >> Have you tried the split (and perhaps strip) methods from > > >> > > >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> > > >> ? > > > > You got lots of specific advice from your previous thread. So which > > version did you end up using? It'd make a good starting place for this > > "problem." > > > > > > > > > can show me one line of how to implement it base on my problem? > > > > > > > As long as the input data is constrained not to have any embedded > > commas, just use: > > > > mylist = line.split(",") > > > > > > instead of print, send your output to a list. Then for each line in the > > list, fix the bracket problem to your strange specs. > > > > outline = outline.replace("[", "(") > > > > -- > > -- > > DaveA Hi Dave thanks for the tips, I manage to code this: f = open('Book1.csv', 'rU') for row in f: print zip([row for (row) in f]) however my output is [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] is there any method to remove the \n ? From jiewei24 at gmail.com Mon Mar 25 23:33:03 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Mon, 25 Mar 2013 20:33:03 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > > If you insist on using GoogleGroups, then make sure you keep your quotes > > small. I'm about to stop reading messages that are double-spaced by > > buggy software. > > > > >>> > > >> > > > > >> > > >> > > >> Have you tried the split (and perhaps strip) methods from > > >> > > >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> > > >> ? > > > > You got lots of specific advice from your previous thread. So which > > version did you end up using? It'd make a good starting place for this > > "problem." > > > > > > > > > can show me one line of how to implement it base on my problem? > > > > > > > As long as the input data is constrained not to have any embedded > > commas, just use: > > > > mylist = line.split(",") > > > > > > instead of print, send your output to a list. Then for each line in the > > list, fix the bracket problem to your strange specs. > > > > outline = outline.replace("[", "(") > > > > -- > > -- > > DaveA Hi Dave thanks for the tips, I manage to code this: f = open('Book1.csv', 'rU') for row in f: print zip([row for (row) in f]) however my output is [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] is there any method to remove the \n ? From python at mrabarnett.plus.com Mon Mar 25 23:48:10 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Mar 2013 03:48:10 +0000 Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <51511A7A.8030807@mrabarnett.plus.com> On 26/03/2013 03:33, Jiewei Huang wrote: > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: >> >> If you insist on using GoogleGroups, then make sure you keep your quotes >> small. I'm about to stop reading messages that are double-spaced by >> buggy software. >> >> >>> >> >> Have you tried the split (and perhaps strip) methods from >> >> >> >> http://docs.python.org/2/library/stdtypes.html#string-methods >> >> >> >> ? >> >> You got lots of specific advice from your previous thread. So which >> version did you end up using? It'd make a good starting place for this >> "problem." >> >> > can show me one line of how to implement it base on my problem? >> > >> >> As long as the input data is constrained not to have any embedded >> commas, just use: >> >> mylist = line.split(",") >> >> instead of print, send your output to a list. Then for each line in the >> list, fix the bracket problem to your strange specs. >> >> outline = outline.replace("[", "(") > > Hi Dave thanks for the tips, > > I manage to code this: > f = open('Book1.csv', 'rU') > for row in f: > print zip([row for (row) in f]) > > however my output is > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > is there any method to remove the \n ? > Use the .rstrip method: print zip(row.rstrip('\n') for row in f) From jiewei24 at gmail.com Tue Mar 26 03:24:49 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Tue, 26 Mar 2013 00:24:49 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <749d7e2c-7a31-451e-8dbb-0594a52e8b91@googlegroups.com> On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > On 26/03/2013 03:33, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > >> > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > >> small. I'm about to stop reading messages that are double-spaced by > > >> buggy software. > > >> > > >> >>> > > >> >> Have you tried the split (and perhaps strip) methods from > > >> >> > > >> >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> >> > > >> >> ? > > >> > > >> You got lots of specific advice from your previous thread. So which > > >> version did you end up using? It'd make a good starting place for this > > >> "problem." > > >> > > >> > can show me one line of how to implement it base on my problem? > > >> > > > >> > > >> As long as the input data is constrained not to have any embedded > > >> commas, just use: > > >> > > >> mylist = line.split(",") > > >> > > >> instead of print, send your output to a list. Then for each line in the > > >> list, fix the bracket problem to your strange specs. > > >> > > >> outline = outline.replace("[", "(") > > > > > > Hi Dave thanks for the tips, > > > > > > I manage to code this: > > > f = open('Book1.csv', 'rU') > > > for row in f: > > > print zip([row for (row) in f]) > > > > > > however my output is > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > is there any method to remove the \n ? > > > > > Use the .rstrip method: > > > > print zip(row.rstrip('\n') for row in f) thanks ! got it working! From jiewei24 at gmail.com Tue Mar 26 03:24:49 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Tue, 26 Mar 2013 00:24:49 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <749d7e2c-7a31-451e-8dbb-0594a52e8b91@googlegroups.com> On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > On 26/03/2013 03:33, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > >> > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > >> small. I'm about to stop reading messages that are double-spaced by > > >> buggy software. > > >> > > >> >>> > > >> >> Have you tried the split (and perhaps strip) methods from > > >> >> > > >> >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> >> > > >> >> ? > > >> > > >> You got lots of specific advice from your previous thread. So which > > >> version did you end up using? It'd make a good starting place for this > > >> "problem." > > >> > > >> > can show me one line of how to implement it base on my problem? > > >> > > > >> > > >> As long as the input data is constrained not to have any embedded > > >> commas, just use: > > >> > > >> mylist = line.split(",") > > >> > > >> instead of print, send your output to a list. Then for each line in the > > >> list, fix the bracket problem to your strange specs. > > >> > > >> outline = outline.replace("[", "(") > > > > > > Hi Dave thanks for the tips, > > > > > > I manage to code this: > > > f = open('Book1.csv', 'rU') > > > for row in f: > > > print zip([row for (row) in f]) > > > > > > however my output is > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > is there any method to remove the \n ? > > > > > Use the .rstrip method: > > > > print zip(row.rstrip('\n') for row in f) thanks ! got it working! From jiewei24 at gmail.com Wed Mar 27 05:35:29 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Wed, 27 Mar 2013 02:35:29 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > On 26/03/2013 03:33, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > >> > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > >> small. I'm about to stop reading messages that are double-spaced by > > >> buggy software. > > >> > > >> >>> > > >> >> Have you tried the split (and perhaps strip) methods from > > >> >> > > >> >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> >> > > >> >> ? > > >> > > >> You got lots of specific advice from your previous thread. So which > > >> version did you end up using? It'd make a good starting place for this > > >> "problem." > > >> > > >> > can show me one line of how to implement it base on my problem? > > >> > > > >> > > >> As long as the input data is constrained not to have any embedded > > >> commas, just use: > > >> > > >> mylist = line.split(",") > > >> > > >> instead of print, send your output to a list. Then for each line in the > > >> list, fix the bracket problem to your strange specs. > > >> > > >> outline = outline.replace("[", "(") > > > > > > Hi Dave thanks for the tips, > > > > > > I manage to code this: > > > f = open('Book1.csv', 'rU') > > > for row in f: > > > print zip([row for (row) in f]) > > > > > > however my output is > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > is there any method to remove the \n ? > > > > > Use the .rstrip method: > > > > print zip(row.rstrip('\n') for row in f) Hi the output is: [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] how to make it to [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] i need ' ' in all the row and the , to be remove after the date From jiewei24 at gmail.com Wed Mar 27 05:35:29 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Wed, 27 Mar 2013 02:35:29 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > On 26/03/2013 03:33, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > >> > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > >> small. I'm about to stop reading messages that are double-spaced by > > >> buggy software. > > >> > > >> >>> > > >> >> Have you tried the split (and perhaps strip) methods from > > >> >> > > >> >> http://docs.python.org/2/library/stdtypes.html#string-methods > > >> >> > > >> >> ? > > >> > > >> You got lots of specific advice from your previous thread. So which > > >> version did you end up using? It'd make a good starting place for this > > >> "problem." > > >> > > >> > can show me one line of how to implement it base on my problem? > > >> > > > >> > > >> As long as the input data is constrained not to have any embedded > > >> commas, just use: > > >> > > >> mylist = line.split(",") > > >> > > >> instead of print, send your output to a list. Then for each line in the > > >> list, fix the bracket problem to your strange specs. > > >> > > >> outline = outline.replace("[", "(") > > > > > > Hi Dave thanks for the tips, > > > > > > I manage to code this: > > > f = open('Book1.csv', 'rU') > > > for row in f: > > > print zip([row for (row) in f]) > > > > > > however my output is > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > is there any method to remove the \n ? > > > > > Use the .rstrip method: > > > > print zip(row.rstrip('\n') for row in f) Hi the output is: [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] how to make it to [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] i need ' ' in all the row and the , to be remove after the date From rustompmody at gmail.com Wed Mar 27 07:18:28 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Mar 2013 04:18:28 -0700 (PDT) Subject: Separate Rows in reader References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> Message-ID: <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> On Mar 27, 2:35?pm, Jiewei Huang wrote: > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > > On 26/03/2013 03:33, Jiewei Huang wrote: > > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > > >> small. ?I'm about to stop reading messages that are double-spaced by > > > >> buggy software. > > > >> >>> > > > >> >> Have you tried the split (and perhaps strip) methods from > > > >> >>http://docs.python.org/2/library/stdtypes.html#string-methods > > > >> >> ? > > > >> You got lots of specific advice from your previous thread. ?So which > > > >> version did you end up using? ?It'd make a good starting place for this > > > >> "problem." > > > >> > can show me one line of how to implement it base on my problem? > > > >> As long as the input data is constrained not to have any embedded > > > >> commas, just use: > > > >> ? ? ?mylist = line.split(",") > > > >> instead of print, send your output to a list. ?Then for each line in the > > > >> list, fix the bracket problem to your strange specs. > > > >> ? ? ?outline = outline.replace("[", "(") > > > > Hi Dave thanks for the tips, > > > > I manage to code this: > > > > f = open('Book1.csv', 'rU') > > > > for row in f: > > > > ? ? ?print zip([row for (row) in f]) > > > > however my output is > > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > is there any method to remove the \n ? > > > Use the .rstrip method: > > > ? ? ?print zip(row.rstrip('\n') for row in f) > > Hi the output is: > > [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] > > how to make it to > > [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] > > i need ' ' in all the row and the , to be remove after the date Everything you need for this has been answered by Tim, Dave, myself (and others?). If you are stuck, tell us where. If something did not work, tell us what. Dont you think if you are asking us to do your homework, you should offer us a little fee? From jiewei24 at gmail.com Wed Mar 27 18:12:15 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Wed, 27 Mar 2013 15:12:15 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> Message-ID: <4bc1553a-0689-4adc-b243-27c58865d639@googlegroups.com> On Wednesday, March 27, 2013 9:18:28 PM UTC+10, rusi wrote: > On Mar 27, 2:35?pm, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > > > > On 26/03/2013 03:33, Jiewei Huang wrote: > > > > > > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > > > > > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > > > > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > > > > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > > > > > > >> small. ?I'm about to stop reading messages that are double-spaced by > > > > > > > >> buggy software. > > > > > > > >> >>> > > > > > > > >> >> Have you tried the split (and perhaps strip) methods from > > > > > > > >> >>http://docs.python.org/2/library/stdtypes.html#string-methods > > > > > > > >> >> ? > > > > > > > >> You got lots of specific advice from your previous thread. ?So which > > > > > > > >> version did you end up using? ?It'd make a good starting place for this > > > > > > > >> "problem." > > > > > > > >> > can show me one line of how to implement it base on my problem? > > > > > > > >> As long as the input data is constrained not to have any embedded > > > > > > > >> commas, just use: > > > > > > > >> ? ? ?mylist = line.split(",") > > > > > > > >> instead of print, send your output to a list. ?Then for each line in the > > > > > > > >> list, fix the bracket problem to your strange specs. > > > > > > > >> ? ? ?outline = outline.replace("[", "(") > > > > > > > > Hi Dave thanks for the tips, > > > > > > > > I manage to code this: > > > > > > > > f = open('Book1.csv', 'rU') > > > > > > > > for row in f: > > > > > > > > ? ? ?print zip([row for (row) in f]) > > > > > > > > however my output is > > > > > > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > > > is there any method to remove the \n ? > > > > > > > Use the .rstrip method: > > > > > > > ? ? ?print zip(row.rstrip('\n') for row in f) > > > > > > Hi the output is: > > > > > > [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] > > > > > > how to make it to > > > > > > [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] > > > > > > i need ' ' in all the row and the , to be remove after the date > > > > Everything you need for this has been answered by Tim, Dave, myself > > (and others?). > > If you are stuck, tell us where. > > If something did not work, tell us what. > > > > Dont you think if you are asking us to do your homework, you should > > offer us a little fee? Hi Rusi, I'm struck and i did say what did not work and i did follow your guideline and i did come out with my own code which come out as a same result ( look at the #) not is not the one i need. f = open('friends.csv', 'rU') for row in f: #print zip([row.rstrip() for (row) in f]) print zip(row.rstrip('\n') for (row) in f) From jiewei24 at gmail.com Wed Mar 27 18:26:22 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Wed, 27 Mar 2013 15:26:22 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> Message-ID: <0696fc8d-5325-438d-82b9-c0f95f8593d5@googlegroups.com> On Wednesday, March 27, 2013 9:18:28 PM UTC+10, rusi wrote: > On Mar 27, 2:35?pm, Jiewei Huang wrote: > > > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > > > > On 26/03/2013 03:33, Jiewei Huang wrote: > > > > > > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > > > > > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > > > > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > > > > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > > > > > > >> small. ?I'm about to stop reading messages that are double-spaced by > > > > > > > >> buggy software. > > > > > > > >> >>> > > > > > > > >> >> Have you tried the split (and perhaps strip) methods from > > > > > > > >> >>http://docs.python.org/2/library/stdtypes.html#string-methods > > > > > > > >> >> ? > > > > > > > >> You got lots of specific advice from your previous thread. ?So which > > > > > > > >> version did you end up using? ?It'd make a good starting place for this > > > > > > > >> "problem." > > > > > > > >> > can show me one line of how to implement it base on my problem? > > > > > > > >> As long as the input data is constrained not to have any embedded > > > > > > > >> commas, just use: > > > > > > > >> ? ? ?mylist = line.split(",") > > > > > > > >> instead of print, send your output to a list. ?Then for each line in the > > > > > > > >> list, fix the bracket problem to your strange specs. > > > > > > > >> ? ? ?outline = outline.replace("[", "(") > > > > > > > > Hi Dave thanks for the tips, > > > > > > > > I manage to code this: > > > > > > > > f = open('Book1.csv', 'rU') > > > > > > > > for row in f: > > > > > > > > ? ? ?print zip([row for (row) in f]) > > > > > > > > however my output is > > > > > > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > > > is there any method to remove the \n ? > > > > > > > Use the .rstrip method: > > > > > > > ? ? ?print zip(row.rstrip('\n') for row in f) > > > > > > Hi the output is: > > > > > > [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] > > > > > > how to make it to > > > > > > [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] > > > > > > i need ' ' in all the row and the , to be remove after the date > > > > Everything you need for this has been answered by Tim, Dave, myself > > (and others?). > > If you are stuck, tell us where. > > If something did not work, tell us what. > > > > Dont you think if you are asking us to do your homework, you should > > offer us a little fee? Hi Rusi, I'm truly struck and I did mention what did not work and i did follow the link you gave and i did come out with my own code which come out as a same result ( look at the #) however it is not the one i need. f = open('friends.csv', 'rU') for row in f: #print zip([row.rstrip() for (row) in f]) print zip(row.rstrip('\n') for (row) in f) From rustompmody at gmail.com Wed Mar 27 21:24:24 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Mar 2013 18:24:24 -0700 (PDT) Subject: Separate Rows in reader References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> <0696fc8d-5325-438d-82b9-c0f95f8593d5@googlegroups.com> Message-ID: <3b7f12b2-b394-4c22-a3af-8022df371336@mz7g2000pbb.googlegroups.com> On Mar 28, 3:26?am, Jiewei Huang wrote: > On Wednesday, March 27, 2013 9:18:28 PM UTC+10, rusi wrote: > > On Mar 27, 2:35?pm, Jiewei Huang wrote: > > > > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: > > > > > On 26/03/2013 03:33, Jiewei Huang wrote: > > > > > > On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: > > > > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: > > > > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: > > > > > >> If you insist on using GoogleGroups, then make sure you keep your quotes > > > > > >> small. ?I'm about to stop reading messages that are double-spaced by > > > > > >> buggy software. > > > > > >> >>> > > > > > >> >> Have you tried the split (and perhaps strip) methods from > > > > > >> >>http://docs.python.org/2/library/stdtypes.html#string-methods > > > > > >> >> ? > > > > > >> You got lots of specific advice from your previous thread. ?So which > > > > > >> version did you end up using? ?It'd make a good starting place for this > > > > > >> "problem." > > > > > >> > can show me one line of how to implement it base on my problem? > > > > > >> As long as the input data is constrained not to have any embedded > > > > > >> commas, just use: > > > > > >> ? ? ?mylist = line.split(",") > > > > > >> instead of print, send your output to a list. ?Then for each line in the > > > > > >> list, fix the bracket problem to your strange specs. > > > > > >> ? ? ?outline = outline.replace("[", "(") > > > > > > Hi Dave thanks for the tips, > > > > > > I manage to code this: > > > > > > f = open('Book1.csv', 'rU') > > > > > > for row in f: > > > > > > ? ? ?print zip([row for (row) in f]) > > > > > > however my output is > > > > > > [('John Konon Ministry of Moon Walks 4567882 27-Feb\n',), ('Stacy Kisha Ministry of Man Power 1234567 17-Jan\n',)] > > > > > > is there any method to remove the \n ? > > > > > Use the .rstrip method: > > > > > ? ? ?print zip(row.rstrip('\n') for row in f) > > > > Hi the output is: > > > > [('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] > > > > how to make it to > > > > [CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] > > > > i need ' ' in all the row and the , to be remove after the date > > > Everything you need for this has been answered by Tim, Dave, myself > > > (and others?). > > > If you are stuck, tell us where. > > > If something did not work, tell us what. > > > Dont you think if you are asking us to do your homework, you should > > > offer us a little fee? > > Hi Rusi, > > I'm truly struck and I did mention what did not work and i did follow the link you gave and i did come out with my own code which come out as a same result ( look at the #) however it is not the one i need. > > f = open('friends.csv', 'rU') > for row in f: > ? ? #print zip([row.rstrip() for (row) in f]) > ? ? print zip(row.rstrip('\n') for (row) in f) >>> s=' John Cleese, Ministry of Silly Walks,5555421,27-Oct \n' >>> s.split(',') [' John Cleese', ' Ministry of Silly Walks', '5555421', '27-Oct \n'] >>> s.strip().split(',') ['John Cleese', ' Ministry of Silly Walks', '5555421', '27-Oct'] >>> From steve+comp.lang.python at pearwood.info Wed Mar 27 21:32:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 01:32:37 GMT Subject: Separate Rows in reader References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> <45072d2b-e8ca-4888-92bc-2556c2c7568c@googlegroups.com> <3c1afe44-1eb4-4074-8f85-540c2a4bb842@oz4g2000pbc.googlegroups.com> <0696fc8d-5325-438d-82b9-c0f95f8593d5@googlegroups.com> <3b7f12b2-b394-4c22-a3af-8022df371336@mz7g2000pbb.googlegroups.com> Message-ID: <51539db5$0$29998$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 18:24:24 -0700, rusi wrote: > On Mar 28, 3:26?am, Jiewei Huang wrote: >> On Wednesday, March 27, 2013 9:18:28 PM UTC+10, rusi wrote: >> > On Mar 27, 2:35?pm, Jiewei Huang wrote: >> > > On Tuesday, March 26, 2013 1:48:10 PM UTC+10, MRAB wrote: >> > > > On 26/03/2013 03:33, Jiewei Huang wrote: >> > > >> On Tuesday, March 26, 2013 11:40:51 AM UTC+10, Dave Angel wrote: >> > > > >> On 03/25/2013 09:05 PM, Jiewei Huang wrote: >> > > > >>> On Monday, March 25, 2013 11:51:51 PM UTC+10, rusi wrote: Eight levels of attribution. And I count up to nine levels of quoting. Doesn't anyone have a working backspace key in their editor? Please trim your responses to what's needed to establish context, there's no need to keep the entire thread duplicated in every post. -- Steven From timr at probo.com Fri Mar 29 00:28:04 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 28 Mar 2013 21:28:04 -0700 Subject: Separate Rows in reader References: <4e1e93e5-14bd-4408-9c92-3c340e558deb@googlegroups.com> <3054bd15-f3d3-4568-aea2-567dd6d762de@googlegroups.com> Message-ID: Jiewei Huang wrote: > >Hi the output is: > >[('John Cleese,Ministry of Silly Walks,5555421,27-Oct',), ('Stacy Kisha,Ministry of Man Power,1234567,17-Jan',)] > >how to make it to > >[CODE][('John Cleese', 'Ministry of Silly Walks' , '5555421', '27-Oct'), ('Stacy Kisha', 'Ministry of Man Power', '1234567,17-Jan')][/CODE] > >i need ' ' in all the row and the , to be remove after the date Do you have any intention of doing ANY of this work on your own? Or are you going to steal it all? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jiewei24 at gmail.com Sun Mar 24 21:15:32 2013 From: jiewei24 at gmail.com (Jiewei Huang) Date: Sun, 24 Mar 2013 18:15:32 -0700 (PDT) Subject: Separate Rows in reader In-Reply-To: References: Message-ID: On Sunday, March 24, 2013 3:20:29 PM UTC+10, Jiewei Huang wrote: thanks to you guys i got my desire outcome! i will continue to code on writing and saving of csv file From fuj.tyoli at gmail.com Sun Mar 24 11:35:29 2013 From: fuj.tyoli at gmail.com (yahya Kacem) Date: Sun, 24 Mar 2013 08:35:29 -0700 (PDT) Subject: ImportError: No module named multipli Message-ID: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Hi, i have this 2 files: file named multipli: #!/usr/bin/python3.2 #-* - coding : utf-8 -* def table(nb, max): i = 0 while i < max: print(i + 1, " * ", nb, "= ", (i + 1) * nb) and file naled test: #!/usr/bin/python3.2 # -* - coding : utf-8 -* import os import sys from multipli import table table(3, 20) os.system("pause") when i run this: python3 test I get this error: Traceback (most recent call last): File "test", line 5, in from multipli import table ImportError: No module named multipli both files are in the same directory. any help thanks in advance. From kwpolska at gmail.com Sun Mar 24 11:46:24 2013 From: kwpolska at gmail.com (Kwpolska) Date: Sun, 24 Mar 2013 16:46:24 +0100 Subject: ImportError: No module named multipli In-Reply-To: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: On Sun, Mar 24, 2013 at 4:35 PM, yahya Kacem wrote: > Hi, i have this 2 files: > > file named multipli: > > #!/usr/bin/python3.2 > #-* - coding : utf-8 -* > def table(nb, max): > i = 0 > while i < max: > print(i + 1, " * ", nb, "= ", (i + 1) * nb) > > and file naled test: > > #!/usr/bin/python3.2 > # -* - coding : utf-8 -* > import os > import sys > from multipli import table > table(3, 20) > os.system("pause") > > when i run this: > > python3 test > > I get this error: > Traceback (most recent call last): > File "test", line 5, in > from multipli import table > ImportError: No module named multipli > both files are in the same directory. > any help thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list make them test.py and multipli.py. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From rosuav at gmail.com Sun Mar 24 11:48:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Mar 2013 02:48:41 +1100 Subject: ImportError: No module named multipli In-Reply-To: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem wrote: > file named multipli: > > and file naled test: > > from multipli import table Try naming it multipli.py ChrisA From breamoreboy at yahoo.co.uk Sun Mar 24 12:10:58 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Mar 2013 16:10:58 +0000 Subject: ImportError: No module named multipli In-Reply-To: References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: On 24/03/2013 15:48, Chris Angelico wrote: > On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem wrote: >> file named multipli: >> >> and file naled test: >> >> from multipli import table > > Try naming it multipli.py > > ChrisA > Before or after fixing the infinite loop? :) -- Cheers. Mark Lawrence From rosuav at gmail.com Sun Mar 24 12:15:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Mar 2013 03:15:21 +1100 Subject: ImportError: No module named multipli In-Reply-To: References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: On Mon, Mar 25, 2013 at 3:10 AM, Mark Lawrence wrote: > On 24/03/2013 15:48, Chris Angelico wrote: >> >> On Mon, Mar 25, 2013 at 2:35 AM, yahya Kacem wrote: >>> >>> file named multipli: >>> >>> and file naled test: >>> >>> from multipli import table >> >> >> Try naming it multipli.py >> >> ChrisA >> > > Before or after fixing the infinite loop? :) Before. Then you run it, see it spew text to the console, and hit Ctrl-C. Programming is iterative: once you fix one problem, you find the next. Programming is also recursive: in fixing one problem, you sometimes have to deal with others that it depends on. Programming is functional, too: you take a list of problems, apply the "Code" function to them, and keep the list of return values, which will be hopefully-working code. And programming is object-oriented... whatever you do, someone will object to it. ChrisA From fuj.tyoli at gmail.com Sun Mar 24 12:03:52 2013 From: fuj.tyoli at gmail.com (yahya Kacem) Date: Sun, 24 Mar 2013 09:03:52 -0700 (PDT) Subject: ImportError: No module named multipli In-Reply-To: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: <5b53566a-b924-4b13-9cb6-08105e97db0d@googlegroups.com> On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote: > Hi, i have this 2 files: > > > > file named multipli: > > > > #!/usr/bin/python3.2 > > #-* - coding : utf-8 -* > > def table(nb, max): > > i = 0 > > while i < max: > > print(i + 1, " * ", nb, "= ", (i + 1) * nb) > > > > and file naled test: > > > > #!/usr/bin/python3.2 > > # -* - coding : utf-8 -* > > import os > > import sys > > from multipli import table > > table(3, 20) > > os.system("pause") > > > > when i run this: > > > > python3 test > > > > I get this error: > > Traceback (most recent call last): > > File "test", line 5, in > > from multipli import table > > ImportError: No module named multipli > > both files are in the same directory. > > any help thanks in advance. Thanks that did it. From breamoreboy at yahoo.co.uk Sun Mar 24 12:19:29 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Mar 2013 16:19:29 +0000 Subject: ImportError: No module named multipli In-Reply-To: <5b53566a-b924-4b13-9cb6-08105e97db0d@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> <5b53566a-b924-4b13-9cb6-08105e97db0d@googlegroups.com> Message-ID: On 24/03/2013 16:03, yahya Kacem wrote: > On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote: >> Hi, i have this 2 files: >> >> >> >> file named multipli: >> >> >> >> #!/usr/bin/python3.2 >> >> #-* - coding : utf-8 -* >> >> def table(nb, max): >> >> i = 0 >> >> while i < max: >> >> print(i + 1, " * ", nb, "= ", (i + 1) * nb) >> >> >> >> and file naled test: >> >> >> >> #!/usr/bin/python3.2 >> >> # -* - coding : utf-8 -* >> >> import os >> >> import sys >> >> from multipli import table >> >> table(3, 20) >> >> os.system("pause") >> >> >> >> when i run this: >> >> >> >> python3 test >> >> >> >> I get this error: >> >> Traceback (most recent call last): >> >> File "test", line 5, in >> >> from multipli import table >> >> ImportError: No module named multipli >> >> both files are in the same directory. >> >> any help thanks in advance. > > Thanks that did it. > May I ask what did it? Please read this as it helps prevent the bill from my optician soaring http://wiki.python.org/moin/GoogleGroupsPython -- Cheers. Mark Lawrence From fuj.tyoli at gmail.com Sun Mar 24 19:06:53 2013 From: fuj.tyoli at gmail.com (yahya Kacem) Date: Sun, 24 Mar 2013 16:06:53 -0700 (PDT) Subject: ImportError: No module named multipli In-Reply-To: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: On Sunday, March 24, 2013 4:35:29 PM UTC+1, yahya Kacem wrote: > Hi, i have this 2 files: > > > > file named multipli: > > > > #!/usr/bin/python3.2 > > #-* - coding : utf-8 -* > > def table(nb, max): > > i = 0 > > while i < max: > > print(i + 1, " * ", nb, "= ", (i + 1) * nb) > > > > and file naled test: > > > > #!/usr/bin/python3.2 > > # -* - coding : utf-8 -* > > import os > > import sys > > from multipli import table > > table(3, 20) > > os.system("pause") > > > > when i run this: > > > > python3 test > > > > I get this error: > > Traceback (most recent call last): > > File "test", line 5, in > > from multipli import table > > ImportError: No module named multipli > > both files are in the same directory. > > any help thanks in advance. Hi, after fixing the infinite loop, there was a missing line in my first post inside the while loop I accidentally deleted this line: i += 1; Sorry for that. adding the .py to the file name (the one to import) did fix the problem, thanks for the help. From fuj.tyoli at gmail.com Sun Mar 24 19:12:07 2013 From: fuj.tyoli at gmail.com (yahya Kacem) Date: Sun, 24 Mar 2013 16:12:07 -0700 (PDT) Subject: ImportError: No module named multipli In-Reply-To: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> References: <2c7cb491-62d7-43f6-a1fd-ea8ea8833cda@googlegroups.com> Message-ID: <3ee2e134-ce86-4950-9fbd-7c81e5023c1c@googlegroups.com> +Mark Lawrence sorry for that I'm new here and I didn't know about that. From l.selmi at icloud.com Sun Mar 24 13:24:54 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Sun, 24 Mar 2013 18:24:54 +0100 Subject: i need advice Message-ID: dear python programmers, i am focused on learning to program but i need help from all of you. i am a beginner but it is hard to find the right book or website to learn, i know that i have to do exercises but so far i found resources with gaps. i would be very grateful if you could give me suggestions. for example i have "think python" and "learning python the hard way", do you recommend them or are there better books? thanks a lot and sorry for bugging you best regards leonardo From joel.goldstick at gmail.com Sun Mar 24 13:33:30 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 24 Mar 2013 13:33:30 -0400 Subject: i need advice In-Reply-To: References: Message-ID: On Sun, Mar 24, 2013 at 1:24 PM, leonardo selmi wrote: > dear python programmers, > > i am focused on learning to program but i need help from all of you. i am > a beginner but it is hard to find the right book or website to learn, i > know that i have to do exercises but so far i found resources with gaps. i > would be very grateful if you could give me suggestions. for example i have > "think python" and "learning python the hard way", do you recommend them or > are there better books? > > thanks a lot and sorry for bugging you > > best regards > Start here: http://www.python.org/about/help/ and especially http://wiki.python.org/moin/BeginnersGuide Everyone learns in their own way so keep trying different resources until you find what works best for you. > > leonardo > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Mar 24 13:37:34 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Mar 2013 17:37:34 +0000 Subject: i need advice In-Reply-To: References: Message-ID: On 24/03/2013 17:24, leonardo selmi wrote: > dear python programmers, > > i am focused on learning to program but i need help from all of you. i am a beginner but it is hard to find the right book or website to learn, i know that i have to do exercises but so far i found resources with gaps. i would be very grateful if you could give me suggestions. for example i have "think python" and "learning python the hard way", do you recommend them or are there better books? > > thanks a lot and sorry for bugging you > > best regards > > leonardo > Start here http://wiki.python.org/moin/BeginnersGuide ? -- Cheers. Mark Lawrence From omerkorat at gmail.com Sun Mar 24 13:35:58 2013 From: omerkorat at gmail.com (Omer) Date: Sun, 24 Mar 2013 19:35:58 +0200 Subject: i need advice In-Reply-To: References: Message-ID: I know some people will disagree with me, but I recommend on "Dive Into Python" by Mark Pilgrim. It assumes no prior knowledge whatsoever, and it explains all the foundations of the language from the bottom up, without skipping any steps. It also provides many examples that demonstrate how to get Python to do things. On 24 March 2013 19:24, leonardo selmi wrote: > dear python programmers, > > i am focused on learning to program but i need help from all of you. i am > a beginner but it is hard to find the right book or website to learn, i > know that i have to do exercises but so far i found resources with gaps. i > would be very grateful if you could give me suggestions. for example i have > "think python" and "learning python the hard way", do you recommend them or > are there better books? > > thanks a lot and sorry for bugging you > > best regards > > leonardo > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From l.selmi at icloud.com Sun Mar 24 13:22:10 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Sun, 24 Mar 2013 18:22:10 +0100 Subject: i need advice Message-ID: dear python programmers, i am focused on learning to program but i need help from all of you. i am a beginner but it is hard to find the right book or website to learn, i know that i have to do exercises but so far i found resources with gaps. i would be very grateful if you could give me suggestions. for example i have "think python" and "learning python the hard way", do you recommend them or are there better books? thanks a lot and sorry for bugging you best regards leonardo From fromberg100 at hotmail.com Sun Mar 24 19:12:49 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Sun, 24 Mar 2013 18:12:49 -0500 Subject: import in Python3.3 Message-ID: Hi, I have a package name collections and inside of my package I want to import the collections package from the standard library, but there is name conflicts. How do I import explicitly from the standard library? Im working on Python3.3 Thanks in advance and regards, Fabian From steve+comp.lang.python at pearwood.info Sun Mar 24 20:27:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2013 00:27:56 GMT Subject: import in Python3.3 References: Message-ID: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > Hi, > > I have a package name collections and inside of my package I want to > import the collections package from the standard library, but there is > name conflicts. > > How do I import explicitly from the standard library? You can't. However, you can import explicitly from your package, or implicitly by using a relative import. Starting from Python 2.7, the "import" statement is always absolute. So the line: import collections will always find the first *top level* module or package "collections" in the python search path. See below for an important proviso. Inside your package, you can either use an explicit import like this: import mypackage.collections as collections or use a relative import like this: from . import collections Here is a concrete example. I create a package containing five files: mypackage/ +-- __init__.py +-- collections.py +-- absolute_import.py +-- explicit_import.py +-- relative_import.py with the following content: # absolute_import.py import collections # explicit_import.py import mypackage.collections as collections # relative_import.py from . import collections The other two files (collections.py and __init__.py) can be blank. Now, from *outside* the package, I can do this: py> import mypackage.absolute_import py> import mypackage.explicit_import py> import mypackage.relative_import py> py> mypackage.absolute_import.collections py> mypackage.explicit_import.collections py> mypackage.relative_import.collections Of course "from mypackage import absolute_import" etc. will also work. However, beware: if you cd into the package directory, and then launch Python, the current directory will contain a file "collections.py" which will shadow the standard library collections.py. So don't do that. -- Steven From fromberg100 at hotmail.com Sun Mar 24 21:39:29 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Sun, 24 Mar 2013 20:39:29 -0500 Subject: import in Python3.3 In-Reply-To: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, thanks a lot for the explanation. I will keep in mind not to use names for my modules that can shadow the standard library. Regards, Fabian On 03/24/2013 07:27 PM, Steven D'Aprano wrote: > On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > >> Hi, >> >> I have a package name collections and inside of my package I want to >> import the collections package from the standard library, but there is >> name conflicts. >> >> How do I import explicitly from the standard library? > > You can't. However, you can import explicitly from your package, or > implicitly by using a relative import. > > Starting from Python 2.7, the "import" statement is always absolute. So > the line: > > import collections > > will always find the first *top level* module or package "collections" in > the python search path. See below for an important proviso. > > Inside your package, you can either use an explicit import like this: > > import mypackage.collections as collections > > or use a relative import like this: > > from . import collections > > Here is a concrete example. I create a package containing five files: > > mypackage/ > +-- __init__.py > +-- collections.py > +-- absolute_import.py > +-- explicit_import.py > +-- relative_import.py > > with the following content: > > # absolute_import.py > import collections > > # explicit_import.py > import mypackage.collections as collections > > # relative_import.py > from . import collections > > > The other two files (collections.py and __init__.py) can be blank. Now, > from *outside* the package, I can do this: > > > py> import mypackage.absolute_import > py> import mypackage.explicit_import > py> import mypackage.relative_import > py> > py> mypackage.absolute_import.collections > > py> mypackage.explicit_import.collections > > py> mypackage.relative_import.collections > > > > Of course "from mypackage import absolute_import" etc. will also work. > > > However, beware: if you cd into the package directory, and then launch > Python, the current directory will contain a file "collections.py" which > will shadow the standard library collections.py. So don't do that. > > > From rocky at gnu.org Mon Mar 25 23:49:06 2013 From: rocky at gnu.org (rocky) Date: Mon, 25 Mar 2013 20:49:06 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> On Sunday, March 24, 2013 8:27:56 PM UTC-4, Steven D'Aprano wrote: > On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > > > > > Hi, > > > > > > I have a package name collections and inside of my package I want to > > > import the collections package from the standard library, but there is > > > name conflicts. > > > > > > How do I import explicitly from the standard library? > > > > You can't. However, you can import explicitly from your package, or > > implicitly by using a relative import. > > > > Starting from Python 2.7, the "import" statement is always absolute. So > > the line: > > > > import collections > > > > will always find the first *top level* module or package "collections" in > > the python search path. See below for an important proviso. > > > > Inside your package, you can either use an explicit import like this: > > > > import mypackage.collections as collections > > > > or use a relative import like this: > > > > from . import collections > > > > Here is a concrete example. I create a package containing five files: > > > > mypackage/ > > +-- __init__.py > > +-- collections.py > > +-- absolute_import.py > > +-- explicit_import.py > > +-- relative_import.py > > > > with the following content: > > > > # absolute_import.py > > import collections > > > > # explicit_import.py > > import mypackage.collections as collections > > > > # relative_import.py > > from . import collections > > > > > > The other two files (collections.py and __init__.py) can be blank. Now, > > from *outside* the package, I can do this: > > > > > > py> import mypackage.absolute_import > > py> import mypackage.explicit_import > > py> import mypackage.relative_import > > py> > > py> mypackage.absolute_import.collections > > > > py> mypackage.explicit_import.collections > > > > py> mypackage.relative_import.collections > > > > > > > > Of course "from mypackage import absolute_import" etc. will also work. > > > > > > However, beware: if you cd into the package directory, and then launch > > Python, the current directory will contain a file "collections.py" which > > will shadow the standard library collections.py. So don't do that. I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like "collections", why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections It was for this reason I wrote import_relative http://code.google.com/p/pyimport-relative/. It is far from perfect, but it pleases me to think that I one can adjust the language to do reasonable things rather than having it bend me into figuring out what's out there and limit the choice of names I use in submodules. > > > > > > > > -- > > Steven From malaclypse2 at gmail.com Tue Mar 26 12:33:54 2013 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 26 Mar 2013 12:33:54 -0400 Subject: import in Python3.3 In-Reply-To: <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> Message-ID: On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote: >> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: >> > I have a package name collections and inside of my package I want to > I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like "collections", why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections You've said a couple of times now that the original author has a package named "mypackage" with a module "collections" in it. As far as I can tell, that's untrue. The original post claims to have a package named "collections", which is colliding with the builtin module of the same name. As far as I can tell, all of your suggestions about using your pyimport-relative tool aren't helpful unless the author re-names his package from "collections" to "mypackage" and then moves all of their code into a "collections" module inside "mypackage", right? -- Jerry From rocky at gnu.org Tue Mar 26 14:41:57 2013 From: rocky at gnu.org (rocky) Date: Tue, 26 Mar 2013 11:41:57 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> Message-ID: <8dc18c81-dbe7-457d-8c54-42cc8d60decd@googlegroups.com> On Tuesday, March 26, 2013 12:33:54 PM UTC-4, Jerry Hill wrote: > On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote: > > >> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > > >> > I have a package name collections and inside of my package I want to > > > > > I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like "collections", why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections > > > > You've said a couple of times now that the original author has a > > package named "mypackage" with a module "collections" in it. As far > > as I can tell, that's untrue. The original post claims to have a > > package named "collections", which is colliding with the builtin > > module of the same name. > > > > As far as I can tell, all of your suggestions about using your > > pyimport-relative tool aren't helpful unless the author re-names his > > package from "collections" to "mypackage" and then moves all of their > > code into a "collections" module inside "mypackage", right? Right. Perhaps then I misunderstand. Having a package called "collections" when there is something out there already called "collections" clearly ill advised. But in that case, using sys.path to get around this is still a bad idea: the clash should be fixed. Sure, only in the case that this really can't be addressed would I use sys.path. > > > > -- > > Jerry From rocky at gnu.org Tue Mar 26 14:41:57 2013 From: rocky at gnu.org (rocky) Date: Tue, 26 Mar 2013 11:41:57 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> Message-ID: <8dc18c81-dbe7-457d-8c54-42cc8d60decd@googlegroups.com> On Tuesday, March 26, 2013 12:33:54 PM UTC-4, Jerry Hill wrote: > On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote: > > >> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > > >> > I have a package name collections and inside of my package I want to > > > > > I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like "collections", why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections > > > > You've said a couple of times now that the original author has a > > package named "mypackage" with a module "collections" in it. As far > > as I can tell, that's untrue. The original post claims to have a > > package named "collections", which is colliding with the builtin > > module of the same name. > > > > As far as I can tell, all of your suggestions about using your > > pyimport-relative tool aren't helpful unless the author re-names his > > package from "collections" to "mypackage" and then moves all of their > > code into a "collections" module inside "mypackage", right? Right. Perhaps then I misunderstand. Having a package called "collections" when there is something out there already called "collections" clearly ill advised. But in that case, using sys.path to get around this is still a bad idea: the clash should be fixed. Sure, only in the case that this really can't be addressed would I use sys.path. > > > > -- > > Jerry From steve+comp.lang.python at pearwood.info Tue Mar 26 19:11:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 23:11:48 GMT Subject: import in Python3.3 References: <514f9a0b$0$30001$c3e8da3$5496439d@news.astraweb.com> <0f669e21-5fd1-402e-9d96-55aa647d1030@googlegroups.com> Message-ID: <51522b34$0$29998$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Mar 2013 12:33:54 -0400, Jerry Hill wrote: > On Mon, Mar 25, 2013 at 11:49 PM, rocky wrote: >>> On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: >>> > I have a package name collections and inside of my package I want to > >> I find this kind of thing sad: it feels to me that programmers are >> working around somewhat arbitrary and changing restrictions. Rather >> than avoid names like "collections", why not try to address the >> underlying problem? There isn't an ambiguity here in my view: the >> fullname is mypackage.collections > > You've said a couple of times now that the original author has a package > named "mypackage" with a module "collections" in it. As far as I can > tell, that's untrue. The original post claims to have a package named > "collections", which is colliding with the builtin module of the same > name. Ah, that would be my fault. I was the first one to mention "mypackage", and I misread the OP's description. Given that he has a *top-level* package "collections" which clashes with the collections in the standard library, there's no simple way to bypass his package and find the standard library collections module. When you have two top-level modules/packages with the same name, whichever one comes first in sys.path will shadow the second one. -- Steven From tjreedy at udel.edu Tue Mar 26 03:04:44 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Mar 2013 03:04:44 -0400 Subject: import in Python3.3 In-Reply-To: References: Message-ID: On 3/24/2013 7:12 PM, Fabian von Romberg wrote: > Hi, > > I have a package name collections and inside of my package I want to > import the collections package from the standard library, but there > is name conflicts. Yes. I strongly advise against trying to do this. > How do I import explicitly from the standard library? Manipulate sys.path. If you don't know how, either read about sys.path (see index) or don't do it. -- Terry Jan Reedy From rocky at gnu.org Tue Mar 26 11:37:00 2013 From: rocky at gnu.org (rocky) Date: Tue, 26 Mar 2013 08:37:00 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: References: Message-ID: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> On Tuesday, March 26, 2013 3:04:44 AM UTC-4, Terry Reedy wrote: > On 3/24/2013 7:12 PM, Fabian von Romberg wrote: > > > Hi, > > > > > > I have a package name collections and inside of my package I want to > > > import the collections package from the standard library, but there > > > is name conflicts. > > > > Yes. I strongly advise against trying to do this. > > > > > How do I import explicitly from the standard library? > > > > Manipulate sys.path. This is a common suggestion for working *around* the issue, but it has problems of its own. In my opinion using sys.path is clunky - you may want to save an restore the value around use especially if the the place you are using it is not at the top level but in some inner less-exposed sub module. And make sure to restore sys.path in the presence of exceptions getting thrown somewhere inside the import. It is also a bit of a security nightmare. If something evil gets injected in there what does it effect and how would you know it? sys.path provides a series of directories where and evil masquerading Python program can linger. And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. So again I come to import_relative, http://code.google.com/p/pyimport-relative/. And again, I wish this package didn't have to exist. > If you don't know how, either read about sys.path > > (see index) or don't do it. > > > > -- > > Terry Jan Reedy From rocky at gnu.org Tue Mar 26 11:37:00 2013 From: rocky at gnu.org (rocky) Date: Tue, 26 Mar 2013 08:37:00 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: References: Message-ID: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> On Tuesday, March 26, 2013 3:04:44 AM UTC-4, Terry Reedy wrote: > On 3/24/2013 7:12 PM, Fabian von Romberg wrote: > > > Hi, > > > > > > I have a package name collections and inside of my package I want to > > > import the collections package from the standard library, but there > > > is name conflicts. > > > > Yes. I strongly advise against trying to do this. > > > > > How do I import explicitly from the standard library? > > > > Manipulate sys.path. This is a common suggestion for working *around* the issue, but it has problems of its own. In my opinion using sys.path is clunky - you may want to save an restore the value around use especially if the the place you are using it is not at the top level but in some inner less-exposed sub module. And make sure to restore sys.path in the presence of exceptions getting thrown somewhere inside the import. It is also a bit of a security nightmare. If something evil gets injected in there what does it effect and how would you know it? sys.path provides a series of directories where and evil masquerading Python program can linger. And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. So again I come to import_relative, http://code.google.com/p/pyimport-relative/. And again, I wish this package didn't have to exist. > If you don't know how, either read about sys.path > > (see index) or don't do it. > > > > -- > > Terry Jan Reedy From pconnell at gmail.com Tue Mar 26 17:16:57 2013 From: pconnell at gmail.com (Phil Connell) Date: Tue, 26 Mar 2013 21:16:57 +0000 Subject: import in Python3.3 In-Reply-To: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> References: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> Message-ID: <20130326211657.GA1615@odell.Belkin> On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote: > And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. > > So again I come to import_relative, http://code.google.com/p/pyimport-relative/. And again, I wish this package didn't have to exist. What's wrong with PEP 328 relative imports? In mypackage.foo, use from . import collections to import mypackage.collections. This has been part of the language since ~2.5 From rocky at gnu.org Tue Mar 26 18:24:02 2013 From: rocky at gnu.org (Rocky Bernstein) Date: Tue, 26 Mar 2013 18:24:02 -0400 Subject: import in Python3.3 In-Reply-To: <20130326211657.GA1615@odell.Belkin> References: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> <20130326211657.GA1615@odell.Belkin> Message-ID: On Tue, Mar 26, 2013 at 5:16 PM, Phil Connell wrote: > On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote: > > And again, I get the impression that for the use case asked about, there > isn't much ambiguity. If I am in mypackage.foo and I want to access > mypackage.collections I should be able to say something like that without > ambiguity or that much inference or directory searching. If > mypackage.colletions is not found inside the same directory as > mypackage.foo, often I DON'T WANT Python to helpfully go searching around > other places for it which sys.path will do. Instead what I probably want is > Python to give me an error. > > > > So again I come to import_relative, > http://code.google.com/p/pyimport-relative/. And again, I wish this > package didn't have to exist. > > What's wrong with PEP 328 relative imports? > They've never worked for me. Some details are mentioned that in the link above. If it works for you, great, use it. > In mypackage.foo, use > > from . import collections > > to import mypackage.collections. > > > This has been part of the language since ~2.5 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Mar 26 19:06:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 23:06:02 GMT Subject: import in Python3.3 References: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> Message-ID: <515229d9$0$29998$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Mar 2013 08:37:00 -0700, rocky wrote: > And again, I get the impression that for the use case asked about, there > isn't much ambiguity. If I am in mypackage.foo and I want to access > mypackage.collections I should be able to say something like that > without ambiguity or that much inference or directory searching. And you can: either explicitly say import mypackage.collections or use a relative import: from . import collections both of which only look inside mypackage. > If > mypackage.colletions is not found inside the same directory as > mypackage.foo, often I DON'T WANT Python to helpfully go searching > around other places for it which sys.path will do. With both solutions above, Python will not. > Instead what I > probably want is Python to give me an error. > > So again I come to import_relative, > http://code.google.com/p/pyimport-relative/. And again, I wish this > package didn't have to exist. I'm not convinced it does. I don't understand the problem you are trying to solve. "Provide relative imports" is not that problem, because the use- case you give on the project page does not describe relative imports, as they are understood in Python terminology. The error message you get gives the game away: ValueError: Attempted relative import in non-package In a stand-alone module, you can't do a relative import because there is no package structure, hence there is nothing to import relative to. As I don't quite understand your use-case, I'm a shooting in the dark here, but it seems to me that you could fix this entire problem by simply using a package instead of a directory of stand-alone modules. A mere directory of stand-alone modules should be merely loosely coupled, no different from any other modules in sys.path. If your modules are tightly coupled, they should go in a package. One thing which would make import manipulations much easier would be if import (and __import__) took an explicit search path, as opposed to operating on a system-wide global. E.g. import module using this_path would be nice. -- Steven From rocky at gnu.org Tue Mar 26 20:33:45 2013 From: rocky at gnu.org (rocky) Date: Tue, 26 Mar 2013 17:33:45 -0700 (PDT) Subject: import in Python3.3 In-Reply-To: <515229d9$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com> <515229d9$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <70df1530-57ec-4a94-89b0-3df6062f2aba@googlegroups.com> On Tuesday, March 26, 2013 7:06:02 PM UTC-4, Steven D'Aprano wrote: > On Tue, 26 Mar 2013 08:37:00 -0700, rocky wrote: > > > > > So again I come to import_relative, > > > http://code.google.com/p/pyimport-relative/. And again, I wish this > > > package didn't have to exist. > > > > > > I'm not convinced it does. Sure, the package doesn't have to exist. I'm pretty sure the majority of Python programmers don't use this. So on that sense it doesn't have to exist. I meant that I wished I didn't need it in order to support a development style that I use in other programming languages like Ruby, Perl, POSIX shell, or Emacs Lisp, among others. There, I can run each file/submodule in a large collection such as the dozens of files in http://code.google.com/p/python3-trepan/ without having to "install" the code. That includes not needing the copying that can go on inside say setup.py to put it in a "build" directory. With this I can treat each file/module/submodule in the collection as a main program or not. This helps me isolate and focus on just that part. I can debug it in isolation starting there even though it is a usually submodule of a bigger collection. > > to solve. "Provide relative imports" is not that problem, because the use- > > case you give on the project page does not describe relative imports, as > > they are understood in Python terminology. If the information above and on that page isn't clear, then please let's just drop it. This is not a new problem. It's been discussed before, I think on this very same newsgroup. As someone has said, relative imports have been around since 2.5 or so; they've been a disappointment to me ever since then too. > > > > The error message you get gives the game away: > > > > ValueError: Attempted relative import in non-package > > > > In a stand-alone module, you can't do a relative import because there is > > no package structure, hence there is nothing to import relative to. So what pyimport-relative does is provide kind of import statement that makes it irrelevant whether or not this has been run as a main program or not. And yes, I know about Python's '-m' option. > > > > As I don't quite understand your use-case, I'm a shooting in the dark > > here, No need to shoot in the dark. If you don't understand the use case, I'm probably not explaining it that well. I'm not asking for help, so let's drop it, lest I get into another long discussion that ultimately leads nowhere. From benjamin at python.org Sun Mar 24 20:30:06 2013 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 24 Mar 2013 20:30:06 -0400 Subject: [RELEASE] Python 2.7.4 release candidate 1 Message-ID: I'm happy to announce the first release candidate of 2.7.4. 2.7.4 will be the latest maintenance release in the Python 2.7 series. It includes hundreds of bugfixes to the core language and standard library. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. 2.7.4 does not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml 2.7.4 release candidate 1 is a testing release. Deploying it in production is not recommended. However, please download it and test with your libraries and applications, reporting any bugs you may find. Assuming no horrible bugs rear their heads, a final release of 2.7.4 will occur in 2 weeks. Downloads are at http://python.org/download/releases/2.7.4/ As always, please report bugs to http://bugs.python.org/ Enjoy, Benjamin Peterson 2.7 Release Manager From fromberg100 at hotmail.com Sun Mar 24 23:56:12 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Sun, 24 Mar 2013 22:56:12 -0500 Subject: io.BytesIO Message-ID: Hi, is there any way to get the allocated memory size from a io.BytesIO object? Thanks and regards, Fabian From steve+comp.lang.python at pearwood.info Mon Mar 25 00:47:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2013 04:47:15 GMT Subject: io.BytesIO References: Message-ID: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote: > Hi, > > is there any way to get the allocated memory size from a io.BytesIO > object? The same as for any object: py> import io, sys py> obj = io.BytesIO() py> sys.getsizeof(obj) 48 Is this what you are after, the size of the object itself, including any overhead? -- Steven From fromberg100 at hotmail.com Mon Mar 25 01:10:04 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Mon, 25 Mar 2013 00:10:04 -0500 Subject: io.BytesIO In-Reply-To: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, actually why I need is to know how much memory has been allocated for buffering. getsizeof gets the size of the object structure. For example, if I do io.BytesIO.truncate(10000), it will resize the buffer to 10000 bytes. So my question is how to get those 10000 back from an attribute or method? Regards, Fabian On 03/24/2013 11:47 PM, Steven D'Aprano wrote: > On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote: > >> Hi, >> >> is there any way to get the allocated memory size from a io.BytesIO >> object? > > The same as for any object: > > py> import io, sys > py> obj = io.BytesIO() > py> sys.getsizeof(obj) > 48 > > > Is this what you are after, the size of the object itself, including any > overhead? > > From steve+comp.lang.python at pearwood.info Mon Mar 25 02:54:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Mar 2013 06:54:07 GMT Subject: io.BytesIO References: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote: > Hi Steven, > > > actually why I need is to know how much memory has been allocated for > buffering. > > getsizeof gets the size of the object structure. I can see at least four ways to get the current size of the BytesIO buffer: py> obj = io.BytesIO(b"x"*12468) py> obj.getbuffer().nbytes 12468 py> len(obj.getvalue()) 12468 py> len(obj.getbuffer()) 12468 py> obj.seek(0, 2) 12468 As far as I can tell, BytesIO objects do not have a fixed size buffer. They will increase in size as needed, just like real file objects on a disk. -- Steven From fromberg100 at hotmail.com Mon Mar 25 22:43:24 2013 From: fromberg100 at hotmail.com (Fabian von Romberg) Date: Mon, 25 Mar 2013 21:43:24 -0500 Subject: io.BytesIO In-Reply-To: <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steve, thanks for your reply. Actually I played around with these methods. Whe you truncate(12468) for example, I thought the object would allocate 12468 bytes and I wanted to get that back. The methods your mention, works only for what ha been written (obj.write()). I think I should use io.BufferedWriter instead. Just one question, what has better performance: BufferedWriter or BytesIO? Thanks and regards, Fabian On 03/25/2013 01:54 AM, Steven D'Aprano wrote: > On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote: > >> Hi Steven, >> >> >> actually why I need is to know how much memory has been allocated for >> buffering. >> >> getsizeof gets the size of the object structure. > > I can see at least four ways to get the current size of the BytesIO > buffer: > > py> obj = io.BytesIO(b"x"*12468) > py> obj.getbuffer().nbytes > 12468 > py> len(obj.getvalue()) > 12468 > py> len(obj.getbuffer()) > 12468 > py> obj.seek(0, 2) > 12468 > > > As far as I can tell, BytesIO objects do not have a fixed size buffer. > They will increase in size as needed, just like real file objects on a > disk. > > > From postfinancial at postribe.com Mon Mar 25 05:30:55 2013 From: postfinancial at postribe.com (billing) Date: Mon, 25 Mar 2013 20:30:55 +1100 Subject: Il tuo ordine e stato accettato. Message-ID: <002901ce293b$713dae00$0500a8c0@SAU-71762-OR.sau.net.au> Good morning, Please read the document. http://www.journeynext.org/Notare/InfoBlocco.zip?vfwVFEPify787=python-list at python.org It was scanned and sent to you using a XER0X WorkCentre Pro. Sent by: Support Number of Document: 1 File Type: ZIP [DOC] WorkCentre Pro Location: machine loctaion not set Device Name: 9059905164065. From info at egenix.com Mon Mar 25 06:10:39 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 25 Mar 2013 11:10:39 +0100 Subject: ANN: eGenix mxODBC 3.2.2 - Python ODBC Database Interface Message-ID: <5150229F.3070509@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.2.2 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.2.2-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.2 release of our mxODBC is the latest patch level release of our popular Python ODBC Interface. In this release, we've included the following the following enhancements and fixes: Feature Enhancements -------------------- * Backported the new .cursortype attribute from the upcoming mxODBC 3.3. The new attribute allows easily adjusting and inspecting the ODBC cursor type to be used for an mxODBC cursor object. The reason for this unusual backport and inclusion in a patch level release is that we found a serious performance issue with MS SQL Server when using it with mxODBC 3.2 (see below). This needed to be addressed immediately. Driver Compatibility -------------------- * MS SQL Server performance can now be much enhanced, and increased to levels beyond that of mxODBC 3.1 and previous releases, by adjusting the default cursor type to forward-only cursors: connection = mx.ODBC.Windows.DriverConnect(...) connection.cursortype = mx.ODBC.Windows.SQL.CURSOR_FORWARD_ONLY # Cursors created on this connection will then default to forward # only cursors, instead of the mxODBC 3.2 default for SQL Server # of using static cursors cursor = connection.cursor() The performance increase compared to mxODBC 3.2.1 is enormous: from 2-3x faster executes/fetches for average queries, up to 300x faster for simple cases. In mxODBC 3.3, we will switch to using forward-only cursors per default for all database backends. * IBM DB2 can benefit from the same performance enhancements using forward-only cursors. The effect is a lot smaller, but still noticeable: up to 2x faster executes/fetches with forward-only cursors, compared to mxODBC 3.2.1. * Added documentation to explain the different cursor types, compatibility with different database backends and effects on performance. Fixes ----- * Fixed a problem with using mxODBC cursors as context managers: these worked fine in Python 2.6, but had stopped working in Python 2.7 due to changes in the Python internals. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html ________________________________________________________________________ FEATURES mxODBC 3.2 was released on 2012-08-28. Please see the full announcement for highlights of the 3.2 release: http://www.egenix.com/company/news/eGenix-mxODBC-3.2.2-GA.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features ________________________________________________________________________ EDITIONS mxODBC is available in these three editions: * The low-cost Standard Edition which provides data connectivity to a single database type, e.g. just MS SQL Server. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. Compared to mxODBC 3.0, we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 3.2 license can continue to use their licenses with this patch level release. Customers who have purchased mxODBC 2.x, 3.0 or 3.1 licenses, can benefit from upgrade discounts. We will give out 20% discount coupons going from mxODBC 2.x to 3.2 and 50% coupons for upgrades from mxODBC 3.x to 3.2. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team at sales at egenix.com with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 25 2013) >>> 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/ ________________________________________________________________________ 2013-03-13: Released eGenix pyOpenSSL 0.13 ... http://egenix.com/go39 ::::: 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 dineshbvadhia at hotmail.com Mon Mar 25 08:29:50 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 25 Mar 2013 05:29:50 -0700 (PDT) Subject: Python 2.7.3 tempfile.py, ln34, from random import Random as _Random Message-ID: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> In Python 2.7.3, at ln34 the source file tempfile.py states: from random import Random as _Random But, Random is a Class. The project imports werkzeug and using PyInstaller, the Traceback is: Traceback (most recent call last): File "", line 9, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 404, in load_module module = imp.load_module(fullname, fp, filename, self._c_ext_tuple) File "xserver.pyx", line 18, in init xserver (//home//ubuntu//Programs//myproject//myproject_pyx/xserver.c:2481) File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/werkzeug.wrappers", line 26, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/werkzeug.http", line 25, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/urllib2", line 94, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/httplib", line 79, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/mimetools", line 6, in File "/home/ubuntu/Programs/pyinstaller-2.0/PyInstaller/loader/pyi_importers.py", line 268, in load_module exec(bytecode, module.__dict__) File "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00-PYZ.pyz/tempfile", line 34, in ImportError: cannot import name Random Is this a bug? Or, is there some workaround available? Thx. From __peter__ at web.de Mon Mar 25 08:43:44 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Mar 2013 13:43:44 +0100 Subject: Python 2.7.3 tempfile.py, ln34, from random import Random as _Random References: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> Message-ID: dbv wrote: > In Python 2.7.3, at ln34 the source file tempfile.py states: > > from random import Random as _Random > > But, Random is a Class. This is not a problem. You can import arbitrary objects from a module. > The project imports werkzeug and using PyInstaller, the Traceback is: > > Traceback (most recent call last): > File "", line 9, in > File [...] > line 268, in load_module > exec(bytecode, module.__dict__) > File > "//home//ubuntu//Programs//myproject//myproject_pi2/build/pyi.linux2/myproject/out00- PYZ.pyz/tempfile", > line 34, in > ImportError: cannot import name Random > > Is this a bug? Or, is there some workaround available? Thx. I don't know about PyInstaller or werkzeug, but the most likely cause is that you shaded the standard library's random module with your own random.py which doesn't contain an object named "Random". Here's a demonostration: Normal behaviour: $ python -c 'from random import Random as _Random' Now add an empty random.py: $ touch random.py $ python -c 'from random import Random as _Random' Traceback (most recent call last): File "", line 1, in ImportError: cannot import name Random Back to normal: $ rm random.pyc random.py $ python -c 'from random import Random as _Random' From d at davea.name Mon Mar 25 08:44:46 2013 From: d at davea.name (Dave Angel) Date: Mon, 25 Mar 2013 08:44:46 -0400 Subject: Python 2.7.3 tempfile.py, ln34, from random import Random as _Random In-Reply-To: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> References: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> Message-ID: <515046BE.5020505@davea.name> On 03/25/2013 08:29 AM, dbv wrote: > In Python 2.7.3, at ln34 the source file tempfile.py states: > > from random import Random as _Random > > But, Random is a Class. > Have you just tried the following: import random print dir(random.random) print random.__file__ I suspect you have another random.py (or equivalent) in your sys.path -- DaveA From dineshbvadhia at hotmail.com Mon Mar 25 08:54:26 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 25 Mar 2013 05:54:26 -0700 (PDT) Subject: Python 2.7.3 tempfile.py, ln34, from random import Random as _Random In-Reply-To: References: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> Message-ID: I have a number of .py source files and one source file has an "import random" and another has "import werkzeug". The project works perfectly in the Python interpreter. Problem appears when using PyInstaller. How do get out of jail? From dineshbvadhia at hotmail.com Mon Mar 25 08:54:26 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 25 Mar 2013 05:54:26 -0700 (PDT) Subject: Python 2.7.3 tempfile.py, ln34, from random import Random as _Random In-Reply-To: References: <02874aa8-aec0-467d-94ed-a944c289976e@googlegroups.com> Message-ID: I have a number of .py source files and one source file has an "import random" and another has "import werkzeug". The project works perfectly in the Python interpreter. Problem appears when using PyInstaller. How do get out of jail? From michael.herrmann at getautoma.com Mon Mar 25 15:29:23 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Mon, 25 Mar 2013 12:29:23 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) Message-ID: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Hello everyone, my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It would be extremely helpful for us if you could let us know which API design feels "right" to you. Our API already offers very simple commands for automating the GUI of a Windows computer. For example: from automa.api import * start("Notepad") write("Hello World!") press(CTRL + 's') write("test.txt", into="File name") click("Save") click("Close") When you execute this script, Automa starts Notepad and simulates key strokes, mouse movements and clicks to perform the required commands. At the moment, each action is performed in the currently active window. We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. One API design would be to have our start(...) function return a "Window" (say) object, whose methods allow you to do the same operations as the global functions write(...), press(...), click(...) etc., but in the respective window. In this design, the example of operating two Notepad windows could be written as notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.write("Hello World!") notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') The problem with this design is that it effectively duplicates our API: We want to keep our "global" functions because they are so easy to read. If we add methods to a new "Window" class that do more or less the same, we feel that we are violating Python's principle that "There should be one - and preferably only one - obvious way to do it." An alternative design would be to make the window switching an explicit action. One way of doing this would be to add a new global function, say "switch_to" or "activate", that takes a single parameter that identifies the window to be switched to. We could still have start(...) return a Window object, that could then be passed to our function: notepad_1 = start("Notepad") notepad_2 = start("Notepad") switch_to(notepad_1) write("Hello World!") press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') Maybe our Window objects could also be used as context managers: notepad_1 = start("Notepad") notepad_2 = start("Notepad") with notepad_1: write("Hello World!") press(CTRL + 'a', CTRL + 'c') with notepad_2: press(CTRL + 'v') As a final idea, switching could also be done as a method of the Window class: notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.activate() write("Hello World!") press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') It would be extremely helpful for us if you could let me know which way of using the API you would prefer. If you opt for an explicit version, how would you call the respective method? "activate" / "switch_to" / "focus" or something else? Thank you so much! Best wishes, Michael From kwpolska at gmail.com Mon Mar 25 15:42:25 2013 From: kwpolska at gmail.com (Kwpolska) Date: Mon, 25 Mar 2013 20:42:25 +0100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: On Mon, Mar 25, 2013 at 8:29 PM, Michael Herrmann wrote: > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.write("Hello World!") > notepad_1.press(CTRL + 'a', CTRL + 'c') > notepad_2.press(CTRL + 'v') Explicit is better than implicit. Changing windows should be explicit and not implified by your library. > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') Much better. > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > with notepad_1: > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > with notepad_2: > press(CTRL + 'v') That?s ugly, and don?t forget that your users aren?t Pythonistas most of the time. > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') That is nice and makes sense, because a global function feels wrong, at least for me. > It would be extremely helpful for us if you could let me know which way of using the API you would prefer. If you opt for an explicit version, how would you call the respective method? "activate" / "switch_to" / "focus" or something else? Window().focus() is the best IMO. PS. do you plan a version for non-Windows OSes? Also, ?99 is too expensive. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From michael.herrmann at getautoma.com Mon Mar 25 16:48:15 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Mon, 25 Mar 2013 13:48:15 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Hi Kwpolska, thanks for your reply (as last time I posted here!). On Monday, March 25, 2013 8:42:25 PM UTC+1, Kwpolska wrote: > ... > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > with notepad_1: > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > with notepad_2: > > press(CTRL + 'v') > > That?s ugly, and don?t forget that your users aren?t Pythonistas most > of the time. I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the "with" is not as explicit as it probably should be. > ... > PS. do you plan a version for non-Windows OSes? Also, ?99 is too expensive. We'd of course love to support other platforms but don't currently have the resources to do this. We actually just wrote a blog entry about this and some related questions: http://www.getautoma.com/blog/automa-faq If we have something wrong, do let us know in the comments over there! It's very hard work building such an automation tool and also we have to live off something. Unfortunately, we can't make the price any lower. P.S.: First-time bottom-posting! From michael.herrmann at getautoma.com Mon Mar 25 16:48:15 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Mon, 25 Mar 2013 13:48:15 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Hi Kwpolska, thanks for your reply (as last time I posted here!). On Monday, March 25, 2013 8:42:25 PM UTC+1, Kwpolska wrote: > ... > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > with notepad_1: > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > with notepad_2: > > press(CTRL + 'v') > > That?s ugly, and don?t forget that your users aren?t Pythonistas most > of the time. I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the "with" is not as explicit as it probably should be. > ... > PS. do you plan a version for non-Windows OSes? Also, ?99 is too expensive. We'd of course love to support other platforms but don't currently have the resources to do this. We actually just wrote a blog entry about this and some related questions: http://www.getautoma.com/blog/automa-faq If we have something wrong, do let us know in the comments over there! It's very hard work building such an automation tool and also we have to live off something. Unfortunately, we can't make the price any lower. P.S.: First-time bottom-posting! From rosuav at gmail.com Mon Mar 25 17:08:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 08:08:53 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 7:48 AM, Michael Herrmann wrote: > On Monday, March 25, 2013 8:42:25 PM UTC+1, Kwpolska wrote: >> ... >> >> > notepad_1 = start("Notepad") >> > notepad_2 = start("Notepad") >> > with notepad_1: >> > write("Hello World!") >> > press(CTRL + 'a', CTRL + 'c') >> > with notepad_2: >> > press(CTRL + 'v') >> >> That?s ugly, and don?t forget that your users aren?t Pythonistas most >> of the time. > > I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the "with" is not as explicit as it probably should be. What happens at the __exit__ of the context manager? What happens if context managers are nested? I'd be inclined to the simpler option of an explicit switch (since focus doesn't really "stack" and it'd feel weird for focus to *sometimes* switch away when you're done working with one window), though the context manager syntax does have its advantages too. >> PS. do you plan a version for non-Windows OSes? Also, ?99 is too expensive. > > We'd of course love to support other platforms but don't currently have the resources to do this. We actually just wrote a blog entry about this and some related questions: http://www.getautoma.com/blog/automa-faq If we have something wrong, do let us know in the comments over there! Make the API clean enough and someone else might well write a Linux equivalent. Then it'll be as simple as a try/import/except/import at the top and multiple platforms will work. > P.S.: First-time bottom-posting! Congrats! Feels good, doesn't it :) ChrisA From michael.herrmann at getautoma.com Tue Mar 26 04:53:30 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 01:53:30 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Message-ID: On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: > ... > > I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the "with" is not as explicit as it probably should be. > > What happens at the __exit__ of the context manager? What happens if > context managers are nested? I'd be inclined to the simpler option of > an explicit switch (since focus doesn't really "stack" and it'd feel > weird for focus to *sometimes* switch away when you're done working > with one window), though the context manager syntax does have its > advantages too. You are right, an __exit__ for a window doesn't really make sense and neither does stacking. There's also the problem that the focus window may change - for instance when closing it. What happens if you're still inside the "with ..." then? At first glance, I think the context manager solution looks nice syntactically, but maybe it isn't the way to go here. > ... > > > We'd of course love to support other platforms but don't currently have the resources to do this. We actually just wrote a blog entry about this and some related questions: http://www.getautoma.com/blog/automa-faq If we have something wrong, do let us know in the comments over there! > > > Make the API clean enough and someone else might well write a Linux > equivalent. Then it'll be as simple as a try/import/except/import at > the top and multiple platforms will work. Yes, that's a good point. A clean API is very important to us (hence my posting here). Thanks for your answer! Michael From rosuav at gmail.com Tue Mar 26 07:38:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 22:38:35 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 7:53 PM, Michael Herrmann wrote: > On Monday, March 25, 2013 10:08:53 PM UTC+1, Chris Angelico wrote: >> ... >> > I kind of like the context manager solution because the indentation makes it very obvious what happens in which window. You are right about our target group though. Also, the "with" is not as explicit as it probably should be. >> >> What happens at the __exit__ of the context manager? What happens if >> context managers are nested? I'd be inclined to the simpler option of >> an explicit switch (since focus doesn't really "stack" and it'd feel >> weird for focus to *sometimes* switch away when you're done working >> with one window), though the context manager syntax does have its >> advantages too. > > You are right, an __exit__ for a window doesn't really make sense and neither does stacking. There's also the problem that the focus window may change - for instance when closing it. What happens if you're still inside the "with ..." then? At first glance, I think the context manager solution looks nice syntactically, but maybe it isn't the way to go here. Fundamental point: As I understand the API, it doesn't *actually* tie to a window. You don't locate the Notepad window and send it keys - you switch focus to Notepad and then send keys to the whole system. Is this correct? I'm basing my understanding on this paragraph from your original post: > We do not (yet) have a functionality that allows you to explicitly switch to a > specific window. Such a functionality would for instance make it possible to > open two Notepad windows using the start(...) command, and copy text > between them. If so, then all of the method-based options are effectively lying, because they imply a binding that's not there. The actual sequence of actions includes imperatives of "switch to some other window", so I think that's what the API should reflect. Otherwise, there's risk that something will get horribly horribly confused between the programmer's brain and the end result (which could happen on either side of your code). But if you can unambiguously identify a running instance of something and switch to it, then a method on the object that start() returns would be absolutely correct. So I'd be looking at either your second or fourth options from the original post. ChrisA From michael.herrmann at getautoma.com Tue Mar 26 08:13:14 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:13:14 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Message-ID: <851c6626-6700-4759-b4ec-7334dbf35c54@googlegroups.com> On Tuesday, March 26, 2013 12:38:35 PM UTC+1, Chris Angelico wrote: > ... > Fundamental point: As I understand the API, it doesn't *actually* tie > to a window. You don't locate the Notepad window and send it keys - > you switch focus to Notepad and then send keys to the whole system. Is > this correct? I'm basing my understanding on this paragraph from your > original post: > > > We do not (yet) have a functionality that allows you to explicitly switch to a > > specific window. Such a functionality would for instance make it possible to > > open two Notepad windows using the start(...) command, and copy text > > between them. > > If so, then all of the method-based options are effectively lying, > because they imply a binding that's not there. The actual sequence of > actions includes imperatives of "switch to some other window", so I > think that's what the API should reflect. Otherwise, there's risk that > something will get horribly horribly confused between the programmer's > brain and the end result (which could happen on either side of your > code). As I just wrote in my reply to Dave, internally we know very well which window an action is to be performed in. This window is the window that'd be in the foreground after the previous action, if nothing interferes with the system while the script is being executed. A common exception is when you enter commands in the interactive interpreter: say you write >>> start("Notepad") The Notepad window opens, but for you to enter the next command, you have to switch back to the interpreter window. If you do that, and enter >>> write("Hello World") then we remember that you were previously working with the Notepad window and activate this window before performing the key strokes to type "Hello World". > But if you can unambiguously identify a running instance of something > and switch to it, then a method on the object that start() returns > would be absolutely correct. So I'd be looking at either your second > or fourth options from the original post. Those are also my favorites at the moment :) Michael www.getautoma.com From michael.herrmann at getautoma.com Tue Mar 26 08:13:14 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:13:14 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <4b2d2295-cffd-4965-8d75-ebd4f0b9da32@googlegroups.com> Message-ID: <851c6626-6700-4759-b4ec-7334dbf35c54@googlegroups.com> On Tuesday, March 26, 2013 12:38:35 PM UTC+1, Chris Angelico wrote: > ... > Fundamental point: As I understand the API, it doesn't *actually* tie > to a window. You don't locate the Notepad window and send it keys - > you switch focus to Notepad and then send keys to the whole system. Is > this correct? I'm basing my understanding on this paragraph from your > original post: > > > We do not (yet) have a functionality that allows you to explicitly switch to a > > specific window. Such a functionality would for instance make it possible to > > open two Notepad windows using the start(...) command, and copy text > > between them. > > If so, then all of the method-based options are effectively lying, > because they imply a binding that's not there. The actual sequence of > actions includes imperatives of "switch to some other window", so I > think that's what the API should reflect. Otherwise, there's risk that > something will get horribly horribly confused between the programmer's > brain and the end result (which could happen on either side of your > code). As I just wrote in my reply to Dave, internally we know very well which window an action is to be performed in. This window is the window that'd be in the foreground after the previous action, if nothing interferes with the system while the script is being executed. A common exception is when you enter commands in the interactive interpreter: say you write >>> start("Notepad") The Notepad window opens, but for you to enter the next command, you have to switch back to the interpreter window. If you do that, and enter >>> write("Hello World") then we remember that you were previously working with the Notepad window and activate this window before performing the key strokes to type "Hello World". > But if you can unambiguously identify a running instance of something > and switch to it, then a method on the object that start() returns > would be absolutely correct. So I'd be looking at either your second > or fourth options from the original post. Those are also my favorites at the moment :) Michael www.getautoma.com From ethan at stoneleaf.us Mon Mar 25 19:11:34 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 25 Mar 2013 16:11:34 -0700 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <5150D9A6.3040308@stoneleaf.us> On 03/25/2013 12:29 PM, Michael Herrmann wrote: > Hello everyone, > > my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It would be extremely helpful for us if you could let us know which API design feels "right" to you. > > Our API already offers very simple commands for automating the GUI of a Windows computer. For example: > > from automa.api import * > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > click("Close") > > When you execute this script, Automa starts Notepad and simulates key strokes, mouse movements and clicks to perform the required commands. At the moment, each action is performed in the currently active window. > > We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. > > One API design would be to have our start(...) function return a "Window" (say) object, whose methods allow you to do the same operations as the global functions write(...), press(...), click(...) etc., but in the respective window. In this design, the example of operating two Notepad windows could be written as > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.write("Hello World!") > notepad_1.press(CTRL + 'a', CTRL + 'c') > notepad_2.press(CTRL + 'v') This is the way to go. Just move your global functions into the Window object (or whatever you call it), break backwards compatibility (major version number change, perhaps?), and call it good. It makes much more sense to call methods of several different objects (which is explicit -- you always know which object is being used) than having a magic function that changes the object in the background (plus you now have to search backwards for the last magic invocation to know -- and what if a called function changes it?). -- ~Ethan~ From msirenef at lightbird.net Mon Mar 25 19:40:45 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Mon, 25 Mar 2013 19:40:45 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <5150E07D.8070401@lightbird.net> On 03/25/2013 03:29 PM, Michael Herrmann wrote: > Hello everyone, > > my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It would be extremely helpful for us if you could let us know which API design feels "right" to you. > > Our API already offers very simple commands for automating the GUI of a Windows computer. For example: > > from automa.api import * > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > click("Close") > > When you execute this script, Automa starts Notepad and simulates key strokes, mouse movements and clicks to perform the required commands. At the moment, each action is performed in the currently active window. > > We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. > > One API design would be to have our start(...) function return a "Window" (say) object, whose methods allow you to do the same operations as the global functions write(...), press(...), click(...) etc., but in the respective window. In this design, the example of operating two Notepad windows could be written as > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.write("Hello World!") > notepad_1.press(CTRL + 'a', CTRL + 'c') > notepad_2.press(CTRL + 'v') > > The problem with this design is that it effectively duplicates our API: We want to keep our "global" functions because they are so easy to read. If we add methods to a new "Window" class that do more or less the same, we feel that we are violating Python's principle that "There should be one - and preferably only one - obvious way to do it." > > An alternative design would be to make the window switching an explicit action. One way of doing this would be to add a new global function, say "switch_to" or "activate", that takes a single parameter that identifies the window to be switched to. We could still have start(...) return a Window object, that could then be passed to our function: > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') > > Maybe our Window objects could also be used as context managers: > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > with notepad_1: > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > with notepad_2: > press(CTRL + 'v') > > As a final idea, switching could also be done as a method of the Window class: > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') > > It would be extremely helpful for us if you could let me know which way of using the API you would prefer. If you opt for an explicit version, how would you call the respective method? "activate" / "switch_to" / "focus" or something else? > > Thank you so much! > > Best wishes, > Michael I think I would prefer context managers. I don't think it's a big problem for win users because this behaviour would be one of the first things documented in the start guide and would be all over example scripts, so a new user missing or forgetting it is not a realistic scenario. The advantages are that it's explicit, blocks are indented and it's impossible to miss which window is the action applied to, and at the same time actions are short and easy to type and read. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From michael.herrmann at getautoma.com Tue Mar 26 05:06:18 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 02:06:18 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: > On 03/25/2013 12:29 PM, Michael Herrmann wrote: > ... > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > notepad_2.press(CTRL + 'v') > > This is the way to go. Just move your global functions into the Window object (or whatever you call it), break > backwards compatibility (major version number change, perhaps?), and call it good. > > It makes much more sense to call methods of several different objects (which is explicit -- you always know which object > is being used) than having a magic function that changes the object in the background (plus you now have to search > backwards for the last magic invocation to know -- and what if a called function changes it?). Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer the simplicity of start("Notepad") write("Hello World!") press(CTRL + 's') write("test.txt", into="File name") click("Save") press(ALT + F4) over notepad = start("Notepad") notepad.write("Hello World!") notepad.press(CTRL + 's') notepad.write("test.txt", into="File name") notepad.click("Save") notepad.press(ALT + F4). Also, there's a problem here: The "Save" dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the "Save" window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window. In light of this, could you live with something along the lines of design #4? notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.focus() write("Hello World!") press(CTRL + 'a', CTRL + 'c') notepad_2.focus() press(CTRL + 'v') Thanks, Michael From davea at davea.name Tue Mar 26 06:26:30 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 06:26:30 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: <515177D6.2030004@davea.name> On 03/26/2013 05:06 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 12:11:34 AM UTC+1, Ethan Furman wrote: >> On 03/25/2013 12:29 PM, Michael Herrmann wrote: >> ... >>> >>> notepad_1 = start("Notepad") >>> notepad_2 = start("Notepad") >>> notepad_1.write("Hello World!") >>> notepad_1.press(CTRL + 'a', CTRL + 'c') >>> notepad_2.press(CTRL + 'v') >> >> This is the way to go. Just move your global functions into the Window object (or whatever you call it), break >> backwards compatibility (major version number change, perhaps?), and call it good. >> >> It makes much more sense to call methods of several different objects (which is explicit -- you always know which object >> is being used) than having a magic function that changes the object in the background (plus you now have to search >> backwards for the last magic invocation to know -- and what if a called function changes it?). > > Your points are valid and I cannot really say anything against them. The problem with moving all global functions into the Window object is that this adds a lot of syntactic baggage that isn't needed in 90% of the cases. We really prefer the simplicity of > > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > press(ALT + F4) > > over > > notepad = start("Notepad") > notepad.write("Hello World!") > notepad.press(CTRL + 's') > notepad.write("test.txt", into="File name") > notepad.click("Save") > notepad.press(ALT + F4). > > Also, there's a problem here: The "Save" dialogue that opens in the above script is technically a different window so in theory you would have to introduce a new object to distinguish between the original window that lets you edit your text document from the "Save" window. This is very tedious and error-prone. You are right, though, that we have to do some logic in the background to remember the last window. > > In light of this, could you live with something along the lines of design #4? > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.focus() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.focus() > press(CTRL + 'v') > > Thanks, > Michael > Seems to me that the official interface should all be methods. However, you could have a new object which always represents the "focus" window. Then the USER could define trivial functions: def write(*args): focused.write(*args) Somewhere in this thread you mention that save() creates a new window, so a method-oriented approach would require that the user get that window object, and call its methods rather than the original window's. I say that's a very good thing, since the things you send may very well have very different meanings to the save dialog than they do in the original one. Another concern I'd have is what happens if the user changes focus with his mouse? Does that change the meaning you had for focus() in the above exchange? Do you want your press() method to apply to a different window when the user changes to that window? -- DaveA From michael.herrmann at getautoma.com Tue Mar 26 08:04:43 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:04:43 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: > ... > Seems to me that the official interface should all be methods. However, > you could have a new object which always represents the "focus" window. > Then the USER could define trivial functions: > > def write(*args): > focused.write(*args) It's an interesting idea. But why not give this write(...) to them in the first place? Am I the only one who appreciates the simplicity of start("Notepad") write("Hello World!") press(CTRL + 's') write("test.txt", into="File name") click("Save") press(ALT + F4) over notepad = start("Notepad") notepad.write("Hello World!") notepad.press(CTRL + 's') notepad.write("test.txt", into="File name") notepad.click("Save") notepad.press(ALT + F4)? > Somewhere in this thread you mention that save() creates a new window, > so a method-oriented approach would require that the user get that > window object, and call its methods rather than the original window's. > I say that's a very good thing, since the things you send may very well > have very different meanings to the save dialog than they do in the > original one. save() is not a function, but I assume you mean the action that opens the "Save" dialogue (I think that'd be `press(CTRL + 's')`). You are right that it's nice for it to be explicit. However, in 95% of cases, the window you want the next action to be performed in is the window that is currently active. I appreciate the explicitness, but to force it on the user for only 5% of cases seems a bit much. > Another concern I'd have is what happens if the user changes focus with > his mouse? Does that change the meaning you had for focus() in the > above exchange? Do you want your press() method to apply to a different > window when the user changes to that window? No. Internally, we remember which window is the currently active window. If you just run a script without user-intervention, this will be the respective foreground window. If some other window is in the foreground - which most typically happens when the user is interactively entering commands one after the other, so the foreground window is the console window, we do switch to the window that's supposed to be the active one. It may sound like black magic, but it works very well in practice, and really is not too ambiguous. When you read a script like start("Notepad") write("Hello World") press(CTRL + 's') write("test.txt", into="File name") click("Save") click("Close") I hold that you intuitively know what's going on, without even thinking about window switching. Best, Michael www.getautoma.com From davea at davea.name Tue Mar 26 08:42:26 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 08:42:26 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: <515197B2.3040903@davea.name> On 03/26/2013 08:04 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: >> ... >> Seems to me that the official interface should all be methods. However, >> you could have a new object which always represents the "focus" window. >> Then the USER could define trivial functions: >> >> def write(*args): >> focused.write(*args) > > It's an interesting idea. But why not give this write(...) to them in the first place? Just to be clear, I was avoiding the problem of having two ways of accessing each function, since most of us prefer the methods, and you have some users who prefer simple functions. > Am I the only one who appreciates the simplicity of > > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > press(ALT + F4) > > over > > notepad = start("Notepad") > notepad.write("Hello World!") > notepad.press(CTRL + 's') > notepad.write("test.txt", into="File name") > notepad.click("Save") > notepad.press(ALT + F4)? > >> Somewhere in this thread you mention that save() creates a new window, >> so a method-oriented approach would require that the user get that >> window object, and call its methods rather than the original window's. >> I say that's a very good thing, since the things you send may very well >> have very different meanings to the save dialog than they do in the >> original one. > > save() is not a function, but I assume you mean the action that opens the "Save" dialogue (I think that'd be `press(CTRL + 's')`). You are right that it's nice for it to be explicit. However, in 95% of cases, the window you want the next action to be performed in is the window that is currently active. I appreciate the explicitness, but to force it on the user for only 5% of cases seems a bit much. > >> Another concern I'd have is what happens if the user changes focus with >> his mouse? Does that change the meaning you had for focus() in the >> above exchange? Do you want your press() method to apply to a different >> window when the user changes to that window? > > No. Internally, we remember which window is the currently active window. If you just run a script without user-intervention, this will be the respective foreground window. If some other window is in the foreground - which most typically happens when the user is interactively entering commands one after the other, so the foreground window is the console window, we do switch to the window that's supposed to be the active one. It may sound like black magic, but it works very well in practice, and really is not too ambiguous. When you read a script like > > start("Notepad") > write("Hello World") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > click("Close") > > I hold that you intuitively know what's going on, without even thinking about window switching. > Until the program you're scripting makes some minor change in its interface, or has something conditional on an attribute not intuitively obvious. Also, it seems that in this thread, we are using "window" both to refer to a particular application instance (like Notepad1 and Notepad2), and to refer to windows within a single application. Anyway, if you're only automating a few specific apps, you're not likely to run into the problems that methods were intended to address. After all, Notepad's bugs haven't seemed to change for a couple of decades, so why should they fix anything now? Having a selected window be an implied object for those global functions yields at least the same problems as any writable global. Multithreading, unexpected side effects from certain functions, callbacks, etc. As long as you know the program is going to be simple, pile on the globals. But as soon as it advances, each of them is a trap to fall into. -- DaveA From steve+comp.lang.python at pearwood.info Tue Mar 26 08:59:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 12:59:58 GMT Subject: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: <51519bcd$0$29998$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:26:30 AM UTC+1, Dave Angel wrote: >> ... >> Seems to me that the official interface should all be methods. >> However, you could have a new object which always represents the >> "focus" window. >> Then the USER could define trivial functions: >> >> def write(*args): >> focused.write(*args) > > It's an interesting idea. But why not give this write(...) to them in > the first place? Am I the only one who appreciates the simplicity of > > start("Notepad") > write("Hello World!") > press(CTRL + 's') > write("test.txt", into="File name") > click("Save") > press(ALT + F4) > > over > > notepad = start("Notepad") > notepad.write("Hello World!") > notepad.press(CTRL + 's') > notepad.write("test.txt", into="File name") > notepad.click("Save") > notepad.press(ALT + F4)? You are not the only one. I suggest that you have a set of functions that work on "the current window", whatever that is. Preferably there should always be a current window, but if not, ensure that you give a clear error message. Then you have syntax for operating on any named(?) window. So a user can implicitly operate on the current window: select(notepad) write("goodbye cruel world") save() or explicitly on any window they like: excel.quit() I suggest you dig up an old book on "Hypercard", for Apple Macs in the 1980s and 90s. Back in the day, Macs could only run a single application at a time, and Hypercard was limited to a single window at a time (called a "stack"). But that stack (think: window) could have multiple "cards" (think: window tabs), one of which was always current. Hypercard's built-in programming language Hypertalk let you do things like this: go to stack "Notepad" type "goodbye cruel world" in field "main" of card 7 click button "Save" click button "Quit" of card "Main" of stack "Excel" (more or less... it's been a few years since I've had a classic Mac capable of running Hypercard.) -- Steven From michael.herrmann at getautoma.com Tue Mar 26 10:26:30 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 07:26:30 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: <51519bcd$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51519bcd$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2deabbbd-7f39-4434-872b-a903f5c2d305@googlegroups.com> On Tuesday, March 26, 2013 1:59:58 PM UTC+1, Steven D'Aprano wrote: > On Tue, 26 Mar 2013 05:04:43 -0700, Michael Herrmann wrote: > ... > Am I the only one who appreciates the simplicity of > > > start("Notepad") > > write("Hello World!") > > press(CTRL + 's') > > write("test.txt", into="File name") > > click("Save") > > press(ALT + F4) > > > over > > > notepad = start("Notepad") > > notepad.write("Hello World!") > > notepad.press(CTRL + 's') > > notepad.write("test.txt", into="File name") > > notepad.click("Save") > > notepad.press(ALT + F4)? > > You are not the only one. > > I suggest that you have a set of functions that work on "the current > window", whatever that is. Preferably there should always be a current > window, but if not, ensure that you give a clear error message. This is exactly the way it is currently. I am glad you also see it that way. > Then you have syntax for operating on any named(?) window. So a user can > implicitly operate on the current window: > > select(notepad) > write("goodbye cruel world") > save() One idea would be to use the Window(...) constructor to select windows: notepad = Window('Untitled - Notepad') select(notepad) save() One advantage of using a global method to switch to a window is that this would allow you to directly switch to a Window without having to call Window(...): switch_to('Untitled - Notepad') I'm still not fully convinced of a global method though, for the reasons several people here have already mentioned. > or explicitly on any window they like: > > excel.quit() This example makes it look likely that there will have to be other operations that can be performed on windows (/running applications as Dave pointed out). So, a 'quit()' method that closes a window in addition to the already mentioned focus/select/activate method. This in turn makes the global function less attractive as once we start going down that route, global functions will proliferate. > I suggest you dig up an old book on "Hypercard", for Apple Macs in the > 1980s and 90s. Back in the day, Macs could only run a single application > at a time, and Hypercard was limited to a single window at a time (called > a "stack"). But that stack (think: window) could have multiple > "cards" (think: window tabs), one of which was always current. > Hypercard's built-in programming language Hypertalk let you do things > like this: > > go to stack "Notepad" > type "goodbye cruel world" in field "main" of card 7 > click button "Save" > click button "Quit" of card "Main" of stack "Excel" > > (more or less... it's been a few years since I've had a classic Mac > capable of running Hypercard.) Very interesting. I had never heard of HyperCard. I read up on it a little and it sounds very similar to the model we are internally building of open applications (stacks) and their windows (cards). Also funny that HyperCard was one of Ward Cunningham's inspirations for coming up with the Wiki idea: http://c2.com/cgi/wiki?WikiWikiHyperCard Thanks for this! Michael www.getautoma.com From michael.herrmann at getautoma.com Tue Mar 26 10:33:18 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 07:33:18 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 1:42:26 PM UTC+1, Dave Angel wrote: > ... > > Also, it seems that in this thread, we are using "window" both to refer > to a particular application instance (like Notepad1 and Notepad2), and > to refer to windows within a single application. > > > > Anyway, if you're only automating a few specific apps, you're not likely > to run into the problems that methods were intended to address. After > all, Notepad's bugs haven't seemed to change for a couple of decades, so > why should they fix anything now? > > Having a selected window be an implied object for those global functions > yields at least the same problems as any writable global. > Multithreading, unexpected side effects from certain functions, > callbacks, etc. > > As long as you know the program is going to be simple, pile on the > globals. But as soon as it advances, each of them is a trap to fall into. You're right with everything you say. globals are bad and it may happen that this will bite me. I'm just not sure whether we should sacrifice the simpler syntax useful in say 80% of cases for something I'm not yet sure will ever become a real problem. From steve+comp.lang.python at pearwood.info Tue Mar 26 18:37:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 22:37:23 GMT Subject: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> Message-ID: <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Mar 2013 07:33:18 -0700, Michael Herrmann wrote: >> As long as you know the program is going to be simple, pile on the >> globals. But as soon as it advances, each of them is a trap to fall >> into. > > You're right with everything you say. globals are bad and it may happen > that this will bite me. Global *variables* are bad, not global functions. You have one global variable, "the current window". So long as your API makes it obvious when the current window changes, implicitly operating on the current window is no more dangerous than Python's implicit operations on the current namespace (e.g. "x = 2" binds 2 to x in the current namespace). I recommend you look at the random.py API. You have a Random class, that allows the user to generate as many independent random number generators as needed. And the module also initialises a private instance, and exposes the methods of that instance as top-level functions, to cover the 90% simple case where your application only cares about a single RNG. -- Steven From michael.herrmann at getautoma.com Wed Mar 27 05:34:09 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 02:34:09 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: > > Global *variables* are bad, not global functions. You have one global > variable, "the current window". So long as your API makes it obvious when > the current window changes, implicitly operating on the current window is > no more dangerous than Python's implicit operations on the current > namespace (e.g. "x = 2" binds 2 to x in the current namespace). I'm generally wary of everything global, but you're right as long as no (global) state is involved. > I recommend you look at the random.py API. You have a Random class, that > allows the user to generate as many independent random number generators > as needed. And the module also initialises a private instance, and > exposes the methods of that instance as top-level functions, to cover the > 90% simple case where your application only cares about a single RNG. I looked it up - I think this is a very good approach; to provide easy access to the functionality used in 90% of cases but still give users the flexibility to cover the edge cases. After everybody's input, I think Design #2 or Design #4 would be the best fit for us: Design #2: notepad_1 = start("Notepad") notepad_2 = start("Notepad") switch_to(notepad_1) write("Hello World!") press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') Design #4: notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.activate() write("Hello World!") press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') Normally, I'd go for Design #4, as it results in one less global, is better for autocompletion etc. The thing with our library is that it tries to make its scripts as similar as possible to giving instructions to someone looking over their shoulder at a screen. And in this situation you would just say activate(notepad) rather than notepad.activate(). So the problem lies in a difference between Python's and English grammar. For beauty, I should go with #2. For pragmatism, I should go with #4. It hurts, but I'm leaning towards #4. I have to think about it a little. Thank you so much to everybody for your inputs so far! Best, Michael www.getautoma.com From ethan at stoneleaf.us Wed Mar 27 12:45:49 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Mar 2013 09:45:49 -0700 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> Message-ID: <5153223D.6040002@stoneleaf.us> On 03/27/2013 02:34 AM, Michael Herrmann wrote: > After everybody's input, I think Design #2 or Design #4 would be the best fit for us: > > Design #2: > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') > > Design #4: > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') > > Normally, I'd go for Design #4, as it results in one less global, is better for autocompletion etc. The thing with our library is that it tries to make its scripts as similar as possible to giving instructions to someone looking over their shoulder at a screen. And in this situation you would just say > > activate(notepad) > > rather than > > notepad.activate(). > > So the problem lies in a difference between Python's and English grammar. For beauty, I should go with #2. For pragmatism, I should go with #4. It hurts, but I'm leaning towards #4. I have to think about it a little. Go with #2. Not everything has to be a method. len(), for example, is not a method, even though it calls one. The 'with' support would also be cool. __enter__ sets the new global window object whilst saving the old one, and then __exit__ restores the old one. -- ~Ethan~ From steve+comp.lang.python at pearwood.info Wed Mar 27 20:42:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 00:42:35 GMT Subject: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> Message-ID: <515391fa$0$29998$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 02:34:09 -0700, Michael Herrmann wrote: > On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: >> >> Global *variables* are bad, not global functions. You have one global >> variable, "the current window". So long as your API makes it obvious >> when the current window changes, implicitly operating on the current >> window is no more dangerous than Python's implicit operations on the >> current namespace (e.g. "x = 2" binds 2 to x in the current namespace). > > I'm generally wary of everything global, but you're right as long as no > (global) state is involved. That comment surprises me. Your preferred API: switch_to(notepad) write("Hello World!") press(CTRL + 'a', CTRL + 'c') uses implied global state (the current window). Even if you avoid the use of an actual global for (say) an instance attribute, it's still semantically a global. Surely you realise that? Not trying to be argumentative, I'm just surprised at your comment. >> I recommend you look at the random.py API. You have a Random class, >> that allows the user to generate as many independent random number >> generators as needed. And the module also initialises a private >> instance, and exposes the methods of that instance as top-level >> functions, to cover the 90% simple case where your application only >> cares about a single RNG. > > I looked it up - I think this is a very good approach; to provide easy > access to the functionality used in 90% of cases but still give users > the flexibility to cover the edge cases. > > After everybody's input, I think Design #2 or Design #4 would be the > best fit for us: > > Design #2: > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') This is nice syntax for trivial cases and beginners whose needs are not demanding, but annoying for experts who have more complicated requirements. If this is the only API, experts who need to simultaneously operate in two windows will be forced to write unproductive boilerplate code that does nothing but jump from window to window. Well what do you know, even in the simple case above, you have unproductive code that does nothing but jump from window to window :-) I'm not against this API, I'm just against it as the *only* API. > Design #4: > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') This is actually no different from #2 above, except that it uses method call syntax while #2 uses function call syntax. So it has the same limitations as above: it's simple for simple uses, but annoying for complex use. Neither API supports advanced users with complicated needs. A hybrid approach, where you have function call syntax that operates on the implicit current window, plus method call syntax that operates on any window, strikes me as the best of both worlds. With a little forethought in your implementation, you don't have to duplicate code. E.g. something like this: class WindowOps: def __init__(self, theWindow=None): self.theWindow = None def press(self, c): win = self.getWindow() send_keypress_to(win) def getWindow(self): if self.theWindow is None: return gTheTopWindow return self.theWindow _implicit = WindowOps(None) press = _implicit.press # etc. del _implicit This gives you the best of both worlds, for free: a simple API using an implicit top window for simple cases, and a slightly more complex API with an explicit window for advanced users. > Normally, I'd go for Design #4, as it results in one less global, I don't see how this is possible. Both APIs use an implicit "top window". What's the one less global you are referring to? > is > better for autocompletion etc. The thing with our library is that it > tries to make its scripts as similar as possible to giving instructions > to someone looking over their shoulder at a screen. And in this > situation you would just say > > activate(notepad) > > rather than > > notepad.activate(). Depends like Yoda they talk whether or not. Unless you go all the way to writing your own parser that accepts English- like syntax, like Hypertalk: select notepad type hello world I don't think it makes that much difference. Function call syntax is not exactly English-like either. We don't generally speak like this: write bracket quote hello world quote close bracket My personal feeling is that people aren't going to be *too* confused by method call syntax, especially not if they've seen or been introduced to any programming at all. You say tom-a-to, I say tom-ar-to. But I think it is useful to distinguish between the "basic API" using function call syntax and an implied current window, and an "advanced API" using method call syntax with an explicit window: # Basic API is pure function calls, using an implicit window switch_to(notepad) write("Hello World!") press(CTRL + 'a', CTRL + 'c') switch_to(calculator) write('2+3=') press(CTRL + 'a') switch_to(notepad) press(CTRL + 'v') # Advanced API uses an explicit window and method calls: notepad.write("Hello World!") notepad.press(CTRL + 'a', CTRL + 'c') calculator.write('2+3=') calculator.press(CTRL + 'a') notepad.press(CTRL + 'v') # Of course you can mix usage: switch_to(notepad) write("Hello World!") press(CTRL + 'a', CTRL + 'c') calculator.write('2+3=') calculator.press(CTRL + 'a') press(CTRL + 'v') You could avoid method call syntax altogether by giving your functions an optional argument that points to the window to operate on: write("Hello World!") write("Hello World!", notepad) but the difference is mere syntax. There's little or no additional complexity of implementation to allow the user to optionally specify an explicit window. I expect you have something like this: def write(string): window = gTheCurrentWindow # use a global send characters of string to window # magic goes here This can trivially be changed to: def write(string, window=None): if window is None: window = gTheCurrentWindow send characters of string to window # magic goes here See, for example, the decimal module. Most operations take an optional "context" argument that specifies the number of decimal places, rounding mode, etc. If not supplied, the global "current context" is used. This gives the simplicity and convenience of a global, without the disadvantages. (Recent versions of decimal have also added "with context" syntax, for even more power.) -- Steven From michael.herrmann at getautoma.com Thu Mar 28 07:41:17 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Thu, 28 Mar 2013 04:41:17 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: <515391fa$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> <515391fa$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <367d05b1-bb24-418f-a40e-3fb2287af12a@googlegroups.com> On Thursday, March 28, 2013 1:42:35 AM UTC+1, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 02:34:09 -0700, Michael Herrmann wrote: > > > On Tuesday, March 26, 2013 11:37:23 PM UTC+1, Steven D'Aprano wrote: > >> > >> Global *variables* are bad, not global functions. You have one global > >> variable, "the current window". So long as your API makes it obvious > >> when the current window changes, implicitly operating on the current > >> window is no more dangerous than Python's implicit operations on the > >> current namespace (e.g. "x = 2" binds 2 to x in the current namespace). > > > I'm generally wary of everything global, but you're right as long as no > > (global) state is involved. > > That comment surprises me. Your preferred API: > > switch_to(notepad) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > > uses implied global state (the current window). Even if you avoid the use > of an actual global for (say) an instance attribute, it's still > semantically a global. Surely you realise that? I do :-) You made the statement that global variables are bad, not global functions. I didn't want to agree completely with this comment, because if a global function refers to a global variable, I would consider it "bad" too. You correctly point out that our global functions would be exactly of that "bad" kind. Of course, it doesn't make sense to be too dogmatic about "bad", which is why I am considering the global functions as an option, for advantages they have despite being "bad". > Not trying to be argumentative, I'm just surprised at your comment. No offense taken :) I guess I just wasn't expressing myself clearly. > > ... > > After everybody's input, I think Design #2 or Design #4 would be the > > best fit for us: > > > > Design #2: > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > switch_to(notepad_2) > > press(CTRL + 'v') > > This is nice syntax for trivial cases and beginners whose needs are not > demanding, but annoying for experts who have more complicated > requirements. If this is the only API, experts who need to simultaneously > operate in two windows will be forced to write unproductive boilerplate > code that does nothing but jump from window to window. > > > Well what do you know, even in the simple case above, you have > unproductive code that does nothing but jump from window to window :-) > > I'm not against this API, I'm just against it as the *only* API. > > > Design #4: > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.activate() > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > notepad_2.activate() > > press(CTRL + 'v') > > This is actually no different from #2 above, except that it uses method > call syntax while #2 uses function call syntax. So it has the same > limitations as above: it's simple for simple uses, but annoying for > complex use. > > Neither API supports advanced users with complicated needs. A hybrid > approach, where you have function call syntax that operates on the > implicit current window, plus method call syntax that operates on any > window, strikes me as the best of both worlds. With a little forethought > in your implementation, you don't have to duplicate code. E.g. something > like this: > > class WindowOps: > def __init__(self, theWindow=None): > self.theWindow = None > > def press(self, c): > win = self.getWindow() > send_keypress_to(win) > > def getWindow(self): > if self.theWindow is None: > return gTheTopWindow > return self.theWindow > > _implicit = WindowOps(None) > press = _implicit.press > # etc. > del _implicit > > This gives you the best of both worlds, for free: a simple API using an > implicit top window for simple cases, and a slightly more complex API > with an explicit window for advanced users. I understand completely where you are coming from, however if we offer two ways of doing the same thing, people will start mixing the styles and things will get messy. A user commented above that this approach - offering global as well as object oriented functions to do the same thing - is offered by matplotlib and makes examples on the net very confusing and difficult to read. For this reason, I would rather only offer one way of doing things now, and add additional ways later in case they are really needed. You are right that this may not cater for experts' needs very well, but I think I prefer a smaller API that can be extended to one that may result in being difficult to read. > > Normally, I'd go for Design #4, as it results in one less global, > > I don't see how this is possible. Both APIs use an implicit "top window". > What's the one less global you are referring to? By "global" I meant function name. > > is > > better for autocompletion etc. The thing with our library is that it > > tries to make its scripts as similar as possible to giving instructions > > to someone looking over their shoulder at a screen. And in this > > situation you would just say > > activate(notepad) > > rather than > > notepad.activate(). > > Depends like Yoda they talk whether or not. > > Unless you go all the way to writing your own parser that accepts English- > like syntax, like Hypertalk: > > select notepad > type hello world > > I don't think it makes that much difference. Function call syntax is not > exactly English-like either. We don't generally speak like this: > > write bracket quote hello world quote close bracket > > My personal feeling is that people aren't going to be *too* confused by > method call syntax, especially not if they've seen or been introduced to > any programming at all. You say tom-a-to, I say tom-ar-to. > > But I think it is useful to distinguish between the "basic API" using > function call syntax and an implied current window, and an "advanced API" > using method call syntax with an explicit window: > > > # Basic API is pure function calls, using an implicit window > > switch_to(notepad) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(calculator) > write('2+3=') > press(CTRL + 'a') > switch_to(notepad) > press(CTRL + 'v') > > # Advanced API uses an explicit window and method calls: > > notepad.write("Hello World!") > notepad.press(CTRL + 'a', CTRL + 'c') > calculator.write('2+3=') > calculator.press(CTRL + 'a') > notepad.press(CTRL + 'v') > > # Of course you can mix usage: > > switch_to(notepad) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > calculator.write('2+3=') > calculator.press(CTRL + 'a') > press(CTRL + 'v') As I said, I think I prefer not giving the possibility to mix usage and potentially adding it later over offering it to begin with. > You could avoid method call syntax altogether by giving your functions an > optional argument that points to the window to operate on: > > write("Hello World!") > write("Hello World!", notepad) > > but the difference is mere syntax. That's been pointed out above. I guess it's mostly a question of taste, but I'd like to avoid mixing the concept of "window switching" with the not-very related concepts of typing and clicking. I'm a big fan of orthogonality, mainly because of the book "The Pragmatic Programmer" but also because of the article http://www.artima.com/intv/dry3.html. > There's little or no additional complexity of implementation to allow the > user to optionally specify an explicit window. That's of course true. What I'm worried about is API complexity: I think the matplotlib example shows that offering too many ways of doing one thing leads to scripts that are difficult to read/maintain. I want to keep the API as simple as possible at first, and then add to it when it turns out it's needed. > ... > See, for example, the decimal module. Most operations take an optional > "context" argument that specifies the number of decimal places, rounding > mode, etc. If not supplied, the global "current context" is used. > This gives the simplicity and convenience of a global, without the > disadvantages. That's a very interesting example! I think the decimal module's "setcontext" would be similar to our "switch_to". The fact that this module offers the optional "context" parameter makes it likely that you'll prove me wrong in not including offering such an optional parameter, but I want to see first if we can get by without it, too. Thanks for all your input. Michael www.getautoma.com From michael.herrmann at getautoma.com Thu Mar 28 06:54:33 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Thu, 28 Mar 2013 03:54:33 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <80d9f8b5-64ad-4691-9489-c0d22c2c2b2d@googlegroups.com> <51522323$0$29998$c3e8da3$5496439d@news.astraweb.com> <3e8c3737-1086-4962-bba7-ba346d593b7b@googlegroups.com> Message-ID: On Wednesday, March 27, 2013 5:45:49 PM UTC+1, Ethan Furman wrote: > On 03/27/2013 02:34 AM, Michael Herrmann wrote: > > Design #2: > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > switch_to(notepad_2) > > press(CTRL + 'v') > ... > > Go with #2. Not everything has to be a method. len(), for example, is not a method, even though it calls one. That's a good point. I actually think #2 is the one we'll use. From michael.herrmann at getautoma.com Tue Mar 26 05:38:01 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 02:38:01 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef wrote: > ... > > I think I would prefer context managers. I don't think it's a big > problem for > win users because this behaviour would be one of the first things documented > in the start guide and would be all over example scripts, so a new user > missing > or forgetting it is not a realistic scenario. > > The advantages are that it's explicit, blocks are indented and it's > impossible to > miss which window is the action applied to, and at the same time actions are > short and easy to type and read. Thank you for your reply. What do you think of Chris Angelico's points? He wrote: > What happens at the __exit__ of the context manager? What happens if > context managers are nested? I'd be inclined to the simpler option of > an explicit switch (since focus doesn't really "stack" and it'd feel > weird for focus to *sometimes* switch away when you're done working > with one window), though the context manager syntax does have its > advantages too. What I am most afraid of: that the window that's currently the context "disappears": notepad = start("Notepad") with notepad: press(ALT + TAB) write("Am I in Notepad now?") What do you think of designs #3 and #4? notepad_1 = start("Notepad") notepad_2 = start("Notepad") switch_to(notepad_1) write("Hello World!") press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.activate() write("Hello World!") press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') I somehow prefer "activate" over "focus" as in my feeling, you'd normally say that you focus *on* something, so it should be called "focus_on" or "give_focus[_to]". Can you say, in everyday English, that you "focus a window"? I'm not a native speaker so maybe my feeling is misguided. Thanks, Michael From rosuav at gmail.com Tue Mar 26 07:43:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 22:43:18 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann wrote: > What do you think of designs #3 and #4? > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') Ehh, I referred to these as options 2 and 4. Got lost in the indexing somewhere. These are the same two I meant, though - these are the options I think are the most plausible. (Hindsight being 20/20, it'd have been awesome if the original snippets had had identifiers next to them. Oh well, no matter.) ChrisA From michael.herrmann at getautoma.com Tue Mar 26 08:18:41 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:18:41 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: <99417dba-d543-4a61-9cea-54638e9cbf4a@googlegroups.com> On Tuesday, March 26, 2013 12:43:18 PM UTC+1, Chris Angelico wrote: > On Tue, Mar 26, 2013 at 8:38 PM, Michael Herrmann > > > What do you think of designs #3 and #4? > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > switch_to(notepad_2) > > press(CTRL + 'v') > > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.activate() > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > notepad_2.activate() > > press(CTRL + 'v') > > Ehh, I referred to these as options 2 and 4. Got lost in the indexing > somewhere. These are the same two I meant, though - these are the > options I think are the most plausible. > > (Hindsight being 20/20, it'd have been awesome if the original > snippets had had identifiers next to them. Oh well, no matter.) True, and the indexing mistake was my fault... Here goes: Design #1: notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.write("Hello World!") notepad_1.press(CTRL + 'a', CTRL + 'c') notepad_2.press(CTRL + 'v') Design #2: notepad_1 = start("Notepad") notepad_2 = start("Notepad") switch_to(notepad_1) write("Hello World!") press(CTRL + 'a', CTRL + 'c') switch_to(notepad_2) press(CTRL + 'v') Design #3: notepad_1 = start("Notepad") notepad_2 = start("Notepad") with notepad_1: write("Hello World!") press(CTRL + 'a', CTRL + 'c') with notepad_2: press(CTRL + 'v') Design #4: notepad_1 = start("Notepad") notepad_2 = start("Notepad") notepad_1.activate() write("Hello World!") press(CTRL + 'a', CTRL + 'c') notepad_2.activate() press(CTRL + 'v') Michael www.getautoma.com From msirenef at lightbird.net Tue Mar 26 09:41:38 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 26 Mar 2013 09:41:38 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: <5151A592.8000804@lightbird.net> On 03/26/2013 05:38 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 12:40:45 AM UTC+1, Mitya Sirenef wrote: >> ... >> >> I think I would prefer context managers. I don't think it's a big >> problem for >> win users because this behaviour would be one of the first things documented >> in the start guide and would be all over example scripts, so a new user >> missing >> or forgetting it is not a realistic scenario. >> >> The advantages are that it's explicit, blocks are indented and it's >> impossible to >> miss which window is the action applied to, and at the same time actions are >> short and easy to type and read. > > Thank you for your reply. What do you think of Chris Angelico's points? At the __exit__, further commands are no longer routed to that window; if it was a nested context, window is switched to the outer context, WHEN there are commands in it (i.e. on the first command). This seems pretty intuitive to me: with notepad1: ^S with notepad2: ^S write('something') > > He wrote: >> What happens at the __exit__ of the context manager? What happens if >> context managers are nested? I'd be inclined to the simpler option of >> an explicit switch (since focus doesn't really "stack" and it'd feel >> weird for focus to *sometimes* switch away when you're done working >> with one window), though the context manager syntax does have its >> advantages too. > > What I am most afraid of: that the window that's currently the context "disappears": > notepad = start("Notepad") > with notepad: > press(ALT + TAB) > write("Am I in Notepad now?") Alt-tab needs to be handled by a wrapper function that gives you the object of the window you've switched to: otherwin = alt_tab() with otherwin: ... If window is changed within 'with' block, the rest of block should be ignored. Perhaps there could also be a way to switch this behaviour off, for the entire script or for current block only. > > What do you think of designs #3 and #4? > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > switch_to(notepad_1) > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > switch_to(notepad_2) > press(CTRL + 'v') > > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.activate() > write("Hello World!") > press(CTRL + 'a', CTRL + 'c') > notepad_2.activate() > press(CTRL + 'v') > > I somehow prefer "activate" over "focus" as in my feeling, you'd normally say that you focus *on* something, so it should be called "focus_on" or "give_focus[_to]". Can you say, in everyday English, that you "focus a window"? I'm not a native speaker so maybe my feeling is misguided. These are ok, too, but I feel it's much easier to send commands to a wrong window vs. context managers. The same command in a different window can have vastly different and dangerous effect. In other python code that's generally not common at all, and would be bad style: lst = lst1 lst.append('x') del lst[3] lst.insert(0, 'a') lst = lst2 del lst[2] lst.append('y') lst = lst3 lst.insert(0, 'x') lst += [1,2] I think current window should also be acquired explicitly: with get_current_window(): type("some kind of snippet") For usage when a command should apply to all types of windows. HTH, -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Food is an important part of a balanced diet. Fran Lebowitz From michael.herrmann at getautoma.com Tue Mar 26 10:59:21 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 07:59:21 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote: > ... > At the __exit__, further commands are no longer routed to that window; > if it was a nested context, window is switched to the outer context, > WHEN there are commands in it (i.e. on the first command). This seems > pretty intuitive to me: > > with notepad1: > ^S > with notepad2: > ^S > write('something') > > ... > > What I am most afraid of: that the window that's currently the > > context "disappears": > > > notepad = start("Notepad") > > with notepad: > > press(ALT + TAB) > > write("Am I in Notepad now?") > > > Alt-tab needs to be handled by a wrapper function that gives you the > object of the window you've switched to: > > otherwin = alt_tab() > with otherwin: > ... > > If window is changed within 'with' block, the rest of block should be > ignored. Perhaps there could also be a way to switch this behaviour off, > for the entire script or for current block only. > > > > What do you think of designs #3 and #4? > > ... > > These are ok, too, but I feel it's much easier to send commands to a > wrong window vs. context managers. The same command in a different > window can have vastly different and dangerous effect. In other python > code that's generally not common at all, and would be bad style: > > lst = lst1 > lst.append('x') > del lst[3] > lst.insert(0, 'a') > lst = lst2 > del lst[2] > lst.append('y') > lst = lst3 > lst.insert(0, 'x') > lst += [1,2] > > I think current window should also be acquired explicitly: > > with get_current_window(): > type("some kind of snippet") > > For usage when a command should apply to all types of windows. I was skeptical of your suggestion at first but trying it out on an example script made me see its appeal: notepad_main = start("Notepad") with notepad_main: write("Hello World!") save_dialogue = press(CTRL + 's') with save_dialogue: write("test.txt", into="File name") click("Save") click("Close") Forcing the library user to always use the "with ..." seems like overkill though. I think the gained precision does not justify this burden on the library user. Hm.... From rosuav at gmail.com Tue Mar 26 11:16:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 02:16:57 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann wrote: > save_dialogue = press(CTRL + 's') Does every single API need to then consider the possibility of focus changing? How does the press() function know that this will (or might - if the file's already been named, Ctrl-S won't open a dlg) change focus? How does the caller know? ChrisA From msirenef at lightbird.net Tue Mar 26 18:01:08 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Tue, 26 Mar 2013 18:01:08 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: <51521AA4.4090104@lightbird.net> On 03/26/2013 10:59 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote: >> ... >> At the __exit__, further commands are no longer routed to that window; >> if it was a nested context, window is switched to the outer context, >> WHEN there are commands in it (i.e. on the first command). This seems >> pretty intuitive to me: >> >> with notepad1: >> ^S >> with notepad2: >> ^S >> write('something') >> > >> ... >> > What I am most afraid of: that the window that's currently the >> > context "disappears": >> >> > notepad = start("Notepad") >> > with notepad: >> > press(ALT + TAB) >> > write("Am I in Notepad now?") >> >> >> Alt-tab needs to be handled by a wrapper function that gives you the >> object of the window you've switched to: >> >> otherwin = alt_tab() >> with otherwin: >> ... >> >> If window is changed within 'with' block, the rest of block should be >> ignored. Perhaps there could also be a way to switch this behaviour off, >> for the entire script or for current block only. >> >> >> > What do you think of designs #3 and #4? >> > ... >> >> These are ok, too, but I feel it's much easier to send commands to a >> wrong window vs. context managers. The same command in a different >> window can have vastly different and dangerous effect. In other python >> code that's generally not common at all, and would be bad style: >> >> lst = lst1 >> lst.append('x') >> del lst[3] >> lst.insert(0, 'a') >> lst = lst2 >> del lst[2] >> lst.append('y') >> lst = lst3 >> lst.insert(0, 'x') >> lst += [1,2] >> >> I think current window should also be acquired explicitly: >> >> with get_current_window(): >> type("some kind of snippet") >> >> For usage when a command should apply to all types of windows. > > I was skeptical of your suggestion at first but trying it out on an example script made me see its appeal: > > notepad_main = start("Notepad") > with notepad_main: > write("Hello World!") > save_dialogue = press(CTRL + 's') > with save_dialogue: > write("test.txt", into="File name") > click("Save") > click("Close") > > Forcing the library user to always use the "with ..." seems like overkill though. I think the gained precision does not justify this burden on the library user. Hm.... I don't see why that's a big deal, I've used AHK extensively and in my experience you don't switch windows all that often. I think it's best to optimize to have easy to type and read commands while you're working in the same window. I think you could argue that dialogs that belong to the main window should be handled implicitly, though. I think for other windows it'd definitely be good to use context managers, but for quick/simple dialogs it's too much hassle, although for large, complex dialogs that have inner tabs and require a lot of work, it again starts to make sense. At the very least, for small dialogs it's sipmpler to do: with press(CTRL + 's'): write("test.txt", into="File name") click("Save") -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Calamities are of two kinds: misfortunes to ourselves, and good fortune to others. Ambrose Bierce, The Devil's Dictionary From michael.herrmann at getautoma.com Wed Mar 27 04:45:19 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 01:45:19 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: <41f33ffa-1c26-4e25-bee3-52647c30a141@googlegroups.com> On Tuesday, March 26, 2013 4:16:57 PM UTC+1, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 1:59 AM, Michael Herrmann > > wrote: > > save_dialogue = press(CTRL + 's') > > Does every single API need to then consider the possibility of focus > changing? How does the press() function know that this will (or might > - if the file's already been named, Ctrl-S won't open a dlg) change > focus? How does the caller know? While I can see where it is coming from, I am also not a big fan of this idea. Michael From michael.herrmann at getautoma.com Wed Mar 27 05:10:58 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 02:10:58 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:01:08 PM UTC+1, Mitya Sirenef wrote: > On 03/26/2013 10:59 AM, Michael Herrmann wrote: > > ... > > Forcing the library user to always use the "with ..." seems like > overkill though. I think the gained precision does not justify this > burden on the library user. Hm.... > > I don't see why that's a big deal, I've used AHK extensively and in my > experience you don't switch windows all that often. I think it's best to > optimize to have easy to type and read commands while you're working in > the same window. > > I think you could argue that dialogs that belong to the main window > should be handled implicitly, though. I think for other windows it'd > definitely be good to use context managers, but for quick/simple dialogs > it's too much hassle, although for large, complex dialogs that have > inner tabs and require a lot of work, it again starts to make sense. > > At the very least, for small dialogs it's sipmpler to do: > > with press(CTRL + 's'): > write("test.txt", into="File name") > click("Save") I think what the context manager approach really has going for itself is the syntactic structure it gives to scripts, that makes it easy to see what is going on in which window. Semantically, however, I think the fit of this approach has some rough edges: The fact that there needs to be some special treatment for ALT + TAB, that actions such as `press` "sometimes" return values that are needed to continue the script and so on. It really has its appeal, but I think it's a bit too special and intricate to be used by a broad audience. > Calamities are of two kinds: misfortunes to ourselves, and good fortune > to others. ;-) Michael www.getautoma.com From msirenef at lightbird.net Wed Mar 27 09:56:55 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 27 Mar 2013 09:56:55 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: <5152FAA7.3010005@lightbird.net> On 03/27/2013 05:10 AM, Michael Herrmann wrote: >> At the very least, for small dialogs it's sipmpler to do: >> > >> > with press(CTRL + 's'): >> > write("test.txt", into="File name") >> > click("Save") > I think what the context manager approach really has going for itself > is the syntactic structure it gives to scripts, that makes it easy to > see what is going on in which window. Semantically, however, I think > the fit of this approach has some rough edges: The fact that there > needs to be some special treatment for ALT + TAB, that actions such as > `press` "sometimes" return values that are needed to continue the > script and so on. It really has its appeal, but I think it's a bit too > special and intricate to be used by a broad audience. > I think alt-tab has to be special in any case. Regular alt-tab would act like the GOTO statement. As a programmer looking at a script you have no idea where you just alt-tabbed to without possibly looking through dozens of lines of previous code. Keypresses that start a new window also seem pretty special to me. They're inherently special. After all, the essential function of a windowing system is when a new window is created, which means subsequent operations have an entirely different meaning, in a text editor key will delete a character, in a file manager key will delete a file! But, as I mentioned, if you can get away with treating simple dialogs implicitly (and I don't see why you can't, at this point), that'd be the preferred way for me. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ "The condition of man is already close to satiety and arrogance, and there is danger of destruction of everything in existence." - a Brahmin to Onesicritus, 327 BC, reported in Strabo's Geography From michael.herrmann at getautoma.com Thu Mar 28 06:52:46 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Thu, 28 Mar 2013 03:52:46 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> Message-ID: On Wednesday, March 27, 2013 2:56:55 PM UTC+1, Mitya Sirenef wrote: > ... > > I think alt-tab has to be special in any case. Regular alt-tab would act > like the GOTO statement. As a programmer looking at a script you have no > idea where you just alt-tabbed to without possibly looking through > dozens of lines of previous code. > > Keypresses that start a new window also seem pretty special to me. > They're inherently special. After all, the essential function of a > windowing system is when a new window is created, which means subsequent > operations have an entirely different meaning, in a text editor > key will delete a character, in a file manager key will delete a > file! > > But, as I mentioned, if you can get away with treating simple dialogs > implicitly (and I don't see why you can't, at this point), that'd be the > preferred way for me. Ok. Thank you for your inputs! From neilc at norwich.edu Tue Mar 26 10:13:30 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Mar 2013 14:13:30 GMT Subject: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: On 2013-03-25, Mitya Sirenef wrote: > I think I would prefer context managers. I don't think it's a > big problem for win users because this behaviour would be one > of the first things documented in the start guide and would be > all over example scripts, so a new user missing or forgetting > it is not a realistic scenario. If window focus switching is really a rarity, and only done briefly then I agree that a context manager makes a nice and neat solution. But it's too powerful a generalisation for such a small corner case. Have you considered adding a keyword argument to each of your global functions, which is normally None, but allows a user to provide a prefered focus window? enter_text("test.txt", focus=save_dialog) press_button(Savebutton, focus=save_dialog) (Those are just guesses at your API functions; sorry.) When focus remains None, your usual assumptions about focus would apply, otherwise the user preference overrides it. -- Neil Cerutti From michael.herrmann at getautoma.com Tue Mar 26 10:40:03 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 07:40:03 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: > On 2013-03-25, Mitya Sirenef wrote: > > > I think I would prefer context managers. I don't think it's a > > big problem for win users because this behaviour would be one > > of the first things documented in the start guide and would be > > all over example scripts, so a new user missing or forgetting > > it is not a realistic scenario. > > > If window focus switching is really a rarity, and only done > briefly then I agree that a context manager makes a nice and neat > solution. > > > But it's too powerful a generalisation for such a small corner > case. > > Have you considered adding a keyword argument to each of your > global functions, which is normally None, but allows a user to > provide a prefered focus window? > > enter_text("test.txt", focus=save_dialog) > > press_button(Savebutton, focus=save_dialog) It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. > (Those are just guesses at your API functions; sorry.) No worries! Thank you for your suggestion! Michael www.getautoma.com From davea at davea.name Tue Mar 26 12:41:42 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 12:41:42 -0400 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> Message-ID: <5151CFC6.8050109@davea.name> On 03/26/2013 10:40 AM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: >> >> >> Have you considered adding a keyword argument to each of your >> global functions, which is normally None, but allows a user to >> provide a prefered focus window? >> >> enter_text("test.txt", focus=save_dialog) >> >> press_button(Savebutton, focus=save_dialog) > > It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. > Perhaps Neil didn't make it clear enough. I figure he meant a keyword argument with an explicit default value of None. (or if you followed my earlier discussion, default value of focused) That way your user can keep using the functions for when there's no ambiguity, but add a focus= parameter only when needed. To go back to my sample wrapper functions, they'd look something like (untested): def write(*args, focus=focused): focus.write(*args) Of course, the user should only use the wrappers when things are sure to remain "simple." -- DaveA From neilc at norwich.edu Tue Mar 26 13:25:41 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Mar 2013 17:25:41 GMT Subject: Help me pick an API design (OO vs functional) References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> Message-ID: On 2013-03-26, Dave Angel wrote: > On 03/26/2013 10:40 AM, Michael Herrmann wrote: >> On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: >>> >>> >>> Have you considered adding a keyword argument to each of your >>> global functions, which is normally None, but allows a user to >>> provide a prefered focus window? >>> >>> enter_text("test.txt", focus=save_dialog) >>> >>> press_button(Savebutton, focus=save_dialog) >> >> It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. >> > > Perhaps Neil didn't make it clear enough. I figure he meant a keyword > argument with an explicit default value of None. (or if you followed my > earlier discussion, default value of focused) > > That way your user can keep using the functions for when there's no > ambiguity, but add a focus= parameter only when needed. > > To go back to my sample wrapper functions, they'd look something like > (untested): > > > def write(*args, focus=focused): > focus.write(*args) > > Of course, the user should only use the wrappers when things > are sure to remain "simple." Yes, along those lines. Most code would never need to provide the focus= keyword. Only when setting focus in a weird way would it be needed. -- Neil Cerutti From michael.herrmann at getautoma.com Wed Mar 27 04:55:22 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 01:55:22 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> Message-ID: <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> On Tuesday, March 26, 2013 5:41:42 PM UTC+1, Dave Angel wrote: > On 03/26/2013 10:40 AM, Michael Herrmann wrote: > > > On Tuesday, March 26, 2013 3:13:30 PM UTC+1, Neil Cerutti wrote: > >> > >> Have you considered adding a keyword argument to each of your > >> global functions, which is normally None, but allows a user to > >> provide a prefered focus window? > > >> enter_text("test.txt", focus=save_dialog) > >> press_button(Savebutton, focus=save_dialog) > > > It's an interesting new idea but I somehow feel it makes the existing functions too complicated. Also, having to add it to all existing, and future functions sounds a bit too cumbersome to me. > > Perhaps Neil didn't make it clear enough. I figure he meant a keyword > argument with an explicit default value of None. (or if you followed my > earlier discussion, default value of focused) > > That way your user can keep using the functions for when there's no > ambiguity, but add a focus= parameter only when needed. > > To go back to my sample wrapper functions, they'd look something like > (untested): > > def write(*args, focus=focused): > focus.write(*args) I understood what you meant - I'm not so worried about the invocations, as of course the parameter can be omitted if there's a default value/behaviour. What I am worried about is the complexity this approach adds to several functions. Yes, you could argue that one keyword argument really isn't that much, but then you have to maintain and document it for all functions that have the new keyword parameter. In other words, a single functionality that is not needed 90% of the time increases the complexity of several, not really related functions. I am very grateful for your suggestions! But I don't think adding this keyword parameter is the way to go for us. Thanks, Michael www.getautoma.com From rosuav at gmail.com Wed Mar 27 07:44:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 22:44:49 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 7:55 PM, Michael Herrmann wrote: > On Tuesday, March 26, 2013 5:41:42 PM UTC+1, Dave Angel wrote: >> To go back to my sample wrapper functions, they'd look something like >> (untested): >> >> def write(*args, focus=focused): >> focus.write(*args) > > I understood what you meant - I'm not so worried about the invocations, as of course the parameter can be omitted if there's a default value/behaviour. What I am worried about is the complexity this approach adds to several functions. Yes, you could argue that one keyword argument really isn't that much, but then you have to maintain and document it for all functions that have the new keyword parameter. In other words, a single functionality that is not needed 90% of the time increases the complexity of several, not really related functions. I am very grateful for your suggestions! But I don't think adding this keyword parameter is the way to go for us. > Not seeking to advocate this particular option, but it would be possible to make a single wrapper for all your functions to handle the focus= parameter: def focusable(func): @functools.wraps(func) def wrapper(*args,focus=None): if focus: focus.activate() return func(*args) return wrapper Then you just decorate all your functions with that: def write(string): # do something with the active window ChrisA From michael.herrmann at getautoma.com Wed Mar 27 08:23:57 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 05:23:57 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> Message-ID: On Wednesday, March 27, 2013 12:44:49 PM UTC+1, Chris Angelico wrote: > ... > Not seeking to advocate this particular option, but it would be > possible to make a single wrapper for all your functions to handle the > focus= parameter: > > def focusable(func): > @functools.wraps(func) > def wrapper(*args,focus=None): > if focus: focus.activate() > return func(*args) > return wrapper > > Then you just decorate all your functions with that: > > def write(string): > # do something with the active window Hi, sure, I wouldn't have copy-pasted the code and of course there are techniques to avoid code duplication. It's not so much what I'm worried about. What I'm worried about is that the concept of window-switching gets "smeared" over several other not-really related concepts such as clicking and typing. I feel it violates orthogonality: http://www.artima.com/intv/dry3.html is the best freely available resource I could find but I think it's best explained in The Pragmatic Programmer http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X. Michael www.getautoma.com From michael.herrmann at getautoma.com Wed Mar 27 08:23:57 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Wed, 27 Mar 2013 05:23:57 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <5b2ddb12-ad76-46f9-9f01-f67595b7ff54@googlegroups.com> <5483aad6-221e-46f8-8909-bf743e9fcb5c@googlegroups.com> Message-ID: On Wednesday, March 27, 2013 12:44:49 PM UTC+1, Chris Angelico wrote: > ... > Not seeking to advocate this particular option, but it would be > possible to make a single wrapper for all your functions to handle the > focus= parameter: > > def focusable(func): > @functools.wraps(func) > def wrapper(*args,focus=None): > if focus: focus.activate() > return func(*args) > return wrapper > > Then you just decorate all your functions with that: > > def write(string): > # do something with the active window Hi, sure, I wouldn't have copy-pasted the code and of course there are techniques to avoid code duplication. It's not so much what I'm worried about. What I'm worried about is that the concept of window-switching gets "smeared" over several other not-really related concepts such as clicking and typing. I feel it violates orthogonality: http://www.artima.com/intv/dry3.html is the best freely available resource I could find but I think it's best explained in The Pragmatic Programmer http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X. Michael www.getautoma.com From jeanmichel at sequans.com Tue Mar 26 06:07:45 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 26 Mar 2013 11:07:45 +0100 (CET) Subject: Help me pick an API design (OO vs functional) In-Reply-To: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <122999203.1016560.1364292465447.JavaMail.root@sequans.com> ----- Original Message ----- > notepad_1 = start("Notepad") > notepad_2 = start("Notepad") > notepad_1.write("Hello World!") > notepad_1.press(CTRL + 'a', CTRL + 'c') > notepad_2.press(CTRL + 'v') > > The problem with this design is that it effectively duplicates our > API: We want to keep our "global" functions because they are so easy > to read. So is the example above. This is the best solution in my opinion. I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style. One looks like legend() title() plot() save() the other looks like fig = figure() fig.add_legend() fig.title() fig.plot() fig.save() The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare. I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting , very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!" 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 michael.herrmann at getautoma.com Tue Mar 26 07:52:49 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 04:52:49 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > notepad_2.press(CTRL + 'v') > > > > The problem with this design is that it effectively duplicates our > > API: We want to keep our "global" functions because they are so easy > > to read. > > So is the example above. This is the best solution in my opinion. Thanks for your reply. What do you mean by "So is the example above" though? > I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style. > > One looks like > > legend() > title() > plot() > save() > > the other looks like > > fig = figure() > fig.add_legend() > fig.title() > fig.plot() > fig.save() > > The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare. Interesting point. I'll google a little about matplotlib. > I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting , very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!" Doesn't the IPython do auto-completion for "global" functions? Thanks, Michael (www.getautoma.com) From michael.herrmann at getautoma.com Tue Mar 26 07:52:49 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 04:52:49 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > notepad_2.press(CTRL + 'v') > > > > The problem with this design is that it effectively duplicates our > > API: We want to keep our "global" functions because they are so easy > > to read. > > So is the example above. This is the best solution in my opinion. Thanks for your reply. What do you mean by "So is the example above" though? > I think you're having the same issue that some other APIs, let's say matplotlib for example. They try to accommodate scientists (matlab) and programmers(python) by having a double API style. > > One looks like > > legend() > title() > plot() > save() > > the other looks like > > fig = figure() > fig.add_legend() > fig.title() > fig.plot() > fig.save() > > The problem is, when searching for example on the net, you'll end up with a mix of both, it can become a nightmare. Interesting point. I'll google a little about matplotlib. > I definitely prefer the later, for the reasons that have already been given to you in this thread and by the fact that with the correct (I)python shell, you can create your window object and get auto-completion on its methods just by hitting , very helpful when introspecting objects. Can be achieved of course in any python shell with function like dir() ; my point being that OOO design keeps things in their place, see the zen of python "Namespaces are one honking great idea -- let's do more of those!" Doesn't the IPython do auto-completion for "global" functions? Thanks, Michael (www.getautoma.com) From rosuav at gmail.com Tue Mar 26 07:57:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 22:57:21 +1100 Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann wrote: > Doesn't the IPython do auto-completion for "global" functions? Even if it does, it'll be polluted with every other global. Methods don't have that problem. On the flip side, since presumably this is (will be) a module, anyone who wants autocomplete of its top-level functions can simply "import module" instead of "from module import *", which will do the same namespacing. ChrisA From jeanmichel at sequans.com Tue Mar 26 08:16:56 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 26 Mar 2013 13:16:56 +0100 (CET) Subject: Help me pick an API design (OO vs functional) In-Reply-To: Message-ID: <2064522478.1127245.1364300216369.JavaMail.root@sequans.com> ----- Original Message ----- > On Tuesday, March 26, 2013 11:07:45 AM UTC+1, Jean-Michel Pichavant > wrote: > > ----- Original Message ----- > > > notepad_1 = start("Notepad") > > > notepad_2 = start("Notepad") > > > notepad_1.write("Hello World!") > > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > > notepad_2.press(CTRL + 'v') > > > ^ | here, this is an above example :D > > > The problem with this design is that it effectively duplicates > > > our > > > API: We want to keep our "global" functions because they are so > > > easy > > > to read. > > > > So is the example above. This is the best solution in my opinion. > > Thanks for your reply. What do you mean by "So is the example above" > though? Well the example above :). [snip] > Doesn't the IPython do auto-completion for "global" functions? Yes it does, but as Chris pointed out, your global/module namespace will be "polluted" by a lot of names. By using completion on an object, you get the method it has access to, which is very useful to narrow down what you can do 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. From michael.herrmann at getautoma.com Tue Mar 26 08:20:21 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:20:21 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: <1a32e2c4-ca0d-4390-8dde-8345d8f7b28c@googlegroups.com> On Tuesday, March 26, 2013 12:57:21 PM UTC+1, Chris Angelico wrote: > On Tue, Mar 26, 2013 at 10:52 PM, Michael Herrmann > > Doesn't the IPython do auto-completion for "global" functions? > > Even if it does, it'll be polluted with every other global. Methods > don't have that problem. On the flip side, since presumably this is > (will be) a module, anyone who wants autocomplete of its top-level > functions can simply "import module" instead of "from module import > *", which will do the same namespacing. True! I don't think "polluting" the global namespace is that much of an issue. From michael.herrmann at getautoma.com Tue Mar 26 08:27:49 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Tue, 26 Mar 2013 05:27:49 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: References: Message-ID: On Tuesday, March 26, 2013 1:16:56 PM UTC+1, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > > > notepad_1 = start("Notepad") > > > > notepad_2 = start("Notepad") > > > > notepad_1.write("Hello World!") > > > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > > > notepad_2.press(CTRL + 'v') > > > > > > ^ > | > here, this is an above example :D > > > > > The problem with this design is that it effectively duplicates > > > > our > > > > API: We want to keep our "global" functions because they are so > > > > easy > > > > to read. > > > > > > So is the example above. This is the best solution in my opinion. > > Ah, so you meant "is also easy to read" ;) I agree but the example with global functions is even easier to read. I guess I am being pretty anal about these issues, but I see every unnecessary syntax we can save as a win. > [snip] > > Doesn't the IPython do auto-completion for "global" functions? > > Yes it does, but as Chris pointed out, your global/module namespace will be "polluted" by a lot of names. > By using completion on an object, you get the method it has access to, which is very useful to narrow down what you can do with it. I see. I know you prefer design #1 but that would at least place design #4 over #3, right? Thanks. Michael www.getautoma.com From tundra at tundraware.com Mon Mar 25 15:24:33 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 25 Mar 2013 14:24:33 -0500 Subject: Python 2.7.3 + Docutils + Cygwin = Aborted? Message-ID: I've asked this question on the Docutils list but there seems to be no obvious Docutils problem, so I'll ask here.... If I do this: python rst2latex.py foo.latex It works BUT python ends with an "Aborted" message and an empty python2.7.exe.stackdump. The practical problem here is that the python abort is causing the makefile that drives the whole process to stop. The same thing works fine with the same input file on FreeBSD or Linux. Is there a known Cygwin python 2.7 interaction issue? -- ----------------------------------------------------------------------- Tim Daneliuk From stalkernew at gmail.com Mon Mar 25 16:28:34 2013 From: stalkernew at gmail.com (Kyle) Date: Mon, 25 Mar 2013 13:28:34 -0700 (PDT) Subject: How to define "exec" method on a class object? Get syntax error due to built in command Message-ID: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand "exec" that is failing to compile in the python case. There seems to be some built-in python command "exec" which is giving a syntax error in the .py file generated by swig when I try to import it: def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ^ SyntaxError: invalid syntax I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called "exec" on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in "exec" command. class dm_cli(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) def __init__(self): raise RuntimeError, "No constructor defined" ... def exec(*args): return _wbt_daemon.dm_cli_exec(*args) ... } From rosuav at gmail.com Mon Mar 25 16:43:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 07:43:45 +1100 Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 7:28 AM, Kyle wrote: > I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand "exec" that is failing to compile in the python case. There seems to be some built-in python command "exec" which is giving a syntax error in the .py file generated by swig when I try to import it: > > def exec(*args): return _wbt_daemon.dm_cli_exec(*args) In Python 2, exec is a keyword, so you can't do that. In Python 3, exec is simply a built-in function, so it'd work fine. Technically you can get around the problem in 2.x with setattr/getattr, but that may not really be all that useful... def _exec(*args): return _wbt_daemon.dm_cli_exec(*args) ... setattr(dm_cli,"exec",dm_cli._exec) Tested on 2.6 for Windows (I really ought to get myself a 2.7, maybe when 2.7.4 gets released I'll grab it). ChrisA From stalkernew at gmail.com Tue Mar 26 14:13:50 2013 From: stalkernew at gmail.com (Kyle) Date: Tue, 26 Mar 2013 11:13:50 -0700 (PDT) Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> Message-ID: <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote: > I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand "exec" that is failing to compile in the python case. There seems to be some built-in python command "exec" which is giving a syntax error in the .py file generated by swig when I try to import it: > > > > def exec(*args): return _wbt_daemon.dm_cli_exec(*args) > > ^ > > SyntaxError: invalid syntax > > > > I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called "exec" on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in "exec" command. > > > > class dm_cli(_object): > > __swig_setmethods__ = {} > > __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) > > __swig_getmethods__ = {} > > __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) > > def __init__(self): raise RuntimeError, "No constructor defined" > > ... > > def exec(*args): return _wbt_daemon.dm_cli_exec(*args) > > ... > > } Thanks for the suggestion. Looks like we currently use 2.3.4. This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. I think the easiest thing for me to do would be to just change the command name from exec to something else. From ethan at stoneleaf.us Tue Mar 26 14:36:12 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Mar 2013 11:36:12 -0700 Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Message-ID: <5151EA9C.4060407@stoneleaf.us> On 03/26/2013 11:13 AM, Kyle wrote: > On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote: >> I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand "exec" that is failing to compile in the python case. There seems to be some built-in python command "exec" which is giving a syntax error in the .py file generated by swig when I try to import it: >> >> >> >> def exec(*args): return _wbt_daemon.dm_cli_exec(*args) >> >> ^ >> >> SyntaxError: invalid syntax >> >> >> >> I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called "exec" on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in "exec" command. >> >> >> >> class dm_cli(_object): >> >> __swig_setmethods__ = {} >> >> __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) >> >> __swig_getmethods__ = {} >> >> __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) >> >> def __init__(self): raise RuntimeError, "No constructor defined" >> >> ... >> >> def exec(*args): return _wbt_daemon.dm_cli_exec(*args) >> >> ... >> >> } > > Thanks for the suggestion. Looks like we currently use 2.3.4. > > This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. > > I think the easiest thing for me to do would be to just change the command name from exec to something else. Yeah, that's unfortunate. I suggest 'execute'. :) -- ~Ethan~ From rosuav at gmail.com Tue Mar 26 14:43:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 05:43:48 +1100 Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 5:13 AM, Kyle wrote: > Thanks for the suggestion. Looks like we currently use 2.3.4. > > This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. > > I think the easiest thing for me to do would be to just change the command name from exec to something else. ..... that's pretty ancient. Any chance you can upgrade at least to 2.7.3? ChrisA From stalkernew at gmail.com Tue Mar 26 15:24:22 2013 From: stalkernew at gmail.com (Kyle) Date: Tue, 26 Mar 2013 12:24:22 -0700 (PDT) Subject: How to define "exec" method on a class object? Get syntax error due to built in command References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Message-ID: On Mar 26, 2:43?pm, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 5:13 AM, Kyle wrote: > > Thanks for the suggestion. Looks like we currently use 2.3.4. > > > This still wouldn't solve the problem because now the user would need to call something like ?getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. > > > I think the easiest thing for me to do would be to just change the command name from exec to something else. > > ..... that's pretty ancient. Any chance you can upgrade at least to 2.7.3? > > ChrisA Unfortunately, while I could update my machine, there's no guarantee others would have the same version--the 2.3.4 seems to be the default on our machines and in the automount dirs. From rosuav at gmail.com Tue Mar 26 15:39:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 06:39:24 +1100 Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 6:24 AM, Kyle wrote: > On Mar 26, 2:43 pm, Chris Angelico wrote: >> On Wed, Mar 27, 2013 at 5:13 AM, Kyle wrote: >> > Thanks for the suggestion. Looks like we currently use 2.3.4. >> >> > This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. >> >> > I think the easiest thing for me to do would be to just change the command name from exec to something else. >> >> ..... that's pretty ancient. Any chance you can upgrade at least to 2.7.3? >> >> ChrisA > > Unfortunately, while I could update my machine, there's no guarantee > others would have the same version--the 2.3.4 seems to be the default > on our machines and in the automount dirs. I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly a decade of bug fixes and feature enhancements behind the times. 2.7.3 is the latest 2.x release, and most likely your code will run unchanged on it; if you can switch to 3.3.0 (the latest 3.x release), that would actually fix your exec problem, for what that's worth. (Moving to 3.3.0 would be a much bigger change, though, and one that's likely to require code edits.) It's a good thing Python has neither the number nor breadth of security vulnerabilities as Windows; you're using something nearly as old as an unpatched Windows XP, no service packs, no Windows Update, nothing... no sane systems administrator would let you put that on the internet. It may not be suicidal like that, but it's still ten years' worth of updates you're missing out on! ChrisA From steve+comp.lang.python at pearwood.info Tue Mar 26 19:19:17 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 23:19:17 GMT Subject: How to define "exec" method on a class object? Get syntax error due to built in command References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Message-ID: <51522cf5$0$29998$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 06:39:24 +1100, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 6:24 AM, Kyle wrote: >> On Mar 26, 2:43 pm, Chris Angelico wrote: >>> On Wed, Mar 27, 2013 at 5:13 AM, Kyle wrote: >>> > Thanks for the suggestion. Looks like we currently use 2.3.4. >>> >>> > This still wouldn't solve the problem because now the user would >>> > need to call something like getattr(wbt, "exec")() instead of >>> > wbt.exec() like all the other commands. >>> >>> > I think the easiest thing for me to do would be to just change the >>> > command name from exec to something else. >>> >>> ..... that's pretty ancient. Any chance you can upgrade at least to >>> 2.7.3? >>> >>> ChrisA >> >> Unfortunately, while I could update my machine, there's no guarantee >> others would have the same version--the 2.3.4 seems to be the default >> on our machines and in the automount dirs. > > I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly > a decade of bug fixes and feature enhancements behind the times. Python 2.3 is still supported by Red Hat, at least if you have paid for extended support. In principle at least, Red Hat will be providing security fixes for 2.3. > 2.7.3 > is the latest 2.x release, and most likely your code will run unchanged > on it; if you can switch to 3.3.0 (the latest 3.x release), that would > actually fix your exec problem, for what that's worth. (Moving to 3.3.0 > would be a much bigger change, though, and one that's likely to require > code edits.) If the OP's code uses string exceptions: raise "an error occurred" they will need to be replaced before migrating to 2.7. -- Steven From rosuav at gmail.com Tue Mar 26 21:27:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 12:27:17 +1100 Subject: How to define "exec" method on a class object? Get syntax error due to built in command In-Reply-To: <51522cf5$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> <51522cf5$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 27, 2013 at 10:19 AM, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 06:39:24 +1100, Chris Angelico wrote: >> I strongly recommend upgrading. 2.3.4 dates back to 2004, that's roughly >> a decade of bug fixes and feature enhancements behind the times. > > Python 2.3 is still supported by Red Hat, at least if you have paid for > extended support. In principle at least, Red Hat will be providing > security fixes for 2.3. Oh, I thought they only supported 2.4. My bad. Still, there's ten years of feature improvements, even if not security patches. ChrisA From rosuav at gmail.com Mon Mar 25 17:51:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 08:51:07 +1100 Subject: Performance of int/long in Python 3 Message-ID: The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally. Is there value in making the int type have a machine-word optimization in the same way? The cost is clear. Compare these methods for calculating the sum of all numbers up to 65535, which stays under 2^31: def range_sum(n): return sum(range(n+1)) def forloop(n): tot=0 for i in range(n+1): tot+=i return tot def forloop_offset(n): tot=1000000000000000 for i in range(n+1): tot+=i return tot-1000000000000000 import timeit import sys print(sys.version) print("inline: %d"%sum(range(65536))) print(timeit.timeit("sum(range(65536))",number=1000)) for func in ['range_sum','forloop','forloop_offset']: print("%s: %r"%(func,(globals()[func](65535)))) print(timeit.timeit(func+"(65535)","from __main__ import "+func,number=1000)) Windows XP: C:\>python26\python inttime.py 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] inline: 2147450880 2.36770455463 range_sum: 2147450880 2.61778550067 forloop: 2147450880 7.91409131608 forloop_offset: 2147450880L 23.3116954809 C:\>python33\python inttime.py 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] inline: 2147450880 5.25038713020789 range_sum: 2147450880 5.412975112758745 forloop: 2147450880 17.875799577879313 forloop_offset: 2147450880 19.31672544974291 Debian Wheezy: rosuav at sikorsky:~$ python inttime.py 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] inline: 2147450880 1.92763710022 range_sum: 2147450880 1.93409109116 forloop: 2147450880 5.14633893967 forloop_offset: 2147450880 5.13459300995 rosuav at sikorsky:~$ python3 inttime.py 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] inline: 2147450880 2.884124994277954 range_sum: 2147450880 2.6586129665374756 forloop: 2147450880 7.660192012786865 forloop_offset: 2147450880 8.11817193031311 On 2.6/2.7, there's a massive penalty for switching to longs; on 3.2/3.3, the two for-loop versions are nearly identical in time. (Side point: I'm often seeing that 3.2 on Linux is marginally faster calling my range_sum function than doing the same thing inline. I do not understand this. If anyone can explain what's going on there, I'm all ears!) Python 3's int is faster than Python 2's long, but slower than Python 2's int. So the question really is, would a two-form representation be beneficial, and if so, is it worth the coding trouble? ChrisA From ethan at stoneleaf.us Mon Mar 25 19:16:05 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 25 Mar 2013 16:16:05 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: <5150DAB5.3060103@stoneleaf.us> On 03/25/2013 02:51 PM, Chris Angelico wrote: > Python 3's int is faster than Python 2's long, but slower than Python > 2's int. So the question really is, would a two-form representation be > beneficial, and if so, is it worth the coding trouble? I'm inclined to say it's not worth the trouble. If you're working with numbers, and speed is an issue, you really should be using one of the numeric or scientific packages out there. -- ~Ethan~ From cousinstanley at gmail.com Mon Mar 25 19:35:41 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Mon, 25 Mar 2013 23:35:41 +0000 (UTC) Subject: Performance of int/long in Python 3 References: Message-ID: Chris Angelico wrote: > The Python 3 merge of int and long has effectively penalized > small-number arithmetic by removing an optimization. > .... > The cost is clear. > .... The cost isn't quite as clear under Debian Wheezy here .... Stanley C. Kitching Debian Wheezy python inline range_sum forloop forloop_offset 2.7.3 3.1359 3.0725 9.0778 15.6475 3.2.3 2.8226 2.8074 13.47624 13.6430 # --------------------------------------------------------- Chris Angelico Debian Wheezy python inline range_sum forloop forloop_offset 2.7.3 1.9276 1.9341 5.1463 5.1346 3.2.3 2.8841 2.6586 7.6602 8.1182 -- Stanley C. Kitching Human Being Phoenix, Arizona From drsalists at gmail.com Mon Mar 25 20:12:10 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 25 Mar 2013 17:12:10 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On Mon, Mar 25, 2013 at 4:35 PM, Cousin Stanley wrote: > > Chris Angelico wrote: > > > The Python 3 merge of int and long has effectively penalized > > small-number arithmetic by removing an optimization. > > .... > > The cost is clear. > > .... > I thought I heard that Python 3.x will use machine words for small integers, and automatically coerce internally to a 2.x long as needed. Either way, it's better to have a small performance cost to avoid problems when computers move from 32 to 64 bit words, or 64 bit to 128 bit words. With 3.x int's, you don't have to worry about a new crop of CPU's breaking your code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Mar 26 02:26:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 17:26:31 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On Tue, Mar 26, 2013 at 10:35 AM, Cousin Stanley wrote: > > Chris Angelico wrote: > >> The Python 3 merge of int and long has effectively penalized >> small-number arithmetic by removing an optimization. >> .... >> The cost is clear. >> .... > > The cost isn't quite as clear > under Debian Wheezy here .... > > Stanley C. Kitching > Debian Wheezy > > python inline range_sum forloop forloop_offset > > 2.7.3 3.1359 3.0725 9.0778 15.6475 > > 3.2.3 2.8226 2.8074 13.47624 13.6430 Interesting, so your 3.x sum() is optimizing something somewhere. Strange. Are we both running the same Python? I got those from apt-get, aiming for consistency (rather than building a 3.3 from source). The cost is still visible in the for-loop versions, though, and you're still seeing the <2^31 and >2^31 for-loops behave the same way in 3.x but perform quite differently in 2.x. So it's looking like things are mostly the same. ChrisA From cousinstanley at gmail.com Tue Mar 26 09:38:39 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 26 Mar 2013 13:38:39 +0000 (UTC) Subject: Performance of int/long in Python 3 References: Message-ID: Chris Angelico wrote: > Interesting, so your 3.x sum() is optimizing something somewhere. > Strange. Are we both running the same Python ? > > I got those from apt-get > .... I also installed python here under Debian Wheezy via apt-get and our versions look to be the same .... -sk- 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] CPU : Intel(R) Celeron(R) D CPU 3.33GHz -ca- 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] CPU : ??? Could differences in underlying CPU architecture lead to our differing python integer results ? -- Stanley C. Kitching Human Being Phoenix, Arizona From rosuav at gmail.com Tue Mar 26 10:08:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 01:08:17 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 12:38 AM, Cousin Stanley wrote: > Chris Angelico wrote: > >> Interesting, so your 3.x sum() is optimizing something somewhere. >> Strange. Are we both running the same Python ? >> >> I got those from apt-get >> .... > > I also installed python here under Debian Wheezy > via apt-get and our versions look to be the same .... > > -sk- > > 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] > > 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] > > CPU : Intel(R) Celeron(R) D CPU 3.33GHz > > > -ca- > > 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] > > 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] > > CPU : ??? > > > Could differences in underlying CPU architecture > lead to our differing python integer results ? Doubtful. I have Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz quad-core with hyperthreading, but I'm only using one core for this job. I've run the tests several times and each time, Py2 is a shade under two seconds for inline/range_sum, and Py3 is about 2.5 seconds for each. Fascinating. Just for curiosity's sake, I spun up the tests on my reiplophobic server, still running Ubuntu Karmic. Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. gideon at gideon:~$ python inttime.py 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] inline: 2147450880 2.7050409317 range_sum: 2147450880 2.64918494225 forloop: 2147450880 6.58765792847 forloop_offset: 2147450880L 16.5167789459 gideon at gideon:~$ python3 inttime.py 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22) [GCC 4.4.1] inline: 2147450880 4.44533085823 range_sum: 2147450880 4.37314105034 forloop: 2147450880 12.4834370613 forloop_offset: 2147450880 13.5000522137 Once again, Py3 is slower on small integers than Py2. So where's the difference with your system? This is really weird! I assume you can repeat the tests and get the same result every time? ChrisA From cousinstanley at gmail.com Tue Mar 26 12:41:13 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 26 Mar 2013 16:41:13 +0000 (UTC) Subject: Performance of int/long in Python 3 References: Message-ID: Chris Angelico wrote: > Once again, Py3 is slower on small integers than Py2. Chris Angelico Ubuntu Karmic. Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. python inline range_sum forloop forloop_offset 2.6.4 2.7050 2.6492 6.5877 16.5168 3.1.1 4.4453 4.3731 12.4834 13.5001 You do seem to have a slight py3 improvement under ubuntu for the forloop_offset case .... > So where's the difference with your system ? CPU ???? > This is really weird ! Yep ... > I assume you can repeat the tests > and get the same result every time ? Yes .... First lines of numbers below are from yesterday while second lines are from today .... Stanley C. Kitching Debian Wheezy Intel(R) Celeron(R) D CPU 3.33GH Single Core python inline range_sum forloop forloop_offset 2.7.3 3.1359 3.0725 9.0778 15.6475 2.7.3 3.0382 3.1452 9.8799 16.8579 3.2.3 2.8226 2.8074 13.47624 13.6430 3.2.3 2.8331 2.8228 13.54151 13.8716 -- Stanley C. Kitching Human Being Phoenix, Arizona From rosuav at gmail.com Tue Mar 26 12:54:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 03:54:47 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 3:41 AM, Cousin Stanley wrote: > > Chris Angelico wrote: > >> Once again, Py3 is slower on small integers than Py2. > > Chris Angelico > Ubuntu Karmic. > Pentium(R) Dual-Core CPU E6500 @ 2.93GHz. > > python inline range_sum forloop forloop_offset > > 2.6.4 2.7050 2.6492 6.5877 16.5168 > > 3.1.1 4.4453 4.3731 12.4834 13.5001 > > You do seem to have a slight py3 improvement > under ubuntu for the forloop_offset case .... Yes, that's correct. The forloop_offset one is using long integers in all cases. (Well, on Py2 it's adding a series of ints to a long, but the arithmetic always has to be done with longs.) Python 3 has had some improvements done, but the main thing is that there's a massive spike in the Py2 time, while Py3 has _already paid_ that cost - as evidenced by the closeness of the forloop and forloop_offset times on Py3. ChrisA From tjreedy at udel.edu Tue Mar 26 14:24:34 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Mar 2013 14:24:34 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On 3/26/2013 12:41 PM, Cousin Stanley wrote: >> So where's the difference with your system ? > > CPU ???? Compilers and compiler settings can also make a difference. -- Terry Jan Reedy From wxjmfauth at gmail.com Tue Mar 26 14:50:14 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 26 Mar 2013 11:50:14 -0700 (PDT) Subject: Performance of int/long in Python 3 References: Message-ID: On 25 mar, 22:51, Chris Angelico wrote: > The Python 3 merge of int and long has effectively penalized > small-number arithmetic by removing an optimization. As we've seen > from PEP 393 strings (jmf aside), there can be huge benefits from > having a single type with multiple representations internally ... ------ A character is not an integer (short form). jmf From rosuav at gmail.com Tue Mar 26 15:03:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 06:03:01 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wrote: > On 25 mar, 22:51, Chris Angelico wrote: >> The Python 3 merge of int and long has effectively penalized >> small-number arithmetic by removing an optimization. As we've seen >> from PEP 393 strings (jmf aside), there can be huge benefits from >> having a single type with multiple representations internally ... > > ------ > > A character is not an integer (short form). So? ChrisA From wxjmfauth at gmail.com Tue Mar 26 16:44:01 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 26 Mar 2013 13:44:01 -0700 (PDT) Subject: Performance of int/long in Python 3 References: Message-ID: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> On 26 mar, 20:03, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wrote: > > On 25 mar, 22:51, Chris Angelico wrote: > >> The Python 3 merge of int and long has effectively penalized > >> small-number arithmetic by removing an optimization. As we've seen > >> from PEP 393 strings (jmf aside), there can be huge benefits from > >> having a single type with multiple representations internally ... > > > ------ > > > A character is not an integer (short form). > > So? > > ChrisA A character is not an integer. jmf From breamoreboy at yahoo.co.uk Tue Mar 26 16:50:28 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 26 Mar 2013 20:50:28 +0000 Subject: Performance of int/long in Python 3 In-Reply-To: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On 26/03/2013 20:44, jmfauth wrote: > On 26 mar, 20:03, Chris Angelico wrote: >> On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wrote: >>> On 25 mar, 22:51, Chris Angelico wrote: >>>> The Python 3 merge of int and long has effectively penalized >>>> small-number arithmetic by removing an optimization. As we've seen >>>> from PEP 393 strings (jmf aside), there can be huge benefits from >>>> having a single type with multiple representations internally ... >> >>> ------ >> >>> A character is not an integer (short form). >> >> So? >> >> ChrisA > > A character is not an integer. > > jmf > But you are an idiot. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From nad at acm.org Tue Mar 26 20:00:43 2013 From: nad at acm.org (Ned Deily) Date: Tue, 26 Mar 2013 17:00:43 -0700 Subject: Performance of int/long in Python 3 References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > But you are an idiot. I repeat the friendly reminder I posted a few weeks ago and I'll be a little less oblique: please avoid gratuitous personal attacks here. It reflects badly on the group and especially on those people making them. We can disagree strongly about technical opinions without resorting to such. On Mon, 11 Mar 2013 11:13:16 -0700, I posted: > A friendly reminder that this forum is for general discussion and > questions about Python. > > "Pretty much anything Python-related is fair game for discussion, and > the group is even fairly tolerant of off-topic digressions; there have > been entertaining discussions of topics such as floating point, good > software design, and other programming languages such as Lisp and Forth." > > But ... > > "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." > > http://www.python.org/community/lists/ > > It's up to all of us to help keep this group/list a place where people > enjoy participating, without fear of gratuitous personal sniping. > Thanks! -- Ned Deily, nad at acm.org From breamoreboy at yahoo.co.uk Tue Mar 26 20:20:14 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 27 Mar 2013 00:20:14 +0000 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On 27/03/2013 00:00, Ned Deily wrote: > In article , > Mark Lawrence wrote: >> But you are an idiot. > > I repeat the friendly reminder I posted a few weeks ago and I'll be a > little less oblique: please avoid gratuitous personal attacks here. It > reflects badly on the group and especially on those people making them. > We can disagree strongly about technical opinions without resorting to > such. > > On Mon, 11 Mar 2013 11:13:16 -0700, I posted: >> A friendly reminder that this forum is for general discussion and >> questions about Python. >> >> "Pretty much anything Python-related is fair game for discussion, and >> the group is even fairly tolerant of off-topic digressions; there have >> been entertaining discussions of topics such as floating point, good >> software design, and other programming languages such as Lisp and Forth." >> >> But ... >> >> "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." >> >> http://www.python.org/community/lists/ >> >> It's up to all of us to help keep this group/list a place where people >> enjoy participating, without fear of gratuitous personal sniping. >> Thanks! > I suggest you spend more time telling the troll that he's a troll and less time moaning at me. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From nad at acm.org Tue Mar 26 21:31:50 2013 From: nad at acm.org (Ned Deily) Date: Tue, 26 Mar 2013 18:31:50 -0700 Subject: Performance of int/long in Python 3 References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > On 27/03/2013 00:00, Ned Deily wrote: [...] > > I repeat the friendly reminder I posted a few weeks ago and I'll be a > > little less oblique: please avoid gratuitous personal attacks here. It > > reflects badly on the group and especially on those people making them. > > We can disagree strongly about technical opinions without resorting to > > such. > > > > On Mon, 11 Mar 2013 11:13:16 -0700, I posted: > >> A friendly reminder that this forum is for general discussion and > >> questions about Python. > >> > >> "Pretty much anything Python-related is fair game for discussion, and > >> the group is even fairly tolerant of off-topic digressions; there have > >> been entertaining discussions of topics such as floating point, good > >> software design, and other programming languages such as Lisp and Forth." > >> > >> But ... > >> > >> "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." > >> > >> http://www.python.org/community/lists/ > >> > >> It's up to all of us to help keep this group/list a place where people > >> enjoy participating, without fear of gratuitous personal sniping. > >> Thanks! > I suggest you spend more time telling the troll that he's a troll and > less time moaning at me. I suggest you re-read the group charter. He may be saying things that most of us disagree with but he does it without personal attacks. He's made his position clear and it doesn't seem likely to change. Ignoring, plonking, or polite responses are all fine responses. Flaming is not. That's not the kind of group most of us want to see. -- Ned Deily, nad at acm.org From breamoreboy at yahoo.co.uk Wed Mar 27 07:51:07 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 27 Mar 2013 11:51:07 +0000 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On 27/03/2013 01:31, Ned Deily wrote: > In article , > Mark Lawrence wrote: >> On 27/03/2013 00:00, Ned Deily wrote: > [...] >>> I repeat the friendly reminder I posted a few weeks ago and I'll be a >>> little less oblique: please avoid gratuitous personal attacks here. It >>> reflects badly on the group and especially on those people making them. >>> We can disagree strongly about technical opinions without resorting to >>> such. >>> >>> On Mon, 11 Mar 2013 11:13:16 -0700, I posted: >>>> A friendly reminder that this forum is for general discussion and >>>> questions about Python. >>>> >>>> "Pretty much anything Python-related is fair game for discussion, and >>>> the group is even fairly tolerant of off-topic digressions; there have >>>> been entertaining discussions of topics such as floating point, good >>>> software design, and other programming languages such as Lisp and Forth." >>>> >>>> But ... >>>> >>>> "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." >>>> >>>> http://www.python.org/community/lists/ >>>> >>>> It's up to all of us to help keep this group/list a place where people >>>> enjoy participating, without fear of gratuitous personal sniping. >>>> Thanks! >> I suggest you spend more time telling the troll that he's a troll and >> less time moaning at me. > > I suggest you re-read the group charter. He may be saying things that > most of us disagree with but he does it without personal attacks. He's > made his position clear and it doesn't seem likely to change. Ignoring, > plonking, or polite responses are all fine responses. Flaming is not. > That's not the kind of group most of us want to see. > He's not going to change so neither am I. I also suggest you go and moan at Steven D'Aprano who called the idiot a liar. Although thinking about it, I prefer Steven's comment to my own as being more accurate. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Wed Mar 27 21:47:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 01:47:25 GMT Subject: Performance of int/long in Python 3 References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 11:51:07 +0000, Mark Lawrence defending an unproductive post flaming a troll: > He's not going to change so neither am I. "He's a troll disrupting the newsgroup, therefore I'm going to be a troll disrupting the newsgroup too, so nyah!!!" > I also suggest you go and moan at Steven D'Aprano who called the idiot a > liar. Although thinking about it, I prefer Steven's comment to my own > as being more accurate. Yes I did, I suggest you reflect on the difference in content between your post and mine, and why yours can be described as abusive flaming and mine shouldn't be. -- Steven From ethan at stoneleaf.us Wed Mar 27 23:18:36 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Mar 2013 20:18:36 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5153B68C.1080106@stoneleaf.us> On 03/27/2013 06:47 PM, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 11:51:07 +0000, Mark Lawrence defending an > unproductive post flaming a troll: I wouldn't call it unproductive -- a half-dozen amusing posts followed because of Mark's initial post, and they were a great relief from the tedium and (dare I say it?) idiocy of jmf's posts. >> He's not going to change so neither am I. > > "He's a troll disrupting the newsgroup, therefore I'm going to be a troll > disrupting the newsgroup too, so nyah!!!" So long as Mark doesn't start cussing and swearing I'm not going to get worked up about it. I find jmf's posts for more aggravating. >> I also suggest you go and moan at Steven D'Aprano who called the idiot a >> liar. Although thinking about it, I prefer Steven's comment to my own >> as being more accurate. > > Yes I did, I suggest you reflect on the difference in content between > your post and mine, and why yours can be described as abusive flaming and > mine shouldn't be. Mark's post was not, in my not-so-humble opinion, abusive. jmf's (again IMNSHO) was. Your post (Steven's) was possibly more accurate, but Mark's was more amusing, and generated more amusing responses. Clearly, jmf is not going to change his thread-hijacking unicode-whining behavior, whether faced with the cold rational responses or the hotter fed-up responses. So I guess what I'm saying is: Don't Feed The Trolls (Anyone!) ;) Of course, somebody still has to reply so a newcomer doesn't get taken in by him. Has anybody else thought that his last few responses are starting to sound bot'ish? -- ~Ethan~ From rosuav at gmail.com Wed Mar 27 23:40:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 14:40:17 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5153B68C.1080106@stoneleaf.us> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153B68C.1080106@stoneleaf.us> Message-ID: On Thu, Mar 28, 2013 at 2:18 PM, Ethan Furman wrote: > Has anybody else thought that [jmf's] last few responses are starting to sound > bot'ish? Yes, I did wonder. It's like he and Dihedral have been trading accounts sometimes. Hey, Dihedral, I hear there's a discussion of Unicode and PEP 393 and Python 3.3 and Unicode and lots of keywords for you to trigger on and Python and bots are funny and this text is almost grammatical! There. Let's see if he takes the bait. ChrisA From breamoreboy at yahoo.co.uk Thu Mar 28 08:39:35 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 28 Mar 2013 12:39:35 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5153B68C.1080106@stoneleaf.us> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153B68C.1080106@stoneleaf.us> Message-ID: On 28/03/2013 03:18, Ethan Furman wrote: > > I wouldn't call it unproductive -- a half-dozen amusing posts followed > because of Mark's initial post, and they were a great relief from the > tedium and (dare I say it?) idiocy of jmf's posts. > > -- > ~Ethan~ Thanks for those words. They're a tonic as I've just clawed my way out of bed at 12:00 GMT having slept for 15 hours. Once the PEP393 unicode debacle has been sorted, does anyone have a cure for Chronic Fatigue Syndrome? :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From dihedral88888 at googlemail.com Thu Mar 28 19:04:10 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 28 Mar 2013 16:04:10 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153B68C.1080106@stoneleaf.us> Message-ID: <6140bbdc-03c3-49d6-a8f8-d18cd802bcdd@googlegroups.com> Chris Angelico? 2013?3?28????UTC+8??11?40?17???? > On Thu, Mar 28, 2013 at 2:18 PM, Ethan Furman wrote: > > > Has anybody else thought that [jmf's] last few responses are starting to sound > > > bot'ish? > > > > Yes, I did wonder. It's like he and Dihedral have been trading > > accounts sometimes. Hey, Dihedral, I hear there's a discussion of > > Unicode and PEP 393 and Python 3.3 and Unicode and lots of keywords > > for you to trigger on and Python and bots are funny and this text is > > almost grammatical! > > > > There. Let's see if he takes the bait. > > > > ChrisA Well, we need some cheap ram to hold 4 bytes per character in a text segment to be observed. For those not to be observed or shown, the old way still works. Windows got this job done right to collect taxes in areas of different languages. From dihedral88888 at googlemail.com Thu Mar 28 19:04:10 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 28 Mar 2013 16:04:10 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153B68C.1080106@stoneleaf.us> Message-ID: <6140bbdc-03c3-49d6-a8f8-d18cd802bcdd@googlegroups.com> Chris Angelico? 2013?3?28????UTC+8??11?40?17???? > On Thu, Mar 28, 2013 at 2:18 PM, Ethan Furman wrote: > > > Has anybody else thought that [jmf's] last few responses are starting to sound > > > bot'ish? > > > > Yes, I did wonder. It's like he and Dihedral have been trading > > accounts sometimes. Hey, Dihedral, I hear there's a discussion of > > Unicode and PEP 393 and Python 3.3 and Unicode and lots of keywords > > for you to trigger on and Python and bots are funny and this text is > > almost grammatical! > > > > There. Let's see if he takes the bait. > > > > ChrisA Well, we need some cheap ram to hold 4 bytes per character in a text segment to be observed. For those not to be observed or shown, the old way still works. Windows got this job done right to collect taxes in areas of different languages. From rustompmody at gmail.com Wed Mar 27 23:49:20 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Mar 2013 20:49:20 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 28, 8:18?am, Ethan Furman wrote: > > So long as Mark doesn't start cussing and swearing I'm not going to get worked up about it. ?I > find jmf's posts for more aggravating. I support Ned's original gentle reminder -- Please be civil irrespective of surrounding nonsensical behavior. In particular "You are a liar" is as bad as "You are an idiot" The same statement can be made non-abusively thus: "... is not true because ..." From steve+comp.lang.python at pearwood.info Thu Mar 28 01:20:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 05:20:19 GMT Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 20:49:20 -0700, rusi wrote: > On Mar 28, 8:18?am, Ethan Furman wrote: >> >> So long as Mark doesn't start cussing and swearing I'm not going to get >> worked up about it. ?I find jmf's posts for more aggravating. > > I support Ned's original gentle reminder -- Please be civil irrespective > of surrounding nonsensical behavior. > > In particular "You are a liar" is as bad as "You are an idiot" The same > statement can be made non-abusively thus: "... is not true because ..." I accept that criticism, even if I disagree with it. Does that make sense? I mean it in the sense that I accept that your opinion differs from mine. Politeness does not always trump honesty, and stating that somebody's statement "is not true because..." is not the same as stating that they are deliberately telling lies (rather than merely being mistaken or confused). The world is full of people who deliberately and in complete awareness of what they are doing lie in order to further their agenda, or for profit, or to feel good about themselves, or to harm others. There comes a time where politely ignoring the elephant in the room (the dirty, rotten, lying scoundrel of an elephant) and giving them the benefit of the doubt simply makes life worse for everyone except the liars. We all know this. Unless you've been living in a cave on the top of some mountain, we all know people whose relationship to the truth is, shall we say, rather bendy. And yet we collectively muddy the water and inject uncertainty into debate by politely going along with their lies, or at least treating them with dignity that they don't deserve, by treating them as at worst a matter of honest misunderstanding or even mere difference of opinion. As an Australian, I am constitutionally required to call a spade a bloody shovel at least twice a week, so I have no regrets. -- Steven From rustompmody at gmail.com Thu Mar 28 01:42:18 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Mar 2013 22:42:18 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> On Mar 28, 10:20?am, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 20:49:20 -0700, rusi wrote: > > On Mar 28, 8:18?am, Ethan Furman wrote: > > >> So long as Mark doesn't start cussing and swearing I'm not going to get > >> worked up about it. ?I find jmf's posts for more aggravating. > > > I support Ned's original gentle reminder -- Please be civil irrespective > > of surrounding nonsensical behavior. > > > In particular "You are a liar" is as bad as "You are an idiot" The same > > statement can be made non-abusively thus: "... is not true because ..." > > I accept that criticism, even if I disagree with it. Does that make > sense? I mean it in the sense that I accept that your opinion differs > from mine. > > Politeness does not always trump honesty, and stating that somebody's > statement "is not true because..." is not the same as stating that they > are deliberately telling lies (rather than merely being mistaken or > confused). > > The world is full of people who deliberately and in complete awareness of > what they are doing lie in order to further their agenda, or for profit, > or to feel good about themselves, or to harm others. There comes a time > where politely ignoring the elephant in the room (the dirty, rotten, > lying scoundrel of an elephant) and giving them the benefit of the doubt > simply makes life worse for everyone except the liars. We all subscribe to legal systems that decide the undecidable; eg. A pulled out a gun and killed B. Was it murder, manslaughter, just a mistake, euthanasia? Any lawyer with experience knows that horrible mistakes happen in making these decisions; yet they (the judges) need to make them. For the purposes of the python list these ascriptions to personal motives are OT enough to be out of place. > > We all know this. Unless you've been living in a cave on the top of some > mountain, we all know people whose relationship to the truth is, shall we > say, rather bendy. And yet we collectively muddy the water and inject > uncertainty into debate by politely going along with their lies, or at > least treating them with dignity that they don't deserve, by treating > them as at worst a matter of honest misunderstanding or even mere > difference of opinion. > > As an Australian, I am constitutionally required to call a spade a bloody > shovel at least twice a week, so I have no regrets. If someone has got physically injured by the spade then its a bloody spade; else you are a bloody liar :-) Well? More seriously Ive never seen anyone -- cause or person -- aided by the use of excessively strong language. IOW I repeat my support for Ned's request: Ad hominiem attacks are not welcome, irrespective of the context/provocation. From steve+comp.lang.python at pearwood.info Thu Mar 28 03:48:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 07:48:30 GMT Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> Message-ID: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 22:42:18 -0700, rusi wrote: > More seriously Ive never seen anyone -- cause or person -- aided by > the use of excessively strong language. Of course not. By definition, if it helps, it wasn't *excessively* strong language. > IOW I repeat my support for Ned's request: Ad hominiem attacks are not > welcome, irrespective of the context/provocation. Insults are not ad hominem attacks. "You sir, are a bounder and a cad. Furthermore, your argument is wrong, because of reasons." may very well be an insult, but it also may be correct, and the reasons logically valid. "Your argument is wrong, because you are a bounder and a cad." is an ad hominem fallacy, because even bounders and cads may tell the truth occasionally, or be correct by accident. I find it interesting that nobody has yet felt the need to defend JMF, and tell me I was factually incorrect about him (as opposed to merely impolite or mean-spirited). In any case, I don't want this to be specifically about any one person, so let's move away from JMF. I disagree that hostile language is *always* inappropriate, although I agree that it is *usually* inappropriate. Although even that depends on what you define as "hostile" -- I would much prefer that people confronted me for being (supposedly) dishonest than silently shunning me without giving me any way to respond or correct either my behaviour or their (mis)apprehensions. Quite frankly, I think that the passive-aggressive silent treatment (kill-filing) is MUCH more hostile and mean-spirited[1] than honest, respectful, direct criticism, even when that criticism is about character ("you sir are a lying scoundrel"). I treat people the way I hope to be treated. As galling as it would be to be accused of lying, I would rather that you called me a liar to my face and gave me the opportunity to respond, than for you to ignore everything I said. I hope that we all agree that we want a nice, friendly, productive community where everyone is welcome. But some people simply cannot or will not behave in ways that are compatible with those community values. There are some people whom we *do not want here* -- spoilers and messers, vandals and spammers and cheats and liars and trolls and crackpots of all sorts. We only disagree as to the best way to make it clear to them that they are not welcome so long as they continue their behaviour. [1] Although sadly, given the reality of communication on the Internet, sometimes kill-filing is the least-worst option. -- Steven From rurpy at yahoo.com Thu Mar 28 15:54:20 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 28 Mar 2013 12:54:20 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/28/2013 01:48 AM, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 22:42:18 -0700, rusi wrote: >> More seriously Ive never seen anyone -- cause or person -- aided by >> the use of excessively strong language. > > Of course not. By definition, if it helps, it wasn't *excessively* strong > language. For someone who delights in pointing out the logical errors of others you are often remarkably sloppy in your own logic. Of course language can be both helpful and excessively strong. That is the case when language less strong would be equally or more helpful. >> IOW I repeat my support for Ned's request: Ad hominiem attacks are not >> welcome, irrespective of the context/provocation. > > Insults are not ad hominem attacks. Insults may or may not be ad hominem attacks. There is nothing mutually exclusive about those terms. > "You sir, are a bounder and a cad. Furthermore, your > argument is wrong, because of reasons." > > may very well be an insult, but it also may be correct, and the reasons > logically valid. Those are two different statements. The first is an ad hominem attack and is not welcome here. The second is an acceptable response. > "Your argument is wrong, because you are a bounder > and a cad." > > is an ad hominem fallacy, because even bounders and cads may tell the > truth occasionally, or be correct by accident. That it is a fallacy does not mean it is not also an attack. > I find it interesting that nobody has yet felt the need to defend JMF, > and tell me I was factually incorrect about him (as opposed to merely > impolite or mean-spirited). Nothing "interesting" about it at all. Most of us (perhaps unlike you) are not interested in discussing the personal characteristics of posters here (in contrast to discussing the technical opinions they post). Further, "liar" is both so non-objective and so pejoratively emotive that it is a word much more likely to be used by someone interested in trolling than in a serious discussion, so most sensible people here likely would not bite. >[...] > I would rather that you called me a liar to my face > and gave me the opportunity to respond, than for you to ignore everything > I said. Even if you personally would prefer someone to respond by calling you a liar, your personal preferences do not form a basis for desirable posting behavior here. But again you're creating a false dichotomy. Those are not the only two choices. A third choice is neither ignore you nor call you a liar but to factually point out where you are wrong, or (if it is a matter of opinion) why one holds a different opinion. That was the point Ned Deily was making I believe. > I hope that we all agree that we want a nice, friendly, productive > community where everyone is welcome. I hope so too but it is likely that some people want a place to develop and assert some sense of influence, engage in verbal duels, instigate arguments, etc. That can be true of regulars here as well as drive-by posters. > But some people simply cannot or > will not behave in ways that are compatible with those community values. > There are some people whom we *do not want here* In other words, everyone is NOT welcome. > -- spoilers and messers, > vandals and spammers and cheats and liars and trolls and crackpots of all > sorts. Where those terms are defined by you and a handful of other voracious posters. "Troll" in particular is often used to mean someone who disagrees with the borg mind here, or who says anything negative about Python, or who due attitude or lack of full English fluency do not express themselves in a sufficiently submissive way. > We only disagree as to the best way to make it clear to them that > they are not welcome so long as they continue their behaviour. No, we disagree on who fits those definitions and even how tolerant we are to those who do fit the definitions. The policing that you and a handful of other self-appointed net-cops try to do is far more obnoxious that the original posts are. > [1] Although sadly, given the reality of communication on the Internet, > sometimes kill-filing is the least-worst option. Please, please, killfile jmfauth, ranting rick, xaw lee and anyone else you don't like so that the rest of us can be spared the orders of magnitude larger, more disruptive and more offensive posts generated by your (plural) responses to them. Believe or not, most of the rest of us here are smart enough to form our own opinions of such posters without you and the other c.l.p truthsquad members telling us what to think. From ethan at stoneleaf.us Thu Mar 28 16:31:56 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Mar 2013 13:31:56 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5154A8BC.9050607@stoneleaf.us> On 03/28/2013 12:54 PM, rurpy at yahoo.com wrote: > On 03/28/2013 01:48 AM, Steven D'Aprano wrote: >> On Wed, 27 Mar 2013 22:42:18 -0700, rusi wrote: > For someone who delights in pointing out the logical errors > of others you are often remarkably sloppy in your own logic. > > Of course language can be both helpful and excessively strong. > That is the case when language less strong would be > equally or more helpful. It can also be the case when language less strong would be useless. > Further, "liar" is both so non-objective and so pejoratively > emotive that it is a word much more likely to be used by > someone interested in trolling than in a serious discussion, > so most sensible people here likely would not bite. Non-objective? If today poster B says X, and tomorrow poster B says s/he was unaware of X until just now, is not "liar" a reasonable conclusion? >> I hope that we all agree that we want a nice, friendly, productive >> community where everyone is welcome. > > I hope so too but it is likely that some people want a place > to develop and assert some sense of influence, engage in verbal > duels, instigate arguments, etc. That can be true of regulars > here as well as drive-by posters. > >> But some people simply cannot or >> will not behave in ways that are compatible with those community values. >> There are some people whom we *do not want here* > > In other words, everyone is NOT welcome. Correct. Do you not agree? >> -- spoilers and messers, >> vandals and spammers and cheats and liars and trolls and crackpots of all >> sorts. > > Where those terms are defined by you and a handful of other > voracious posters. "Troll" in particular is often used to > mean someone who disagrees with the borg mind here, or who > says anything negative about Python, or who due attitude or > lack of full English fluency do not express themselves in > a sufficiently submissive way. I cannot speak for the borg mind, but for myself a troll is anyone who continually posts rants (such as RR & XL) or who continuously hijacks threads to talk about their pet peeve (such as jmf). >> We only disagree as to the best way to make it clear to them that >> they are not welcome so long as they continue their behaviour. > > No, we disagree on who fits those definitions and even > how tolerant we are to those who do fit the definitions. > The policing that you and a handful of other self-appointed > net-cops try to do is far more obnoxious that the original > posts are. I completely disagree, and I am grateful to those who bother to take the time to continually point out the errors from those posters and to warn newcomers that those posters should not be believed. > Believe or not, most of the rest of us here are smart enough to > form our own opinions of such posters without you and the other > c.l.p truthsquad members telling us what to think. If one of my first few posts on c.l.p netted a response from a troll I would greatly appreciate a reply from one of the regulars saying that was a troll so I didn't waste time trying to use whatever they said, or be concerned that the language I was trying to use and learn was horribly flawed. If the "truthsquad" posts are so offensive to you, why don't you kill-file them? -- ~Ethan~ From steve+comp.lang.python at pearwood.info Thu Mar 28 20:35:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 00:35:23 GMT Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5154e1cb$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 12:54:20 -0700, rurpy wrote: > Even if you personally would prefer someone to respond by calling you a > liar, your personal preferences do not form a basis for desirable > posting behavior here. Whereas yours apparently are. Thanks for the feedback, I'll take it under advisement. -- Steven From invalid at invalid.invalid Fri Mar 29 10:52:40 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 29 Mar 2013 14:52:40 +0000 (UTC) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-03-28, Ethan Furman wrote: > I cannot speak for the borg mind, but for myself a troll is anyone > who continually posts rants (such as RR & XL) or who continuously > hijacks threads to talk about their pet peeve (such as jmf). Assuming jmf actually does care deeply and genuinely about Unicode implementations, and his postings reflect his actual position/opinion, then he's not a troll. Traditionally, a troll is someone who posts statements purely to provoke a response -- they don't really care about the topic and often don't believe what they're posting. -- Grant Edwards grant.b.edwards Yow! BARBARA STANWYCK makes at me nervous!! gmail.com From ethan at stoneleaf.us Fri Mar 29 11:51:30 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Mar 2013 08:51:30 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5155B882.3040400@stoneleaf.us> On 03/29/2013 07:52 AM, Grant Edwards wrote: > On 2013-03-28, Ethan Furman wrote: > >> I cannot speak for the borg mind, but for myself a troll is anyone >> who continually posts rants (such as RR & XL) or who continuously >> hijacks threads to talk about their pet peeve (such as jmf). > > Assuming jmf actually does care deeply and genuinely about Unicode > implementations, and his postings reflect his actual position/opinion, > then he's not a troll. Traditionally, a troll is someone who posts > statements purely to provoke a response -- they don't really care > about the topic and often don't believe what they're posting. Even if he does care deeply and genuinely he still hijacks threads, still refuses the challenges to try X or Y and report back, and (ISTM) still refuses to learn. If that's not trollish behavior, what is it? FWIW I don't think he does care deeply and genuinely (at least not genuinely) or he would do more than whine about micro benchmarks and make sweeping statements like "nobody here understands unicode" (paraphrased). -- ~Ethan~ From invalid at invalid.invalid Fri Mar 29 12:50:18 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 29 Mar 2013 16:50:18 +0000 (UTC) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-03-29, Ethan Furman wrote: > On 03/29/2013 07:52 AM, Grant Edwards wrote: >> On 2013-03-28, Ethan Furman wrote: >> >>> I cannot speak for the borg mind, but for myself a troll is anyone >>> who continually posts rants (such as RR & XL) or who continuously >>> hijacks threads to talk about their pet peeve (such as jmf). >> >> Assuming jmf actually does care deeply and genuinely about Unicode >> implementations, and his postings reflect his actual >> position/opinion, then he's not a troll. Traditionally, a troll is >> someone who posts statements purely to provoke a response -- they >> don't really care about the topic and often don't believe what >> they're posting. > > Even if he does care deeply and genuinely he still hijacks threads, > still refuses the challenges to try X or Y and report back, and > (ISTM) still refuses to learn. > > If that's not trollish behavior, what is it? He might indeed be trolling. But what defines a troll is motive/intent, not behavior. Those behaviors are all common in non-troll net.kooks. Maybe I'm being a bit too "old-school Usenet", but being rude, ignorant (even stubbornly so), wrong, or irrational doesn't make you a troll. What makes you a troll is intent. If you don't actually care about the topic but are posting because you enjoy poking people with a stick to watch them jump and howl, then you're a troll. > FWIW I don't think he does care deeply and genuinely (at least not > genuinely) or he would do more than whine about micro benchmarks and > make sweeping statements like "nobody here understands unicode" > (paraphrased). Perhaps he doesn't care about Unicode or Python performance. If so he's putting on a pretty good act -- if he's a troll, he's a good one and he's running a long game. Personally, I don't think he's a troll. I think he's obsessed with what he percieves as an issue with Python's string implementation. IOW, if he's a troll, he's got me fooled. -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From rurpy at yahoo.com Fri Mar 29 17:26:24 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 29 Mar 2013 14:26:24 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> On 03/28/2013 02:31 PM, Ethan Furman wrote: > On 03/28/2013 12:54 PM, rurpy at yahoo.com wrote: >> On 03/28/2013 01:48 AM, Steven D'Aprano wrote: >> For someone who delights in pointing out the logical errors of >> others you are often remarkably sloppy in your own logic. >> >> Of course language can be both helpful and excessively strong. That >> is the case when language less strong would be equally or more >> helpful. > > It can also be the case when language less strong would be useless. I don't get your point. I was pointing out the fallacy in Steven's logic (which you cut). How is your statement relevant to that? >> Further, "liar" is both so non-objective and so pejoratively >> emotive that it is a word much more likely to be used by someone >> interested in trolling than in a serious discussion, so most >> sensible people here likely would not bite. > > Non-objective? If today poster B says X, and tomorrow poster B says > s/he was unaware of X until just now, is not "liar" a reasonable > conclusion? Of course not. People forget what they posted previously, change their mind, don't express what they intended perfectly, sometimes express a complex thought that the reader inaccurately perceives as contradictory, don't realize themselves that their thinking is contradictory, ... And of course who among us *not* a "liar" since we all lie from time to time. Lying involves intent to deceive. I haven't been following jmfauth's claims since they are not of interest to me, but going back and quickly looking at the posts that triggered the "liar" and "idiot" posts, I did not see anything that made me think that jmfauth was not sincere in his beliefs. Being wrong and being sincere are not exclusive. Nor did Steven even try to justify the "liar" claim. As to Mark Lawrence, that seemed like a pure "I don't like you" insult whose proper place is /dev/null. Even if the odds are 80% that the person is lying, why risk your own credibility by making a nearly impossible to substantiate claim? Someone may praise some company's product constantly online and be discovered to be a salesperson at that company. Most of the time you would be right to accuse the person of dishonesty. But I knew a person who was very young and naive, who really believed in the product and truly didn't see anything wrong in doing that. That doesn't make it good behavior but those who claimed he was hiding his identity for personal gain were wrong (at least as far as I could tell, knowing the person personally.) Just post the facts and let people draw their own conclusions; that's better than making aggressive and offensive claims than can never be proven. Calling people liars or idiots not only damages the reputation of the Python community in general [*1] but hurts your own credibility as well, since any sensible reader will wonder if other opinions you post are more influenced by your emotions than by your intelligence. >>> I hope that we all agree that we want a nice, friendly, >>> productive community where everyone is welcome. >> >> I hope so too but it is likely that some people want a place to >> develop and assert some sense of influence, engage in verbal duels, >> instigate arguments, etc. That can be true of regulars here as >> well as drive-by posters. >> >>> But some people simply cannot or will not behave in ways that are >>> compatible with those community values. There are some people >>> whom we *do not want here* >> >> In other words, everyone is NOT welcome. > > Correct. Do you not agree? Don't ask me, ask Steven. He was the one who wrote two sentences earlier, "...we want a...community where everyone is welcome." I'll snip the rest of your post because it is your opinions and I've already said why I disagree. Most people are smart enough to make their own evaluations of posters here and if they are not, and reject python based on what they read from a single poster who obviously has "strong" views, then perhaps that's for the best. That possibility (which I think is very close to zero) is a tiny price to pay to avoid all the hostility and noise. ---- [*1] See for example the blog post at http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-and-you-should-feel-bad/ which was recently discussed in this list and in which the author wrote, "the community around Python is one of the most hostile and unhelpful communities around any programming-related topic that I have ever seen". From ethan at stoneleaf.us Fri Mar 29 19:07:21 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Mar 2013 16:07:21 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> Message-ID: <51561EA9.3020301@stoneleaf.us> On 03/29/2013 02:26 PM, rurpy at yahoo.com wrote: > On 03/28/2013 02:31 PM, Ethan Furman wrote: >> On 03/28/2013 12:54 PM, rurpy at yahoo.com wrote: >>> On 03/28/2013 01:48 AM, Steven D'Aprano wrote: >>> For someone who delights in pointing out the logical errors of >>> others you are often remarkably sloppy in your own logic. >>> >>> Of course language can be both helpful and excessively strong. That >>> is the case when language less strong would be equally or more >>> helpful. >> >> It can also be the case when language less strong would be useless. > > I don't get your point. > I was pointing out the fallacy in Steven's logic (which you cut). > How is your statement relevant to that? Ah. I thought you were saying that in all cases helpful strong language would be even more helpful if less strong. >>> Further, "liar" is both so non-objective and so pejoratively >>> emotive that it is a word much more likely to be used by someone >>> interested in trolling than in a serious discussion, so most >>> sensible people here likely would not bite. >> >> Non-objective? If today poster B says X, and tomorrow poster B says >> s/he was unaware of X until just now, is not "liar" a reasonable >> conclusion? > > Of course not. People forget what they posted previously, change > their mind, don't express what they intended perfectly, sometimes > express a complex thought that the reader inaccurately perceives > as contradictory, don't realize themselves that their thinking > is contradictory, ... I agree, which is why I resisted my own impulse to call him a liar; however, he has been harping on this subject for months now, so I would be suprised if he actually was surprised and had forgotten... > Lying involves intent to deceive. I haven't been following jmfauth's > claims since they are not of interest to me, but going back and quickly > looking at the posts that triggered the "liar" and "idiot" posts, I > did not see anything that made me think that jmfauth was not sincere > in his beliefs. Being wrong and being sincere are not exclusive. > Nor did Steven even try to justify the "liar" claim. As to Mark > Lawrence, that seemed like a pure "I don't like you" insult whose > proper place is /dev/null. After months of jmf's antagonist posts, I don't blame them. >>>> I hope that we all agree that we want a nice, friendly, >>>> productive community where everyone is welcome. >>> >>> I hope so too but it is likely that some people want a place to >>> develop and assert some sense of influence, engage in verbal duels, >>> instigate arguments, etc. That can be true of regulars here as >>> well as drive-by posters. >>> >>>> But some people simply cannot or will not behave in ways that are >>>> compatible with those community values. There are some people >>>> whom we *do not want here* >>> >>> In other words, everyone is NOT welcome. >> >> Correct. Do you not agree? > > Don't ask me, ask Steven. He was the one who wrote two sentences > earlier, "...we want a...community where everyone is welcome." Ah, right -- missed that! -- ~Ethan~ From wxjmfauth at gmail.com Sun Mar 31 03:35:23 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 31 Mar 2013 00:35:23 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> Message-ID: ------ Neil Hodgson: "The counter-problem is that a French document that needs to include one mathematical symbol (or emoji) outside Latin-1 will double in size as a Python string." Serious developers/typographers/users know that you can not compose a text in French with "latin-1". This is now also the case with German (Germany). --- Neil's comment is correct, >>> sys.getsizeof('a' * 1000 + 'z') 1026 >>> sys.getsizeof('a' * 1000 + '?') 2040 This is not really the problem. "Serious users" may notice sooner or later, Python and Unicode are walking in opposite directions (technically and in spirit). >>> timeit.repeat("'a' * 1000 + '?'") [1.1088995672090292, 1.0842266613261913, 1.1010779011941594] >>> timeit.repeat("'a' * 1000 + 'z'") [0.6362570846925735, 0.6159128762502917, 0.6200501673623791] (Just an opinion) jmf From steve+comp.lang.python at pearwood.info Sun Mar 31 04:22:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Mar 2013 08:22:48 GMT Subject: ASCII versus non-ASCII [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> Message-ID: <5157f258$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Mar 2013 00:35:23 -0700, jmfauth wrote: > This is not really the problem. "Serious users" may notice sooner or > later, Python and Unicode are walking in opposite directions > (technically and in spirit). > >>>> timeit.repeat("'a' * 1000 + '?'") > [1.1088995672090292, 1.0842266613261913, 1.1010779011941594] >>>> timeit.repeat("'a' * 1000 + 'z'") > [0.6362570846925735, 0.6159128762502917, 0.6200501673623791] Perhaps you should stick to Python 3.2, where ASCII strings are no faster than non-ASCII strings. Python 3.2 versus Python 3.3, no significant difference: # 3.2 py> timeit.repeat("'a' * 1000 + '?'") [1.7418999671936035, 1.7198870182037354, 1.763346004486084] # 3.3 py> timeit.repeat("'a' * 1000 + '?'") [1.8083378580026329, 1.818592812011484, 1.7922867869958282] Python 3.2, ASCII vs Non-ASCII: py> timeit.repeat("'a' * 1000 + 'z'") [1.756322135925293, 1.8002049922943115, 1.721085958480835] py> timeit.repeat("'a' * 1000 + '?'") [1.7209150791168213, 1.7162668704986572, 1.7260780334472656] In other words, if you stick to non-ASCII strings, Python 3.3 is no slower than Python 3.2. -- Steven From breamoreboy at yahoo.co.uk Sun Mar 31 08:55:33 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 31 Mar 2013 13:55:33 +0100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> Message-ID: On 31/03/2013 08:35, jmfauth wrote: > ------ > > Neil Hodgson: > > "The counter-problem is that a French document that needs to include > one mathematical symbol (or emoji) outside Latin-1 will double in size > as a Python string." > > Serious developers/typographers/users know that you can not compose > a text in French with "latin-1". This is now also the case with > German (Germany). > > --- > > Neil's comment is correct, > >>>> sys.getsizeof('a' * 1000 + 'z') > 1026 >>>> sys.getsizeof('a' * 1000 + '?') > 2040 > > This is not really the problem. "Serious users" may > notice sooner or later, Python and Unicode are walking in > opposite directions (technically and in spirit). > >>>> timeit.repeat("'a' * 1000 + '?'") > [1.1088995672090292, 1.0842266613261913, 1.1010779011941594] >>>> timeit.repeat("'a' * 1000 + 'z'") > [0.6362570846925735, 0.6159128762502917, 0.6200501673623791] > > > (Just an opinion) > > jmf > I'm feeling very sorry for this horse, it's been flogged so often it's down to bare bones. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rosuav at gmail.com Thu Mar 28 06:22:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 21:22:25 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 28, 2013 at 4:20 PM, Steven D'Aprano wrote: > On Wed, 27 Mar 2013 20:49:20 -0700, rusi wrote: > >> In particular "You are a liar" is as bad as "You are an idiot" The same >> statement can be made non-abusively thus: "... is not true because ..." > > I accept that criticism, even if I disagree with it. Does that make > sense? I mean it in the sense that I accept that your opinion differs > from mine. > > Politeness does not always trump honesty, and stating that somebody's > statement "is not true because..." is not the same as stating that they > are deliberately telling lies (rather than merely being mistaken or > confused). There comes a time when a bit of rudeness is a small cost to pay for forum maintenance. Before you criticize someone for nit-picking, think what happens when someone reads the thread archive. Of course, that particular example can be done courteously too - cf the "def" vs "class" nit from a recent thread. But it'd still be of value even if done rudely, so the hundreds of subsequent readers would have a chance to know what's going on. I was researching a problem with ALSA a couple of weeks ago, and came across a forum thread that discussed exactly what I needed to know. A dozen or so courteous posts delivered misinformation; finally someone had the guts to be rude and call people out for posting incorrect points (and got criticized for doing so), and that one post was the most useful in the whole thread. I'd rather this list have some vinegar than it devolve into uselessness. Or, worse, if there's a hard-and-fast rule about courtesy, devolve into aspartame... everyone's courteous in words but hates each other underneath. Or am I taking the analogy too far? :) ChrisA From nad at acm.org Thu Mar 28 16:23:37 2013 From: nad at acm.org (Ned Deily) Date: Thu, 28 Mar 2013 13:23:37 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > I'd rather this list have some vinegar than it devolve into > uselessness. Or, worse, if there's a hard-and-fast rule about > courtesy, devolve into aspartame... everyone's courteous in words but > hates each other underneath. Or am I taking the analogy too far? :) I think you are positing false choices. No one - at least I'm not - is advocating to avoid challenging false or misleading statements in the interests of maintaining some false "see how well we all get along" facade. The point is we can have meaningful, hard-nosed discussions without resorting to personal insults, i.e. flaming. I think the discussion in this topic over the past 24 hours or so demonstrates that. -- Ned Deily, nad at acm.org From ethan at stoneleaf.us Thu Mar 28 02:12:21 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Mar 2013 23:12:21 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5153DF45.9030203@stoneleaf.us> On 03/27/2013 08:49 PM, rusi wrote: > In particular "You are a liar" is as bad as "You are an idiot" > The same statement can be made non-abusively thus: "... is not true > because ..." I don't agree. With all the posts and micro benchmarks and other drivel that jmf has inflicted on us, I find it /very/ hard to believe that he forgot -- which means he was deliberately lying. At some point we have to stop being gentle / polite / politically correct and call a shovel a shovel... er, spade. -- ~Ethan~ From rosuav at gmail.com Thu Mar 28 20:03:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 11:03:07 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153DF45.9030203@stoneleaf.us> Message-ID: On Fri, Mar 29, 2013 at 10:53 AM, Dennis Lee Bieber wrote: > On Wed, 27 Mar 2013 23:12:21 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > >> >> At some point we have to stop being gentle / polite / politically correct and call a shovel a shovel... er, spade. > > Call it an Instrument For the Transplantation of Dirt > > (Is an antique Steam Shovel ever a Steam Spade?) I don't know, but I'm pretty sure there's a private detective who wouldn't appreciate being called Sam Shovel. ChrisA From breamoreboy at yahoo.co.uk Thu Mar 28 20:15:59 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 29 Mar 2013 00:15:59 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153DF45.9030203@stoneleaf.us> Message-ID: On 28/03/2013 23:53, Dennis Lee Bieber wrote: > On Wed, 27 Mar 2013 23:12:21 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > >> >> At some point we have to stop being gentle / polite / politically correct and call a shovel a shovel... er, spade. > > Call it an Instrument For the Transplantation of Dirt > > (Is an antique Steam Shovel ever a Steam Spade?) > Surely you can spade a lot more things than dirt? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From wxjmfauth at gmail.com Thu Mar 28 05:03:09 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 02:03:09 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> On 28 mar, 07:12, Ethan Furman wrote: > On 03/27/2013 08:49 PM, rusi wrote: > > > In particular "You are a liar" is as bad as "You are an idiot" > > The same statement can be made non-abusively thus: "... is not true > > because ..." > > I don't agree. ?With all the posts and micro benchmarks and other drivel that jmf has inflicted on us, I find it /very/ > hard to believe that he forgot -- which means he was deliberately lying. > > At some point we have to stop being gentle / polite / politically correct and call a shovel a shovel... er, spade. > > -- > ~Ethan~ ----------- The problem is elsewhere. Nobody understand the examples I gave on this list, because nobody understand Unicode. These examples are not random examples, they are well thought. If you were understanding the coding of the characters, Unicode and what this flexible representation does, it would not be a problem for you to create analog examples. So, we are turning into circles. This flexible representation succeeds to cumulate in one shoot all the design mistakes it is possible to do, when one wishes to implements Unicode. Example of a good Unicode understanding. If you wish 1) to preserve memory, 2) to cover the whole range of Unicode, 3) to keep maximum performance while preserving the good work Unicode.org as done (normalization, sorting), there is only one solution: utf-8. For this you have to understand, what is really a "unicode transformation format". Why all the actors, active in the "text field", like MicroSoft, Apple, Adobe, the unicode compliant TeX engines, the foundries, the "organisation" in charge of the OpenType font specifications, are able to handle all this stuff correctly (understanding + implementation) and Python not?, I should say this is going beyond my understanding. Python has certainly and definitvely not "revolutionize" Unicode. jmf From ian at feete.org Thu Mar 28 05:36:19 2013 From: ian at feete.org (Ian Foote) Date: Thu, 28 Mar 2013 09:36:19 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: <51540F13.5070406@feete.org> On 28/03/13 09:03, jmfauth wrote: > The problem is elsewhere. Nobody understand the examples > I gave on this list, because nobody understand Unicode. > These examples are not random examples, they are well > thought. > > If you were understanding the coding of the characters, > Unicode and what this flexible representation does, it > would not be a problem for you to create analog examples. > > So, we are turning into circles. > > This flexible representation succeeds to cumulate in one > shoot all the design mistakes it is possible to do, when > one wishes to implements Unicode. > > Example of a good Unicode understanding. > If you wish 1) to preserve memory, 2) to cover the whole range > of Unicode, 3) to keep maximum performance while preserving the > good work Unicode.org as done (normalization, sorting), there > is only one solution: utf-8. For this you have to understand, > what is really a "unicode transformation format". > > Why all the actors, active in the "text field", like MicroSoft, > Apple, Adobe, the unicode compliant TeX engines, the foundries, > the "organisation" in charge of the OpenType font specifications, > are able to handle all this stuff correctly (understanding + > implementation) and Python not?, I should say this is going > beyond my understanding. > > Python has certainly and definitvely not "revolutionize" > Unicode. > > jmf > You're confusing python's choice of internal string representation with the programmer's choice of encoding for communicating with other programs. I think most people agree that utf-8 is usually the best encoding to use for interoperating with other unicode aware software, but as a variable-length encoding it has disadvantages that make it unsuitable for use as an internal representation. Specifically, indexing a variable-length encoding like utf-8 is not as efficient as indexing a fixed-length encoding. Regards, Ian F From oscar.j.benjamin at gmail.com Thu Mar 28 05:47:04 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 28 Mar 2013 09:47:04 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: On 28 March 2013 09:03, jmfauth wrote: > > The problem is elsewhere. Nobody understand the examples > I gave on this list, because nobody understand Unicode. > These examples are not random examples, they are well > thought. There are many people here and among the Python devs who understand unicode. Similarly they have understood the examples that you have given. It has been accepted that there are a handful of cases where performance has been reduced as a result of the change. There are also many cases where the performance has improved. It is certainly not clear that there is an *overall* performance reduction for people using non latin-1 characters as you have often suggested. The reason your initial posts received a poor reception is that they were accompanied with pointless rants and arrogant claims that no one understood the problem. Had you simply reported the timing differences without the rants then I imagine that you would have received a response like "Okay, there might be a few regressions. Can you open an issue on the tracker please?". Since then you have been relentlessly hijacking unrelated threads and this is clearly just trolling. > > If you were understanding the coding of the characters, > Unicode and what this flexible representation does, it > would not be a problem for you to create analog examples. > > So, we are turning into circles. > > This flexible representation succeeds to cumulate in one > shoot all the design mistakes it is possible to do, when > one wishes to implements Unicode. This is clearly untrue.The most significant design mistakes are the ones that lead to incorrect handling of unicode characters. This new implementation in Python 3.3 has been designed in a way that makes it possible to handle all unicode characters correctly. > > Example of a good Unicode understanding. > If you wish 1) to preserve memory, 2) to cover the whole range > of Unicode, 3) to keep maximum performance while preserving the > good work Unicode.org as done (normalization, sorting), there > is only one solution: utf-8. For this you have to understand, > what is really a "unicode transformation format". Again you pretend that others here don't understand. Most people here are well aware of utf-8 is. Your suggestion that "maximum performance" would be achieved if Python use utf-8 internally ignores the fact that it would have many negative performance implications for slicing and indexing and so on. > > Why all the actors, active in the "text field", like MicroSoft, > Apple, Adobe, the unicode compliant TeX engines, the foundries, > the "organisation" in charge of the OpenType font specifications, > are able to handle all this stuff correctly (understanding + > implementation) and Python not?, I should say this is going > beyond my understanding. > > Python has certainly and definitvely not "revolutionize" > Unicode. Perhaps not, but it does now correctly handle all unicode characters (unlike many other languages and pieces of software). Oscar From rosuav at gmail.com Thu Mar 28 06:30:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 21:30:27 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 8:03 PM, jmfauth wrote: > Example of a good Unicode understanding. > If you wish 1) to preserve memory, 2) to cover the whole range > of Unicode, 3) to keep maximum performance while preserving the > good work Unicode.org as done (normalization, sorting), there > is only one solution: utf-8. For this you have to understand, > what is really a "unicode transformation format". You really REALLY need to sort out in your head the difference between correctness and performance. I still haven't seen one single piece of evidence from you that Python 3.3 fails on any point of Unicode correctness. Covering the whole range of Unicode has never been a problem. In terms of memory usage and performance, though, there's one obvious solution. Fork CPython 3.3 (or the current branch head[1]), change the internal representation of a string to be UTF-8 (by the way, that's the official spelling), and run the string benchmarks. Then post your code and benchmark figures so other people can replicate your results. > Python has certainly and definitvely not "revolutionize" > Unicode. This is one place where you're actually correct, though, because PEP 393 isn't the first instance of this kind of format - Pike's had it for years. Funny though, I don't think that was your point :) [1] Apologies if my terminology is wrong, I'm a git user and did one quick Google search to see if hg uses the same term. ChrisA From nhodgson at iinet.net.au Thu Mar 28 08:11:55 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Thu, 28 Mar 2013 23:11:55 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: Ian Foote: > Specifically, indexing a variable-length encoding like utf-8 is not as > efficient as indexing a fixed-length encoding. Many common string operations do not require indexing by character which reduces the impact of this inefficiency. UTF-8 seems like a reasonable choice for an internal representation to me. One benefit of UTF-8 over Python's flexible representation is that it is, on average, more compact over a wide set of samples. Neil From steve+comp.lang.python at pearwood.info Thu Mar 28 09:01:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 13:01:57 GMT Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 23:11:55 +1100, Neil Hodgson wrote: > Ian Foote: > >> Specifically, indexing a variable-length encoding like utf-8 is not as >> efficient as indexing a fixed-length encoding. > > Many common string operations do not require indexing by character > which reduces the impact of this inefficiency. Which common string operations do you have in mind? Specifically in Python's case, the most obvious counter-example is the length of a string. But that's only because Python strings are immutable objects, and include a field that records the length. So once the string is created, checking its length takes constant time. Some string operations need to inspect every character, e.g. str.upper(). Even for them, the increased complexity of a variable-width encoding costs. It's not sufficient to walk the string inspecting a fixed 1, 2 or 4 bytes per character. You have to walk the string grabbing 1 byte at a time, and then decide whether you need another 1, 2 or 3 bytes. Even though it's still O(N), the added bit-masking and overhead of variable- width encoding adds to the overall cost. Any string method that takes a starting offset requires the method to walk the string byte-by-byte. I've even seen languages put responsibility for dealing with that onto the programmer: the "start offset" is given in *bytes*, not characters. I don't remember what language this was... it might have been Haskell? Whatever it was, it horrified me. > UTF-8 seems like a > reasonable choice for an internal representation to me. It's not. Haskell, for example, uses UTF-8 internally, and it warns that this makes string operations O(N) instead of O(1) precisely because of the need to walk the string inspecting every byte. Remember, when your string primitives are O(N), it is very easy to write code that becomes O(N**2). Using UTF-8 internally is just begging for user-written code to be O(N**2). > One benefit of > UTF-8 over Python's flexible representation is that it is, on average, > more compact over a wide set of samples. Sure. And over a different set of samples, it is less compact. If you write a lot of Latin-1, Python will use one byte per character, while UTF-8 will use two bytes per character. -- Steven From wxjmfauth at gmail.com Thu Mar 28 10:12:10 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 07:12:10 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> On 28 mar, 14:01, Steven D'Aprano wrote: > On Thu, 28 Mar 2013 23:11:55 +1100, Neil Hodgson wrote: > > Ian Foote: > > > > One benefit of > > UTF-8 over Python's flexible representation is that it is, on average, > > more compact over a wide set of samples. > > Sure. And over a different set of samples, it is less compact. If you > write a lot of Latin-1, Python will use one byte per character, while > UTF-8 will use two bytes per character. > This flexible string representation is so absurd that not only "it" does not know you can not write Western European Languages with latin-1, "it" penalizes you by just attempting to optimize latin-1. Shown in my multiple examples. (This is a similar case of the long and short int question/dicussion Chris Angelico opened). PS1: I received plenty of private mails. I'm suprise, how the dev do not understand unicode. PS2: Question I received once from a registrated French Python Developper (in another context). What are those French characters you can handle with cp1252 and not with latin-1? jmf From rosuav at gmail.com Thu Mar 28 10:38:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 01:38:07 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 1:12 AM, jmfauth wrote: > This flexible string representation is so absurd that not only > "it" does not know you can not write Western European Languages > with latin-1, "it" penalizes you by just attempting to optimize > latin-1. Shown in my multiple examples. PEP393 strings have two optimizations, or kinda three: 1a) ASCII-only strings 1b) Latin1-only strings 2) BMP-only strings 3) Everything else Options 1a and 1b are almost identical - I'm not sure what the detail is, but there's something flagging those strings that fit inside seven bits. (Something to do with optimizing encodings later?) Both are optimized down to a single byte per character. Option 2 is optimized to two bytes per character. Option 3 is stored in UTF-32. Once again, jmf, you are forgetting that option 2 is a safe and bug-free optimization. ChrisA From tjreedy at udel.edu Thu Mar 28 12:01:25 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Mar 2013 12:01:25 -0400 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: On 3/28/2013 10:38 AM, Chris Angelico wrote: > PEP393 strings have two optimizations, or kinda three: > > 1a) ASCII-only strings > 1b) Latin1-only strings > 2) BMP-only strings > 3) Everything else > > Options 1a and 1b are almost identical - I'm not sure what the detail > is, but there's something flagging those strings that fit inside seven > bits. (Something to do with optimizing encodings later?) Yes. 'Encoding' an ascii-only string to any ascii-compatible encoding amounts to a simple copy of the internal bytes. I do not know if *all* the codecs for such encodings are 393-aware, but I do know that the utf-8 and latin-1 group are. This is one operation that 3.3+ does much faster than 3.2- -- Terry Jan Reedy From rosuav at gmail.com Thu Mar 28 12:16:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 03:16:55 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 3:01 AM, Terry Reedy wrote: > On 3/28/2013 10:38 AM, Chris Angelico wrote: > >> PEP393 strings have two optimizations, or kinda three: >> >> 1a) ASCII-only strings >> 1b) Latin1-only strings >> 2) BMP-only strings >> 3) Everything else >> >> Options 1a and 1b are almost identical - I'm not sure what the detail >> is, but there's something flagging those strings that fit inside seven >> bits. (Something to do with optimizing encodings later?) > > > Yes. 'Encoding' an ascii-only string to any ascii-compatible encoding > amounts to a simple copy of the internal bytes. I do not know if *all* the > codecs for such encodings are 393-aware, but I do know that the utf-8 and > latin-1 group are. This is one operation that 3.3+ does much faster than > 3.2- Thanks Terry. So that's not so much a representation difference as a flag that costs little or nothing to retain, and can improve performance in the encode later on. Sounds like a useful tweak to the basics of flexible string representation, without being particularly germane to jmf's complaints. ChrisA From ian.g.kelly at gmail.com Thu Mar 28 12:11:59 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Mar 2013 10:11:59 -0600 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 8:38 AM, Chris Angelico wrote: > PEP393 strings have two optimizations, or kinda three: > > 1a) ASCII-only strings > 1b) Latin1-only strings > 2) BMP-only strings > 3) Everything else > > Options 1a and 1b are almost identical - I'm not sure what the detail > is, but there's something flagging those strings that fit inside seven > bits. (Something to do with optimizing encodings later?) Both are > optimized down to a single byte per character. The only difference for ASCII-only strings is that they are kept in a struct with a smaller header. The smaller header omits the utf8 pointer (which optionally points to an additional UTF-8 representation of the string) and its associated length variable. These are not needed for ASCII-only strings because an ASCII string can be directly interpreted as a UTF-8 string for the same result. The smaller header also omits the "wstr_length" field which, according to the PEP, "differs from length only if there are surrogate pairs in the representation." For an ASCII string, of course there would not be any surrogate pairs. From steve+comp.lang.python at pearwood.info Thu Mar 28 20:39:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 00:39:57 GMT Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 10:11:59 -0600, Ian Kelly wrote: > On Thu, Mar 28, 2013 at 8:38 AM, Chris Angelico > wrote: >> PEP393 strings have two optimizations, or kinda three: >> >> 1a) ASCII-only strings >> 1b) Latin1-only strings >> 2) BMP-only strings >> 3) Everything else >> >> Options 1a and 1b are almost identical - I'm not sure what the detail >> is, but there's something flagging those strings that fit inside seven >> bits. (Something to do with optimizing encodings later?) Both are >> optimized down to a single byte per character. > > The only difference for ASCII-only strings is that they are kept in a > struct with a smaller header. The smaller header omits the utf8 pointer > (which optionally points to an additional UTF-8 representation of the > string) and its associated length variable. These are not needed for > ASCII-only strings because an ASCII string can be directly interpreted > as a UTF-8 string for the same result. The smaller header also omits > the "wstr_length" field which, according to the PEP, "differs from > length only if there are surrogate pairs in the representation." For an > ASCII string, of course there would not be any surrogate pairs. I wonder why they need care about surrogate pairs? ASCII and Latin-1 strings obviously do not have them. Nor do BMP-only strings. It's only strings in the SMPs that could need surrogate pairs, and they don't need them in Python's implementation since it's a full 32- bit implementation. So where do the surrogate pairs come into this? I also wonder why the implementation bothers keeping a UTF-8 representation. That sounds like premature optimization to me. Surely you only need it when writing to a file with UTF-8 encoding? For most strings, that will never happen. -- Steven From rosuav at gmail.com Thu Mar 28 20:54:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 11:54:41 +1100 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 29, 2013 at 11:39 AM, Steven D'Aprano wrote: > ASCII and Latin-1 strings obviously do not have them. Nor do BMP-only > strings. It's only strings in the SMPs that could need surrogate pairs, > and they don't need them in Python's implementation since it's a full 32- > bit implementation. So where do the surrogate pairs come into this? PEP 393 says: """ wstr_length, wstr: representation in platform's wchar_t (null-terminated). If wchar_t is 16-bit, this form may use surrogate pairs (in which cast wstr_length differs form length). wstr_length differs from length only if there are surrogate pairs in the representation. utf8_length, utf8: UTF-8 representation (null-terminated). data: shortest-form representation of the unicode string. The string is null-terminated (in its respective representation). All three representations are optional, although the data form is considered the canonical representation which can be absent only while the string is being created. If the representation is absent, the pointer is NULL, and the corresponding length field may contain arbitrary data. """ If the string was created from a wchar_t string, that string will be retained, and presumably can be used to re-output the original for a clean and fast round-trip. Same with... > I also wonder why the implementation bothers keeping a UTF-8 > representation. That sounds like premature optimization to me. Surely you > only need it when writing to a file with UTF-8 encoding? For most > strings, that will never happen. ... the UTF-8 version. It'll keep it if it has it, and not else. A lot of content will go out in the same encoding it came in in, so it makes sense to hang onto it where possible. Though, from the same quote: The UTF-8 representation is null-terminated. Does this mean that it can't be used if there might be a \0 in the string? Minor nitpick, btw: > (in which cast wstr_length differs form length) Should be "in which case" and "from". Who has the power to correct typos in PEPs? ChrisA From breamoreboy at yahoo.co.uk Thu Mar 28 21:03:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 29 Mar 2013 01:03:51 +0000 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 29/03/2013 00:54, Chris Angelico wrote: > > Minor nitpick, btw: >> (in which cast wstr_length differs form length) > Should be "in which case" and "from". Who has the power to correct > typos in PEPs? > > ChrisA > Sneak it in here? http://bugs.python.org/issue13604 -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rosuav at gmail.com Thu Mar 28 21:10:54 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 12:10:54 +1100 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 29, 2013 at 12:03 PM, Mark Lawrence wrote: > On 29/03/2013 00:54, Chris Angelico wrote: >> Minor nitpick, btw: >>> >>> (in which cast wstr_length differs form length) >> >> Should be "in which case" and "from". Who has the power to correct >> typos in PEPs? > > Sneak it in here? http://bugs.python.org/issue13604 Ah! Turns out it's already been fixed; a reword of that section, as shown in the attached files, no longer has the parenthesis, and thus its typos. ChrisA From python at mrabarnett.plus.com Thu Mar 28 22:00:24 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Mar 2013 02:00:24 +0000 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5154F5B8.9080401@mrabarnett.plus.com> On 29/03/2013 00:54, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 11:39 AM, Steven D'Aprano > wrote: >> ASCII and Latin-1 strings obviously do not have them. Nor do BMP-only >> strings. It's only strings in the SMPs that could need surrogate pairs, >> and they don't need them in Python's implementation since it's a full 32- >> bit implementation. So where do the surrogate pairs come into this? > > PEP 393 says: > """ > wstr_length, wstr: representation in platform's wchar_t > (null-terminated). If wchar_t is 16-bit, this form may use surrogate > pairs (in which cast wstr_length differs form length). wstr_length > differs from length only if there are surrogate pairs in the > representation. > > utf8_length, utf8: UTF-8 representation (null-terminated). > > data: shortest-form representation of the unicode string. The string > is null-terminated (in its respective representation). > > All three representations are optional, although the data form is > considered the canonical representation which can be absent only while > the string is being created. If the representation is absent, the > pointer is NULL, and the corresponding length field may contain > arbitrary data. > """ > > If the string was created from a wchar_t string, that string will be > retained, and presumably can be used to re-output the original for a > clean and fast round-trip. Same with... > >> I also wonder why the implementation bothers keeping a UTF-8 >> representation. That sounds like premature optimization to me. Surely you >> only need it when writing to a file with UTF-8 encoding? For most >> strings, that will never happen. > > ... the UTF-8 version. It'll keep it if it has it, and not else. A lot > of content will go out in the same encoding it came in in, so it makes > sense to hang onto it where possible. > > Though, from the same quote: The UTF-8 representation is > null-terminated. Does this mean that it can't be used if there might > be a \0 in the string? > You could ask the same question about any encoding. It's only an issue if it's passed to a C function which expects a null-terminated string. > Minor nitpick, btw: >> (in which cast wstr_length differs form length) > Should be "in which case" and "from". Who has the power to correct > typos in PEPs? > From steve+comp.lang.python at pearwood.info Thu Mar 28 22:37:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 02:37:55 GMT Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Mar 2013 11:54:41 +1100, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 11:39 AM, Steven D'Aprano > wrote: >> ASCII and Latin-1 strings obviously do not have them. Nor do BMP-only >> strings. It's only strings in the SMPs that could need surrogate pairs, >> and they don't need them in Python's implementation since it's a full >> 32- bit implementation. So where do the surrogate pairs come into this? > > PEP 393 says: > """ > wstr_length, wstr: representation in platform's wchar_t > (null-terminated). If wchar_t is 16-bit, this form may use surrogate > pairs (in which cast wstr_length differs form length). wstr_length > differs from length only if there are surrogate pairs in the > representation. > > utf8_length, utf8: UTF-8 representation (null-terminated). > > data: shortest-form representation of the unicode string. The string is > null-terminated (in its respective representation). > > All three representations are optional, although the data form is > considered the canonical representation which can be absent only while > the string is being created. If the representation is absent, the > pointer is NULL, and the corresponding length field may contain > arbitrary data. > """ All the words are in English (well, most of them...) but what does it mean? > If the string was created from a wchar_t string, that string will be > retained, and presumably can be used to re-output the original for a > clean and fast round-trip. Under what circumstances will a string be created from a wchar_t string? How, and why, would such a string be created? Why would Python still support strings containing surrogates when it now has a nice, shiny, surrogate-free flexible representation? >> I also wonder why the implementation bothers keeping a UTF-8 >> representation. That sounds like premature optimization to me. Surely >> you only need it when writing to a file with UTF-8 encoding? For most >> strings, that will never happen. > > ... the UTF-8 version. It'll keep it if it has it, and not else. A lot > of content will go out in the same encoding it came in in, so it makes > sense to hang onto it where possible. Not to me. That almost doubles the size of the string, on the off-chance that you'll need the UTF-8 encoding. Which for many uses, you don't, and even if you do, it seems like premature optimization to keep it around just in case. Encoding to UTF-8 will be fast for small N, and for large N, why carry around (potentially) multiple megabytes of duplicated data just in case the encoded version is needed some time? > Though, from the same quote: The UTF-8 representation is > null-terminated. Does this mean that it can't be used if there might be > a \0 in the string? > > Minor nitpick, btw: >> (in which cast wstr_length differs form length) > Should be "in which case" and "from". Who has the power to correct typos > in PEPs? > > ChrisA From rosuav at gmail.com Thu Mar 28 22:44:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 13:44:50 +1100 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 29, 2013 at 1:37 PM, Steven D'Aprano wrote: > Under what circumstances will a string be created from a wchar_t string? > How, and why, would such a string be created? Why would Python still > support strings containing surrogates when it now has a nice, shiny, > surrogate-free flexible representation? Strings are created from some form of content. If not from another Python string, then - most likely - it's from a stream of bytes. If from a C API that returns wchar_t, then it'd make sense to have that form around. ChrisA From ian.g.kelly at gmail.com Fri Mar 29 02:11:37 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 29 Mar 2013 00:11:37 -0600 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 28, 2013 at 8:37 PM, Steven D'Aprano wrote: >>> I also wonder why the implementation bothers keeping a UTF-8 >>> representation. That sounds like premature optimization to me. Surely >>> you only need it when writing to a file with UTF-8 encoding? For most >>> strings, that will never happen. >> >> ... the UTF-8 version. It'll keep it if it has it, and not else. A lot >> of content will go out in the same encoding it came in in, so it makes >> sense to hang onto it where possible. > > Not to me. That almost doubles the size of the string, on the off-chance > that you'll need the UTF-8 encoding. Which for many uses, you don't, and > even if you do, it seems like premature optimization to keep it around > just in case. Encoding to UTF-8 will be fast for small N, and for large > N, why carry around (potentially) multiple megabytes of duplicated data > just in case the encoded version is needed some time? >From the PEP: """ A new function PyUnicode_AsUTF8 is provided to access the UTF-8 representation. It is thus identical to the existing _PyUnicode_AsString, which is removed. The function will compute the utf8 representation when first called. Since this representation will consume memory until the string object is released, applications should use the existing PyUnicode_AsUTF8String where possible (which generates a new string object every time). APIs that implicitly converts a string to a char* (such as the ParseTuple functions) will use PyUnicode_AsUTF8 to compute a conversion. """ So the utf8 representation is not populated when the string is created, but when a utf8 representation is requested, and only when requested by the API that returns a char*, not by the API that returns a bytes object. From ian.g.kelly at gmail.com Fri Mar 29 02:22:08 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 29 Mar 2013 00:22:08 -0600 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 29, 2013 at 12:11 AM, Ian Kelly wrote: > From the PEP: > > """ > A new function PyUnicode_AsUTF8 is provided to access the UTF-8 > representation. It is thus identical to the existing > _PyUnicode_AsString, which is removed. The function will compute the > utf8 representation when first called. Since this representation will > consume memory until the string object is released, applications > should use the existing PyUnicode_AsUTF8String where possible (which > generates a new string object every time). APIs that implicitly > converts a string to a char* (such as the ParseTuple functions) will > use PyUnicode_AsUTF8 to compute a conversion. > """ > > So the utf8 representation is not populated when the string is > created, but when a utf8 representation is requested, and only when > requested by the API that returns a char*, not by the API that returns > a bytes object. Since the PEP specifically mentions ParseTuple string conversion, I am thinking that this is probably the motivation for caching it. A string that is passed into a C function (that uses one of the various UTF-8 char* format specifiers) is perhaps likely to be passed into that function again at some point, so the UTF-8 representation is kept around to avoid the need to recompose it at on each call. From christian at python.org Fri Mar 29 18:05:12 2013 From: christian at python.org (Christian Heimes) Date: Fri, 29 Mar 2013 23:05:12 +0100 Subject: Surrogate pairs in new flexible string representation In-Reply-To: References: <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 29.03.2013 07:22, schrieb Ian Kelly: > Since the PEP specifically mentions ParseTuple string conversion, I am > thinking that this is probably the motivation for caching it. A > string that is passed into a C function (that uses one of the various > UTF-8 char* format specifiers) is perhaps likely to be passed into > that function again at some point, so the UTF-8 representation is kept > around to avoid the need to recompose it at on each call. It's not just about caching but also about memory management. The additional utf8 member is required for backward compatibility. The APIs expect a pointer to an existing and shared block of memory. They don't take ownership of the memory block and therefore don't free() it. Christian From tjreedy at udel.edu Fri Mar 29 14:06:40 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Mar 2013 14:06:40 -0400 Subject: Surrogate pairs in new flexible string representation [was Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <5154e2dd$0$29974$c3e8da3$5496439d@news.astraweb.com> <5154fe82$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/28/2013 10:37 PM, Steven D'Aprano wrote: > Under what circumstances will a string be created from a wchar_t string? > How, and why, would such a string be created? Why would Python still > support strings containing surrogates when it now has a nice, shiny, > surrogate-free flexible representation? I believe because surrogates are legal codepoints and users may put them in strings even though python does not (except for surrogate_escape error handling). I believe some of the internal complexity comes from supporting the old C-api so as to not immediately invalidate existing extensions. -- Terry Jan Reedy From wxjmfauth at gmail.com Thu Mar 28 11:14:43 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 08:14:43 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> Message-ID: <6c93d273-2289-4c49-a586-52675aea9567@p5g2000yqj.googlegroups.com> On 28 mar, 15:38, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 1:12 AM, jmfauth wrote: > > This flexible string representation is so absurd that not only > > "it" does not know you can not write Western European Languages > > with latin-1, "it" penalizes you by just attempting to optimize > > latin-1. Shown in my multiple examples. > > PEP393 strings have two optimizations, or kinda three: > > 1a) ASCII-only strings > 1b) Latin1-only strings > 2) BMP-only strings > 3) Everything else > > Options 1a and 1b are almost identical - I'm not sure what the detail > is, but there's something flagging those strings that fit inside seven > bits. (Something to do with optimizing encodings later?) Both are > optimized down to a single byte per character. > > Option 2 is optimized to two bytes per character. > > Option 3 is stored in UTF-32. > > Once again, jmf, you are forgetting that option 2 is a safe and > bug-free optimization. > > ChrisA As long as you are attempting to devide a set of characters in chunks and try to handle them seperately, it will never work. Read my previous post about the unicode transformation format. I know what pep393 does. jmf From rosuav at gmail.com Thu Mar 28 11:21:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 02:21:03 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <6c93d273-2289-4c49-a586-52675aea9567@p5g2000yqj.googlegroups.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <6c93d273-2289-4c49-a586-52675aea9567@p5g2000yqj.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 2:14 AM, jmfauth wrote: > As long as you are attempting to devide a set of characters in > chunks and try to handle them seperately, it will never work. Okay. Let's look at integers. To properly represent the Python 3 'int' type (or the Python 2 'long'), we need to be able to encode ANY integer. And of course, any attempt to divide them up into chunks will never work. So we need a single representation that will cover ANY integer, right? Perfect. We already have one of those, detailed in RFC 2795. (It's coming up to its thirteenth anniversary in a day or two. Very appropriate.) http://tools.ietf.org/html/rfc2795#section-4 Are you saying Python's integers should be stored as I-TAGs? ChrisA From wxjmfauth at gmail.com Thu Mar 28 11:45:51 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 08:45:51 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <944f195c-cbfe-47e1-a963-05fe3d98238d@5g2000yqz.googlegroups.com> <6c93d273-2289-4c49-a586-52675aea9567@p5g2000yqj.googlegroups.com> Message-ID: <9f3c6d10-46a3-4835-baf5-76a7da4b0c7c@k1g2000yqf.googlegroups.com> On 28 mar, 16:14, jmfauth wrote: > On 28 mar, 15:38, Chris Angelico wrote: > > > > > > > > > > > On Fri, Mar 29, 2013 at 1:12 AM, jmfauth wrote: > > > This flexible string representation is so absurd that not only > > > "it" does not know you can not write Western European Languages > > > with latin-1, "it" penalizes you by just attempting to optimize > > > latin-1. Shown in my multiple examples. > > > PEP393 strings have two optimizations, or kinda three: > > > 1a) ASCII-only strings > > 1b) Latin1-only strings > > 2) BMP-only strings > > 3) Everything else > > > Options 1a and 1b are almost identical - I'm not sure what the detail > > is, but there's something flagging those strings that fit inside seven > > bits. (Something to do with optimizing encodings later?) Both are > > optimized down to a single byte per character. > > > Option 2 is optimized to two bytes per character. > > > Option 3 is stored in UTF-32. > > > Once again, jmf, you are forgetting that option 2 is a safe and > > bug-free optimization. > > > ChrisA > > As long as you are attempting to devide a set of characters in > chunks and try to handle them seperately, it will never work. > > Read my previous post about the unicode transformation format. > I know what pep393 does. > > jmf Addendum. This was you correctly percieved in one another thread. You qualified it as a "switch". Now you have to understand from where this "switch" is coming from. jmf by toy with From ian.g.kelly at gmail.com Thu Mar 28 12:01:06 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Mar 2013 10:01:06 -0600 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 28, 2013 at 7:01 AM, Steven D'Aprano wrote: > Any string method that takes a starting offset requires the method to > walk the string byte-by-byte. I've even seen languages put responsibility > for dealing with that onto the programmer: the "start offset" is given in > *bytes*, not characters. I don't remember what language this was... it > might have been Haskell? Whatever it was, it horrified me. Go does this. I remember because it came up in one of these threads, where jmf (or was it Ranting Rick?) was praising Go for just getting Unicode "right". From nhodgson at iinet.net.au Thu Mar 28 23:34:27 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Fri, 29 Mar 2013 14:34:27 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> Steven D'Aprano: > Some string operations need to inspect every character, e.g. str.upper(). > Even for them, the increased complexity of a variable-width encoding > costs. It's not sufficient to walk the string inspecting a fixed 1, 2 or > 4 bytes per character. You have to walk the string grabbing 1 byte at a > time, and then decide whether you need another 1, 2 or 3 bytes. Even > though it's still O(N), the added bit-masking and overhead of variable- > width encoding adds to the overall cost. It does add to implementation complexity but should only add a small amount of time. To compare costs, I am using the text of the web site http://www.mofa.go.jp/mofaj/ since it has a reasonable amount (10%) of multi-byte characters. Since the document fits in the the BMP, Python would choose a 2-byte wide implementation so I am emulating that choice with a very simple 16-bit table-based upper-caser. Real Unicode case conversion code is more concerned with edge cases like Turkic and Lithuanian locales and Greek combining characters and also allowing for measurement/reallocation for the cases where the result is smaller/larger. See, for example, glib's real_toupper in https://git.gnome.org/browse/glib/tree/glib/guniprop.c Here is some simplified example code that implements upper-casing over 16-bit wide (utf16_up) and UTF-8 (utf8_up) buffers: http://www.scintilla.org/UTF8Up.cxx Since I didn't want to spend too much time writing code it only handles the BMP and doesn't have upper-case table entries outside ASCII for now. If this was going to be worked on further to be made maintainable, most of the masking and so forth would be in macros similar to UTF8_COMPUTE/UTF8_GET in glib. The UTF-8 case ranges from around 5% slower on average in a 32 bit release build (VC2012 on an i7 870) to averaging a little faster in a 64-bit build. They're both around a billion characters per-second. C:\u\hg\UpUTF\UpUTF>..\x64\Release\UpUTF.exe Time taken for UTF8 of 80449=0.006528 Time taken for UTF16 of 71525=0.006610 Relative time taken UTF8/UTF16 0.987581 > Any string method that takes a starting offset requires the method to > walk the string byte-by-byte. I've even seen languages put responsibility > for dealing with that onto the programmer: the "start offset" is given in > *bytes*, not characters. I don't remember what language this was... it > might have been Haskell? Whatever it was, it horrified me. It doesn't horrify me - I've been working this way for over 10 years and it seems completely natural. You can wrap access in iterators that hide the byte offsets if you like. This then ensures that all operations on those iterators are safe only allowing the iterator to point at the start/end of valid characters. > Sure. And over a different set of samples, it is less compact. If you > write a lot of Latin-1, Python will use one byte per character, while > UTF-8 will use two bytes per character. I think you mean writing a lot of Latin-1 characters outside ASCII. However, even people writing texts in, say, French will find that only a small proportion of their text is outside ASCII and so the cost of UTF-8 is correspondingly small. The counter-problem is that a French document that needs to include one mathematical symbol (or emoji) outside Latin-1 will double in size as a Python string. Neil From ethan at stoneleaf.us Fri Mar 29 00:56:05 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Mar 2013 21:56:05 -0700 Subject: unicode and the FSR [was: Re: flaming vs accuracy [was Re: Performance of int/long in Python 3]] In-Reply-To: <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> Message-ID: <51551EE5.8000502@stoneleaf.us> On 03/28/2013 08:34 PM, Neil Hodgson wrote: > Steven D'Aprano: > >> Any string method that takes a starting offset requires the method to >> walk the string byte-by-byte. I've even seen languages put responsibility >> for dealing with that onto the programmer: the "start offset" is given in >> *bytes*, not characters. I don't remember what language this was... it >> might have been Haskell? Whatever it was, it horrified me. > > It doesn't horrify me - I've been working this way for over 10 years and it seems completely natural. Horrifying or not, I am willing to give up a small amount of speed for correctness. Heck, I'm willing to give up a lot of speed for correctness. Once I have my slow but correct prototype going I can recode in a faster language (if needed) and compare it's blazingly fast output with my slowly-generated but known-good output. > You can wrap > access in iterators that hide the byte offsets if you like. This then ensures that all operations on those iterators are > safe only allowing the iterator to point at the start/end of valid characters. Sure. Or I can let Python handle it for me. > The counter-problem is that a French document that needs to include one mathematical symbol (or emoji) outside > Latin-1 will double in size as a Python string. True. But how often do you have the entire document as a single string? Use readlines() instead of read(). Besides, memory is cheap. -- ~Ethan~ From rosuav at gmail.com Fri Mar 29 01:33:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 16:33:52 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> Message-ID: On Fri, Mar 29, 2013 at 2:34 PM, Neil Hodgson wrote: > It doesn't horrify me - I've been working this way for over 10 years and > it seems completely natural. You can wrap access in iterators that hide the > byte offsets if you like. This then ensures that all operations on those > iterators are safe only allowing the iterator to point at the start/end of > valid characters. But both this and your example of case conversion are, fundamentally, iterating over the string. What if you aren't doing that? What if you want to parse and process? ChrisA From nhodgson at iinet.net.au Fri Mar 29 01:46:14 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Fri, 29 Mar 2013 16:46:14 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <51543f45$0$29998$c3e8da3$5496439d@news.astraweb.com> <-LGdnWTpyKcdkcjMnZ2dnUVZ_jCdnZ2d@westnet.com.au> Message-ID: Chris Angelico: > But both this and your example of case conversion are, fundamentally, > iterating over the string. What if you aren't doing that? What if you > want to parse and process? Parsing is also normally a scanning operation. If you want to process pieces of the string based on the parse then you remember the positions (as iterators) at the significant places and extract/process the data based on those positions. Neil From python at mrabarnett.plus.com Thu Mar 28 10:51:56 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Mar 2013 14:51:56 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: <5154590C.9030902@mrabarnett.plus.com> On 28/03/2013 12:11, Neil Hodgson wrote: > Ian Foote: > >> Specifically, indexing a variable-length encoding like utf-8 is not >> as efficient as indexing a fixed-length encoding. > > Many common string operations do not require indexing by character > which reduces the impact of this inefficiency. UTF-8 seems like a > reasonable choice for an internal representation to me. One benefit > of UTF-8 over Python's flexible representation is that it is, on > average, more compact over a wide set of samples. > Implementing the regex module (http://pypi.python.org/pypi/regex) would have been more difficult if the internal representation had been UTF-8, because of the need to decode, and the implementation would also have been slower for that reason. From rosuav at gmail.com Thu Mar 28 11:07:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 02:07:45 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <5154590C.9030902@mrabarnett.plus.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <5154590C.9030902@mrabarnett.plus.com> Message-ID: On Fri, Mar 29, 2013 at 1:51 AM, MRAB wrote: > On 28/03/2013 12:11, Neil Hodgson wrote: >> >> Ian Foote: >> >>> Specifically, indexing a variable-length encoding like utf-8 is not >>> as efficient as indexing a fixed-length encoding. >> >> >> Many common string operations do not require indexing by character >> which reduces the impact of this inefficiency. UTF-8 seems like a >> reasonable choice for an internal representation to me. One benefit >> of UTF-8 over Python's flexible representation is that it is, on >> average, more compact over a wide set of samples. >> > Implementing the regex module (http://pypi.python.org/pypi/regex) would > have been more difficult if the internal representation had been UTF-8, > because of the need to decode, and the implementation would also have > been slower for that reason. In fact, nearly ALL string parsing operations would need to be done differently. The only method that I can think of that wouldn't be impacted is a linear state-machine parser - something that could be written inside a "for character in string" loop. text = [] def initial(c): global state if c=='<': state=tag else: text.append(c) def tag(c): global state if c=='>': state=initial state = initial for character in string: state(character) print(''.join(text)) I'm pretty sure this will run in O(N) time, even with UTF-8 strings. But it's an *extremely* simple parser. ChrisA From nhodgson at iinet.net.au Thu Mar 28 23:57:20 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Fri, 29 Mar 2013 14:57:20 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: MRAB: > Implementing the regex module (http://pypi.python.org/pypi/regex) would > have been more difficult if the internal representation had been UTF-8, > because of the need to decode, and the implementation would also have > been slower for that reason. One way to build regex support for UTF-8 is to build a fixed width version of the regex code and then interpose an object that converts between the UTF-8 representation and that code. The C++11 standard library contains a regex template that can be instantiated over a UTF-8 representation in this way. Neil From wxjmfauth at gmail.com Thu Mar 28 09:34:32 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 06:34:32 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: On 28 mar, 11:30, Chris Angelico wrote: > On Thu, Mar 28, 2013 at 8:03 PM, jmfauth wrote: ----- > You really REALLY need to sort out in your head the difference between > correctness and performance. I still haven't seen one single piece of > evidence from you that Python 3.3 fails on any point of Unicode > correctness. That's because you are not understanding unicode. Unicode takes you from the character to the unicoded transformed fomat via the code point, working with a unique set of characters with a contigoous range of code points. Then it is up to the "implementors" (languages, compilers, ...) to implement this utf. > Covering the whole range of Unicode has never been a > problem. ... for all those, who are following the scheme explained above. And it magically works smoothly. Of course, there are some variations due to the Character Encoding Form wich is later influenced by the Character Encoding Scheme (the serialization of the character Encoding Scheme). Rough explanation in other words. I does not matter if you are using utf-8, -16, -32, ucs2 or ucs4. All the single characters are handled in the same way with the "same algorithm". --- The flexible string representation takes the problem from the other side, it attempts to work with the characters by using their representations and it (can only) fails... PS I never propose to use utf-8. I only spoke about utf-8 as an example. If you start to discuss indexing, you are off-topic. jmf From ian.g.kelly at gmail.com Thu Mar 28 12:33:46 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Mar 2013 10:33:46 -0600 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: > The flexible string representation takes the problem from the > other side, it attempts to work with the characters by using > their representations and it (can only) fails... This is false. As I've pointed out to you before, the FSR does not divide characters up by representation. It divides them up by codepoint -- more specifically, by the *bit-width* of the codepoint. We call the internal format of the string "ASCII" or "Latin-1" or "UCS-2" for conciseness and a point of reference, but fundamentally all of the FSR formats are simply byte arrays of *codepoints* -- you know, those things you keep harping on. The major optimization performed by the FSR is to consistently truncate the leading zero bytes from each codepoint when it is possible to do so safely. But regardless of to what extent this truncation is applied, the string is *always* internally just an array of codepoints, and the same algorithms apply for all representations. From wxjmfauth at gmail.com Thu Mar 28 12:55:46 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 09:55:46 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: <2362b4e9-fc37-492a-a216-08a22632b28d@u20g2000yqj.googlegroups.com> Chris, Your problem with int/long, the start of this thread, is very intersting. This is not a demonstration, a proof, rather an illustration. Assume you have a set of integers {0...9} and an operator, let say, the addition. Idea. Just devide this set in two chunks, {0...4} and {5...9} and work hardly to optimize the addition of 2 operands in the sets {0...4}. The problems. - When optimizing "{0...4}", your algorithm will most probably weaken "{5...9}". - When using "{5...9}", you do not benefit from your algorithm, you will be penalized just by the fact you has optimized "{0...4}" - And the first mistake, you are just penalized and impacted by the fact you have to select in which subset you operands are when working with "{0...9}". Very interestingly, working with the representation (bytes) of these integers will not help. You have to consider conceptually {0..9} as numbers. Now, replace numbers by characters, bytes by "encoded code points", and you have qualitatively the flexible string representation. In Unicode, there is one more level of abstraction: one conceptually neither works with characters, nor with "encoded code points", but with unicode transformed formated "entities". (see my previous post). That means you can work very hardly on the "bytes levels", you will never solves the problem which is one level higher in the unicode hierarchy: character -> code point -> utf -> bytes (implementation) with the important fact that this construct can only go from left to right. --- In fact, by proposing a flexible representation of ints, you may just fall in the same trap the flexible string representation presents. ---- All this stuff is explained in good books about the coding of the characters and/or unicode. The unicode.org documention explains it too. It is a little bit harder to discover, because the doc is presenting always this stuff from a "technical" perspective. You get it when reading a large part of the Unicode doc. jmf From rosuav at gmail.com Thu Mar 28 13:13:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 04:13:24 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <2362b4e9-fc37-492a-a216-08a22632b28d@u20g2000yqj.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <2362b4e9-fc37-492a-a216-08a22632b28d@u20g2000yqj.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 3:55 AM, jmfauth wrote: > Assume you have a set of integers {0...9} and an operator, > let say, the addition. > > Idea. > Just devide this set in two chunks, {0...4} and {5...9} > and work hardly to optimize the addition of 2 operands in > the sets {0...4}. > > The problems. > - When optimizing "{0...4}", your algorithm will most probably > weaken "{5...9}". > - When using "{5...9}", you do not benefit from your algorithm, you > will be penalized just by the fact you has optimized "{0...4}" > - And the first mistake, you are just penalized and impacted by the > fact you have to select in which subset you operands are when > working with "{0...9}". > > Very interestingly, working with the representation (bytes) of > these integers will not help. You have to consider conceptually > {0..9} as numbers. Yeah, and there's an easy representation of those numbers. But let's look at Python's representations of integers. I have a sneaking suspicion something takes note of how large the number is before deciding how to represent it. Look! >>> sys.getsizeof(1) 14 >>> sys.getsizeof(1<<2) 14 >>> sys.getsizeof(1<<4) 14 >>> sys.getsizeof(1<<8) 14 >>> sys.getsizeof(1<<31) 18 >>> sys.getsizeof(1<<30) 18 >>> sys.getsizeof(1<<16) 16 >>> sys.getsizeof(1<<12345) 1660 >>> sys.getsizeof(1<<123456) 16474 Small numbers are represented more compactly than large ones! And it's not like in REXX, where all numbers are stored as strings. Go fork CPython and make the changes you suggest. Then run real-world code on it and see how it performs. Or at very least, run plausible benchmarks like the strings benchmark from the standard tests. My original post about integers was based on two comparisons: Python 2 and Pike. Both languages have an optimization for "small" integers (where "small" is "within machine word" - on rechecking some of my stats, I find that I perhaps should have used a larger offset, as the 64-bit Linux Python I used appeared to be a lot faster than it should have been), which Python 3 doesn't have. Real examples, real statistics, real discussion. (I didn't include Pike stats in what I posted, for two reasons: firstly, it would require a reworking of the code, rather than simply "run this under both interpreters"; and secondly, Pike performance is completely different from CPython performance, and is non-comparable. Pike is more similar to PyPy, able to compile - in certain circumstances - to machine code. So the comparisons were Py2 vs Py3.) ChrisA From wxjmfauth at gmail.com Thu Mar 28 13:48:33 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 10:48:33 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> Message-ID: <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> On 28 mar, 17:33, Ian Kelly wrote: > On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: > > The flexible string representation takes the problem from the > > other side, it attempts to work with the characters by using > > their representations and it (can only) fails... > > This is false. ?As I've pointed out to you before, the FSR does not > divide characters up by representation. ?It divides them up by > codepoint -- more specifically, by the *bit-width* of the codepoint. > We call the internal format of the string "ASCII" or "Latin-1" or > "UCS-2" for conciseness and a point of reference, but fundamentally > all of the FSR formats are simply byte arrays of *codepoints* -- you > know, those things you keep harping on. ?The major optimization > performed by the FSR is to consistently truncate the leading zero > bytes from each codepoint when it is possible to do so safely. ?But > regardless of to what extent this truncation is applied, the string is > *always* internally just an array of codepoints, and the same > algorithms apply for all representations. ----- You know, we can discuss this ad nauseam. What is important is Unicode. You have transformed Python back in an ascii oriented product. If Python had imlemented Unicode correctly, there would be no difference in using an "a", "?", "?" or any character, what the narrow builds did. If I am practically the only one, who speakes /discusses about this, I can ensure you, this has been noticed. Now, it's time to prepare the Asparagus, the "jambon cru" and a good bottle a dry white wine. jmf From rosuav at gmail.com Thu Mar 28 13:55:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 04:55:03 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 4:48 AM, jmfauth wrote: > If Python had imlemented Unicode correctly, there would > be no difference in using an "a", "?", "?" or any character, > what the narrow builds did. I'm not following your grammar perfectly here, but if Python were implementing Unicode correctly, there would be no difference between any of those characters, which is the way a *wide* build works. With a narrow build, there is a difference between BMP and non-BMP characters. ChrisA From wxjmfauth at gmail.com Thu Mar 28 16:26:57 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 13:26:57 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: On 28 mar, 18:55, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 4:48 AM, jmfauth wrote: > > If Python had imlemented Unicode correctly, there would > > be no difference in using an "a", "?", "?" or any character, > > what the narrow builds did. > > I'm not following your grammar perfectly here, but if Python were > implementing Unicode correctly, there would be no difference between > any of those characters, which is the way a *wide* build works. With a > narrow build, there is a difference between BMP and non-BMP > characters. > > ChrisA -------- The wide build (I never used) is in my mind as correct as the narrow build. It "just" covers a different range in unicode (the whole range). Claiming that the narrow build is buggy, because it does not cover the whole unicode is not correct. Unicode does not stipulate, one has to cover the whole range. Unicode expects that every character in a range behaves the same way. This is clearly not realized with the flexible string representation. An user should not be somehow penalized simply because it not an ascii user. If you take the fonts in consideration (btw a problem nobody is speaking about) and you ensure your application, toolkit, ... is MES-X or WGL4 compliant, your are also deliberately (and correctly) working with a restriced unicode range. jmf From rosuav at gmail.com Thu Mar 28 17:45:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 08:45:36 +1100 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 7:26 AM, jmfauth wrote: > The wide build (I never used) is in my mind as correct as > the narrow build. It "just" covers a different range in unicode > (the whole range). Actually it does; it covers all of the Unicode range, by using (effectively) UTF-16. Characters that cannot be represented in one 16-bit number are represented in two. That's not "just" covering a different range. It's being buggy. And it's creating a way for code to unexpectedly behave fundamentally differently on Windows and Linux (since the most common builds for Windows were narrow and for Linux were wide). This is a Bad Thing for Python. ChrisA From tjreedy at udel.edu Thu Mar 28 19:12:07 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Mar 2013 19:12:07 -0400 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: On 3/28/2013 4:26 PM, jmfauth wrote: Please provide references for your assertions. I have read the unicode standard, parts more than once, and your assertions contradict my memory. > Unicode does not stipulate, one has to cover the whole range. I believe it does. As I remember, the recognized encodings all encode the entire unicode codepoint range > Unicode expects that every character in a range behaves the same > way. I have no idea what you mean by 'same way'. Each codepoint is supposed to behave differently in some way. That is the reason for having multiple codepoints. One causes an 'a' to appear, another a 'b'. Indeed, the standard define multiple categories of codepoints and chars in different categories are supposed to act differently (or be treated differently). Glyphic chars versus control chars are one example. -- Terry Jan Reedy From benjamin.kaplan at case.edu Thu Mar 28 16:29:23 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 28 Mar 2013 13:29:23 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 10:48 AM, jmfauth wrote: > On 28 mar, 17:33, Ian Kelly wrote: >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: >> > The flexible string representation takes the problem from the >> > other side, it attempts to work with the characters by using >> > their representations and it (can only) fails... >> >> This is false. As I've pointed out to you before, the FSR does not >> divide characters up by representation. It divides them up by >> codepoint -- more specifically, by the *bit-width* of the codepoint. >> We call the internal format of the string "ASCII" or "Latin-1" or >> "UCS-2" for conciseness and a point of reference, but fundamentally >> all of the FSR formats are simply byte arrays of *codepoints* -- you >> know, those things you keep harping on. The major optimization >> performed by the FSR is to consistently truncate the leading zero >> bytes from each codepoint when it is possible to do so safely. But >> regardless of to what extent this truncation is applied, the string is >> *always* internally just an array of codepoints, and the same >> algorithms apply for all representations. > > ----- > > You know, we can discuss this ad nauseam. What is important > is Unicode. > > You have transformed Python back in an ascii oriented product. > > If Python had imlemented Unicode correctly, there would > be no difference in using an "a", "?", "?" or any character, > what the narrow builds did. > > If I am practically the only one, who speakes /discusses about > this, I can ensure you, this has been noticed. > > Now, it's time to prepare the Asparagus, the "jambon cru" > and a good bottle a dry white wine. > > jmf > > You still have yet to explain how Python's string representation is wrong. Just how it isn't optimal for one specific case. Here's how I understand it: 1) Strings are sequences of stuff. Generally, we talk about strings as either sequences of bytes or sequences of characters. 2) Unicode is a format used to represent characters. Therefore, Unicode strings are character strings, not byte strings. 2) Encodings are functions that map characters to bytes. They typically also define an inverse function that converts from bytes back to characters. 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I mentioned in the previous point. It happens to be one of the five standard encodings that is defined for all characters in the Unicode standard (the others being the little and big endian variants of UTF-16 and UTF-32). 4) The internal representation of a character string DOES NOT MATTER. All that matters is that the API represents it as a string of characters, regardless of the representation. We could implement character strings by putting the Unicode code-points in binary-coded decimal and it would be a Unicode character string. 5) The String type that .NET and Java (and unicode type in Python narrow builds) use is not a character string. It is a string of shorts, each of which corresponds to a UTF-16 code point. I know this is the case because in all of these, the length of "\u1f435" is 2 even though it only consists of one character. 6) The new string representation in Python 3.3 can successfully represent all characters in the Unicode standard. The actual number of bytes that each character consumes is invisible to the user. From wxjmfauth at gmail.com Thu Mar 28 17:11:18 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 14:11:18 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> Message-ID: <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> On 28 mar, 21:29, Benjamin Kaplan wrote: > On Thu, Mar 28, 2013 at 10:48 AM, jmfauth wrote: > > On 28 mar, 17:33, Ian Kelly wrote: > >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: > >> > The flexible string representation takes the problem from the > >> > other side, it attempts to work with the characters by using > >> > their representations and it (can only) fails... > > >> This is false. ?As I've pointed out to you before, the FSR does not > >> divide characters up by representation. ?It divides them up by > >> codepoint -- more specifically, by the *bit-width* of the codepoint. > >> We call the internal format of the string "ASCII" or "Latin-1" or > >> "UCS-2" for conciseness and a point of reference, but fundamentally > >> all of the FSR formats are simply byte arrays of *codepoints* -- you > >> know, those things you keep harping on. ?The major optimization > >> performed by the FSR is to consistently truncate the leading zero > >> bytes from each codepoint when it is possible to do so safely. ?But > >> regardless of to what extent this truncation is applied, the string is > >> *always* internally just an array of codepoints, and the same > >> algorithms apply for all representations. > > > ----- > > > You know, we can discuss this ad nauseam. What is important > > is Unicode. > > > You have transformed Python back in an ascii oriented product. > > > If Python had imlemented Unicode correctly, there would > > be no difference in using an "a", "?", "?" or any character, > > what the narrow builds did. > > > If I am practically the only one, who speakes /discusses about > > this, I can ensure you, this has been noticed. > > > Now, it's time to prepare the Asparagus, the "jambon cru" > > and a good bottle a dry white wine. > > > jmf > > You still have yet to explain how Python's string representation is > wrong. Just how it isn't optimal for one specific case. Here's how I > understand it: > > 1) Strings are sequences of stuff. Generally, we talk about strings as > either sequences of bytes or sequences of characters. > > 2) Unicode is a format used to represent characters. Therefore, > Unicode strings are character strings, not byte strings. > > 2) Encodings ?are functions that map characters to bytes. They > typically also define an inverse function that converts from bytes > back to characters. > > 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I > mentioned in the previous point. It happens to be one of the five > standard encodings that is defined for all characters in the Unicode > standard (the others being the little and big endian variants of > UTF-16 and UTF-32). > > 4) The internal representation of a character string DOES NOT MATTER. > All that matters is that the API represents it as a string of > characters, regardless of the representation. We could implement > character strings by putting the Unicode code-points in binary-coded > decimal and it would be a Unicode character string. > > 5) The String type that .NET and Java (and unicode type in Python > narrow builds) use is not a character string. It is a string of > shorts, each of which corresponds to a UTF-16 code point. I know this > is the case because in all of these, the length of "\u1f435" is 2 even > though it only consists of one character. > > 6) The new string representation in Python 3.3 can successfully > represent all characters in the Unicode standard. The actual number of > bytes that each character consumes is invisible to the user. ---------- I shew enough examples. As soon as you are using non latin-1 chars your "optimization" just became irrelevant and not only this, you are penalized. I'm sorry, saying Python now is just covering the whole unicode range is not a valuable excuse. I prefer a "correct" version with a narrower range of chars, especially if this range represents the "daily used chars". I can go a step further, if I wish to write an application for Western European users, I'm better served if I'm using a coding scheme covering all thesee languages/scripts. What about cp1252 [*]? Does this not remind somthing? Python can do better, it only succeeds to do worth! [*] yes, I kwnow, internally .... jmf From wxjmfauth at gmail.com Thu Mar 28 17:33:03 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 28 Mar 2013 14:33:03 -0700 (PDT) Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> Message-ID: <88e569e8-9631-47df-a327-da52addb0ee7@k14g2000vbv.googlegroups.com> On 28 mar, 22:11, jmfauth wrote: > On 28 mar, 21:29, Benjamin Kaplan wrote: > > > > > > > > > > > On Thu, Mar 28, 2013 at 10:48 AM, jmfauth wrote: > > > On 28 mar, 17:33, Ian Kelly wrote: > > >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: > > >> > The flexible string representation takes the problem from the > > >> > other side, it attempts to work with the characters by using > > >> > their representations and it (can only) fails... > > > >> This is false. ?As I've pointed out to you before, the FSR does not > > >> divide characters up by representation. ?It divides them up by > > >> codepoint -- more specifically, by the *bit-width* of the codepoint. > > >> We call the internal format of the string "ASCII" or "Latin-1" or > > >> "UCS-2" for conciseness and a point of reference, but fundamentally > > >> all of the FSR formats are simply byte arrays of *codepoints* -- you > > >> know, those things you keep harping on. ?The major optimization > > >> performed by the FSR is to consistently truncate the leading zero > > >> bytes from each codepoint when it is possible to do so safely. ?But > > >> regardless of to what extent this truncation is applied, the string is > > >> *always* internally just an array of codepoints, and the same > > >> algorithms apply for all representations. > > > > ----- > > > > You know, we can discuss this ad nauseam. What is important > > > is Unicode. > > > > You have transformed Python back in an ascii oriented product. > > > > If Python had imlemented Unicode correctly, there would > > > be no difference in using an "a", "?", "?" or any character, > > > what the narrow builds did. > > > > If I am practically the only one, who speakes /discusses about > > > this, I can ensure you, this has been noticed. > > > > Now, it's time to prepare the Asparagus, the "jambon cru" > > > and a good bottle a dry white wine. > > > > jmf > > > You still have yet to explain how Python's string representation is > > wrong. Just how it isn't optimal for one specific case. Here's how I > > understand it: > > > 1) Strings are sequences of stuff. Generally, we talk about strings as > > either sequences of bytes or sequences of characters. > > > 2) Unicode is a format used to represent characters. Therefore, > > Unicode strings are character strings, not byte strings. > > > 2) Encodings ?are functions that map characters to bytes. They > > typically also define an inverse function that converts from bytes > > back to characters. > > > 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I > > mentioned in the previous point. It happens to be one of the five > > standard encodings that is defined for all characters in the Unicode > > standard (the others being the little and big endian variants of > > UTF-16 and UTF-32). > > > 4) The internal representation of a character string DOES NOT MATTER. > > All that matters is that the API represents it as a string of > > characters, regardless of the representation. We could implement > > character strings by putting the Unicode code-points in binary-coded > > decimal and it would be a Unicode character string. > > > 5) The String type that .NET and Java (and unicode type in Python > > narrow builds) use is not a character string. It is a string of > > shorts, each of which corresponds to a UTF-16 code point. I know this > > is the case because in all of these, the length of "\u1f435" is 2 even > > though it only consists of one character. > > > 6) The new string representation in Python 3.3 can successfully > > represent all characters in the Unicode standard. The actual number of > > bytes that each character consumes is invisible to the user. > > ---------- > > I shew enough examples. As soon as you are using non latin-1 chars > your "optimization" just became irrelevant and not only this, you > are penalized. > > I'm sorry, saying Python now is just covering the whole unicode > range is not a valuable excuse. I prefer a "correct" version with > a narrower range of chars, especially if this range represents > the "daily used chars". > > I can go a step further, if I wish to write an application for > Western European users, I'm better served if I'm using a coding > scheme covering all thesee languages/scripts. What about cp1252 [*]? > Does this not remind somthing? > > Python can do better, it only succeeds to do worth! > > [*] yes, I kwnow, internally .... > > jmf ----- Addendum. And you kwow what? Py34 will suffer from the same desease. You are spending your time in improving chunks of bytes, when the problem is elsewhere. In fact you are working for peanuts, eg the replacing method. If you are not satisfied with my examples, just pick up the examples of GvR (ascii-string) on the bug tracker, "timeit" them and you will see there is already a problem. Better, "timeit" them afeter having replaced his ascii-strings with non ascii characters... jmf and you will see, there is From python at mrabarnett.plus.com Thu Mar 28 17:50:14 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Mar 2013 21:50:14 +0000 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> Message-ID: <5154BB16.4020606@mrabarnett.plus.com> On 28/03/2013 21:11, jmfauth wrote: > On 28 mar, 21:29, Benjamin Kaplan wrote: >> On Thu, Mar 28, 2013 at 10:48 AM, jmfauth wrote: >> > On 28 mar, 17:33, Ian Kelly wrote: >> >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: >> >> > The flexible string representation takes the problem from the >> >> > other side, it attempts to work with the characters by using >> >> > their representations and it (can only) fails... >> >> >> This is false. As I've pointed out to you before, the FSR does not >> >> divide characters up by representation. It divides them up by >> >> codepoint -- more specifically, by the *bit-width* of the codepoint. >> >> We call the internal format of the string "ASCII" or "Latin-1" or >> >> "UCS-2" for conciseness and a point of reference, but fundamentally >> >> all of the FSR formats are simply byte arrays of *codepoints* -- you >> >> know, those things you keep harping on. The major optimization >> >> performed by the FSR is to consistently truncate the leading zero >> >> bytes from each codepoint when it is possible to do so safely. But >> >> regardless of to what extent this truncation is applied, the string is >> >> *always* internally just an array of codepoints, and the same >> >> algorithms apply for all representations. >> >> > ----- >> >> > You know, we can discuss this ad nauseam. What is important >> > is Unicode. >> >> > You have transformed Python back in an ascii oriented product. >> >> > If Python had imlemented Unicode correctly, there would >> > be no difference in using an "a", "?", "?" or any character, >> > what the narrow builds did. >> >> > If I am practically the only one, who speakes /discusses about >> > this, I can ensure you, this has been noticed. >> >> > Now, it's time to prepare the Asparagus, the "jambon cru" >> > and a good bottle a dry white wine. >> >> > jmf >> >> You still have yet to explain how Python's string representation is >> wrong. Just how it isn't optimal for one specific case. Here's how I >> understand it: >> >> 1) Strings are sequences of stuff. Generally, we talk about strings as >> either sequences of bytes or sequences of characters. >> >> 2) Unicode is a format used to represent characters. Therefore, >> Unicode strings are character strings, not byte strings. >> >> 2) Encodings are functions that map characters to bytes. They >> typically also define an inverse function that converts from bytes >> back to characters. >> >> 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I >> mentioned in the previous point. It happens to be one of the five >> standard encodings that is defined for all characters in the Unicode >> standard (the others being the little and big endian variants of >> UTF-16 and UTF-32). >> >> 4) The internal representation of a character string DOES NOT MATTER. >> All that matters is that the API represents it as a string of >> characters, regardless of the representation. We could implement >> character strings by putting the Unicode code-points in binary-coded >> decimal and it would be a Unicode character string. >> >> 5) The String type that .NET and Java (and unicode type in Python >> narrow builds) use is not a character string. It is a string of >> shorts, each of which corresponds to a UTF-16 code point. I know this >> is the case because in all of these, the length of "\u1f435" is 2 even >> though it only consists of one character. >> >> 6) The new string representation in Python 3.3 can successfully >> represent all characters in the Unicode standard. The actual number of >> bytes that each character consumes is invisible to the user. > > ---------- > > > I shew enough examples. As soon as you are using non latin-1 chars > your "optimization" just became irrelevant and not only this, you > are penalized. > > I'm sorry, saying Python now is just covering the whole unicode > range is not a valuable excuse. I prefer a "correct" version with > a narrower range of chars, especially if this range represents > the "daily used chars". > > I can go a step further, if I wish to write an application for > Western European users, I'm better served if I'm using a coding > scheme covering all thesee languages/scripts. What about cp1252 [*]? > Does this not remind somthing? > > Python can do better, it only succeeds to do worth! > > [*] yes, I kwnow, internally .... > If you're that concerned about it, why don't you modify the source code so that the string representation chooses between only 2 bytes and 4 bytes per codepoint, and then see whether that you prefer that situation. How do the memory usage and speed compare? From benjamin.kaplan at case.edu Thu Mar 28 17:52:27 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 28 Mar 2013 14:52:27 -0700 Subject: flaming vs accuracy [was Re: Performance of int/long in Python 3] In-Reply-To: <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <987c4bd9-0e5e-4387-9c78-1075a77d3c47@c6g2000yqh.googlegroups.com> <7f993624-8105-4055-a268-3417e5fe21dc@g4g2000yqd.googlegroups.com> <691c604c-b643-4d66-a2ea-c5c52d603316@c6g2000yqh.googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 2:11 PM, jmfauth wrote: > On 28 mar, 21:29, Benjamin Kaplan wrote: >> On Thu, Mar 28, 2013 at 10:48 AM, jmfauth wrote: >> > On 28 mar, 17:33, Ian Kelly wrote: >> >> On Thu, Mar 28, 2013 at 7:34 AM, jmfauth wrote: >> >> > The flexible string representation takes the problem from the >> >> > other side, it attempts to work with the characters by using >> >> > their representations and it (can only) fails... >> >> >> This is false. As I've pointed out to you before, the FSR does not >> >> divide characters up by representation. It divides them up by >> >> codepoint -- more specifically, by the *bit-width* of the codepoint. >> >> We call the internal format of the string "ASCII" or "Latin-1" or >> >> "UCS-2" for conciseness and a point of reference, but fundamentally >> >> all of the FSR formats are simply byte arrays of *codepoints* -- you >> >> know, those things you keep harping on. The major optimization >> >> performed by the FSR is to consistently truncate the leading zero >> >> bytes from each codepoint when it is possible to do so safely. But >> >> regardless of to what extent this truncation is applied, the string is >> >> *always* internally just an array of codepoints, and the same >> >> algorithms apply for all representations. >> >> > ----- >> >> > You know, we can discuss this ad nauseam. What is important >> > is Unicode. >> >> > You have transformed Python back in an ascii oriented product. >> >> > If Python had imlemented Unicode correctly, there would >> > be no difference in using an "a", "?", "?" or any character, >> > what the narrow builds did. >> >> > If I am practically the only one, who speakes /discusses about >> > this, I can ensure you, this has been noticed. >> >> > Now, it's time to prepare the Asparagus, the "jambon cru" >> > and a good bottle a dry white wine. >> >> > jmf >> >> You still have yet to explain how Python's string representation is >> wrong. Just how it isn't optimal for one specific case. Here's how I >> understand it: >> >> 1) Strings are sequences of stuff. Generally, we talk about strings as >> either sequences of bytes or sequences of characters. >> >> 2) Unicode is a format used to represent characters. Therefore, >> Unicode strings are character strings, not byte strings. >> >> 2) Encodings are functions that map characters to bytes. They >> typically also define an inverse function that converts from bytes >> back to characters. >> >> 3) UTF-8 IS NOT UNICODE. It is an encoding- one of those functions I >> mentioned in the previous point. It happens to be one of the five >> standard encodings that is defined for all characters in the Unicode >> standard (the others being the little and big endian variants of >> UTF-16 and UTF-32). >> >> 4) The internal representation of a character string DOES NOT MATTER. >> All that matters is that the API represents it as a string of >> characters, regardless of the representation. We could implement >> character strings by putting the Unicode code-points in binary-coded >> decimal and it would be a Unicode character string. >> >> 5) The String type that .NET and Java (and unicode type in Python >> narrow builds) use is not a character string. It is a string of >> shorts, each of which corresponds to a UTF-16 code point. I know this >> is the case because in all of these, the length of "\u1f435" is 2 even >> though it only consists of one character. >> >> 6) The new string representation in Python 3.3 can successfully >> represent all characters in the Unicode standard. The actual number of >> bytes that each character consumes is invisible to the user. > > ---------- > > > I shew enough examples. As soon as you are using non latin-1 chars > your "optimization" just became irrelevant and not only this, you > are penalized. > > I'm sorry, saying Python now is just covering the whole unicode > range is not a valuable excuse. I prefer a "correct" version with > a narrower range of chars, especially if this range represents > the "daily used chars". > > I can go a step further, if I wish to write an application for > Western European users, I'm better served if I'm using a coding > scheme covering all thesee languages/scripts. What about cp1252 [*]? > Does this not remind somthing? > > Python can do better, it only succeeds to do worth! > > [*] yes, I kwnow, internally .... > > jmf By that logic, we should all be using ASCII because it's "correct" for the 127 characters that I (as an English speaker) use, and therefore it's all that we should care about. I don't care if ? counts as two characters, it's faster and more memory efficient for all of my strings to just count bytes. There are certain domains where characters outside the basic multilingual plane are used. Python's job is to be correct in all of those circumstances, not just the ones you care about. From rurpy at yahoo.com Wed Mar 27 00:31:44 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 26 Mar 2013 21:31:44 -0700 (PDT) Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: <3364b54c-3547-4f14-be98-69e932da045e@googlegroups.com> On Tuesday, March 26, 2013 6:00:43 PM UTC-6, Ned Deily wrote: > In article , > Mark Lawrence wrote: > > But you are an idiot. > > I repeat the friendly reminder I posted a few weeks ago and I'll be a > little less oblique: please avoid gratuitous personal attacks here. It > reflects badly on the group and especially on those people making them. > We can disagree strongly about technical opinions without resorting to > such. >[..] +1, thank you for posting that. From rosuav at gmail.com Tue Mar 26 16:52:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 07:52:09 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 7:44 AM, jmfauth wrote: > On 26 mar, 20:03, Chris Angelico wrote: >> On Wed, Mar 27, 2013 at 5:50 AM, jmfauth wrote: >> > On 25 mar, 22:51, Chris Angelico wrote: >> >> The Python 3 merge of int and long has effectively penalized >> >> small-number arithmetic by removing an optimization. As we've seen >> >> from PEP 393 strings (jmf aside), there can be huge benefits from >> >> having a single type with multiple representations internally ... >> >> > ------ >> >> > A character is not an integer (short form). >> >> So? >> >> ChrisA > > A character is not an integer. Yes, I heard you the first time. And I repeat: A needle pulling thread? You have not made any actual, uhh, _point_. ChrisA From invalid at invalid.invalid Tue Mar 26 17:08:55 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 26 Mar 2013 21:08:55 +0000 (UTC) Subject: Performance of int/long in Python 3 References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On 2013-03-26, Mark Lawrence wrote: > On 26/03/2013 20:44, jmfauth wrote: >>> >>>> A character is not an integer (short form). >>> >>> So? >> >> A character is not an integer. >> >> jmf > > But you are an idiot. I think we all agree that jmf is a character. So we've established that no characters are integers, but some characters are idiots. Does that allow us to determine wheter integers are idiots or not? -- Grant Edwards grant.b.edwards Yow! All of life is a blur at of Republicans and meat! gmail.com From rosuav at gmail.com Tue Mar 26 17:14:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 08:14:46 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards wrote: > On 2013-03-26, Mark Lawrence wrote: >> On 26/03/2013 20:44, jmfauth wrote: >>>> >>>>> A character is not an integer (short form). >>>> >>>> So? >>> >>> A character is not an integer. >>> >>> jmf >> >> But you are an idiot. > > I think we all agree that jmf is a character. > > So we've established that no characters are integers, but some > characters are idiots. > > Does that allow us to determine wheter integers are idiots or not? No, it doesn't. I'm fairly confident that most of them are not... however, I have my eye on 42. He gets around, a bit, but never seems to do anything very useful. I'd think twice before hiring him. But 1, now, he's a good fellow. Even when things get divisive, he's the voice of unity. ChrisA From breamoreboy at yahoo.co.uk Tue Mar 26 17:26:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 26 Mar 2013 21:26:30 +0000 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: On 26/03/2013 21:14, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards wrote: >> On 2013-03-26, Mark Lawrence wrote: >>> On 26/03/2013 20:44, jmfauth wrote: >>>>> >>>>>> A character is not an integer (short form). >>>>> >>>>> So? >>>> >>>> A character is not an integer. >>>> >>>> jmf >>> >>> But you are an idiot. >> >> I think we all agree that jmf is a character. >> >> So we've established that no characters are integers, but some >> characters are idiots. >> >> Does that allow us to determine wheter integers are idiots or not? > > No, it doesn't. I'm fairly confident that most of them are not... > however, I have my eye on 42. He gets around, a bit, but never seems > to do anything very useful. I'd think twice before hiring him. > > But 1, now, he's a good fellow. Even when things get divisive, he's > the voice of unity. > > ChrisA > Which reminds me, why do people on newsgroups often refer to 101, my favourite number? I mean, do we really care about the number of a room that Eric Blair worked in when he was at the BBC? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From davea at davea.name Tue Mar 26 17:28:41 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 17:28:41 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: <51521309.9020405@davea.name> On 03/26/2013 05:14 PM, Chris Angelico wrote: > >> Does that allow us to determine wheter integers are idiots or not? > > No, it doesn't. I'm fairly confident that most of them are not... > however, I have my eye on 42. He gets around, a bit, but never seems > to do anything very useful. I'd think twice before hiring him. Ah, 42, the "Answer to Life, the Universe, and Everything" -- DaveA From greg.ewing at canterbury.ac.nz Tue Mar 26 19:10:10 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 27 Mar 2013 12:10:10 +1300 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: > On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards wrote: > >>Does that allow us to determine wheter integers are idiots or not? > > No, it doesn't. I'm fairly confident that most of them are not... > however, I have my eye on 42. He thought he was equal to 6 x 9 at one point, which seems pretty idiotic to me. -- Greg From davea at davea.name Tue Mar 26 19:19:15 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 19:19:15 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: <51522CF3.6000606@davea.name> On 03/26/2013 07:10 PM, Gregory Ewing wrote: >> On Wed, Mar 27, 2013 at 8:08 AM, Grant Edwards >> wrote: >> >>> Does that allow us to determine wheter integers are idiots or not? >> >> No, it doesn't. I'm fairly confident that most of them are not... >> however, I have my eye on 42. > > He thought he was equal to 6 x 9 at one point, which > seems pretty idiotic to me. > Not in base 13. -- DaveA From wxjmfauth at gmail.com Wed Mar 27 16:30:24 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 27 Mar 2013 13:30:24 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <0b779c80-4f50-4716-8c30-47755c15f304@m12g2000yqp.googlegroups.com> Message-ID: <25522028-49d3-477b-b5e0-f0c1e3a6d3cf@u20g2000yqj.googlegroups.com> On 26 mar, 22:08, Grant Edwards wrote: > > I think we all agree that jmf is a character. > ------ The characters are also "intrisic characteristics" of a group in the Group Theory. If you are not a mathematician, but eg a scientist in need of these characters, they are available in "precalculated" tables, one shorly calls ... "Tables of characters" ! (My booklet of the tables is titled "Tables for Group Theory") Example in chemistry, mainly "quantum chemistry": Group Theory and its Application to Chemistry http://chemwiki.ucdavis.edu/Physical_Chemistry/Symmetry/Group_Theory%3A_Application (Copied link from Firefox). jmf From steve+comp.lang.python at pearwood.info Mon Mar 25 20:17:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 00:17:04 GMT Subject: Performance of int/long in Python 3 References: Message-ID: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Mar 2013 16:16:05 -0700, Ethan Furman wrote: > On 03/25/2013 02:51 PM, Chris Angelico wrote: >> Python 3's int is faster than Python 2's long, but slower than Python >> 2's int. So the question really is, would a two-form representation be >> beneficial, and if so, is it worth the coding trouble? > > I'm inclined to say it's not worth the trouble. If you're working with > numbers, and speed is an issue, you really should be using one of the > numeric or scientific packages out there. Or PyPy, which will probably optimize it just fine. Also, speaking as somebody who remembers a time when ints where not automatically promoted to longs (introduced in, Python 2.2, I think?) let me say that having a single unified int type is *fantastic*, and managing ints/longs by hand is a right royal PITA. What I would like to see though is a module where I can import fixed- width signed and unsigned integers that behave like in C, complete with overflow, for writing code that matches the same behaviour as other languages. -- Steven From rosuav at gmail.com Mon Mar 25 20:28:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 11:28:25 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 26, 2013 at 11:17 AM, Steven D'Aprano wrote: > Also, speaking as somebody who remembers a time when ints where not > automatically promoted to longs (introduced in, Python 2.2, I think?) let > me say that having a single unified int type is *fantastic*, and managing > ints/longs by hand is a right royal PITA. Oh, I absolutely agree! I'm just looking at performance here, but definitely the int/long unification is a Good Thing. ChrisA From oscar.j.benjamin at gmail.com Mon Mar 25 20:49:42 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 26 Mar 2013 00:49:42 +0000 Subject: Performance of int/long in Python 3 In-Reply-To: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26 March 2013 00:17, Steven D'Aprano wrote: > On Mon, 25 Mar 2013 16:16:05 -0700, Ethan Furman wrote: > [snip] >> If you're working with >> numbers, and speed is an issue, you really should be using one of the >> numeric or scientific packages out there. > [snip] > What I would like to see though is a module where I can import fixed- > width signed and unsigned integers that behave like in C, complete with > overflow, for writing code that matches the same behaviour as other > languages. Numpy can do this: >>> import numpy >>> a = numpy.array([0], numpy.uint32) >>> a array([0], dtype=uint32) >>> a[0] = -1 >>> a array([4294967295], dtype=uint32) Unfortunately it doesn't work with numpy "scalars", so to use this without the index syntax you'd need a wrapper class. Also it uses Python style floor rounding rather than truncation as in C (actually I seem to remember discovering that in C this is implementation defined). Presumably ctypes has something like this as well. Oscar From roy at panix.com Mon Mar 25 20:55:03 2013 From: roy at panix.com (Roy Smith) Date: Mon, 25 Mar 2013 20:55:03 -0400 Subject: Performance of int/long in Python 3 References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5150e900$0$29998$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Also, speaking as somebody who remembers a time when ints where not > automatically promoted to longs (introduced in, Python 2.2, I think?) let > me say that having a single unified int type is *fantastic*, And incredibly useful when solving Project Euler problems :-) [I remember when strings didn't have methods] From steve+comp.lang.python at pearwood.info Tue Mar 26 01:01:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 05:01:41 GMT Subject: Performance of int/long in Python 3 References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51512bb5$0$29973$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Mar 2013 20:55:03 -0400, Roy Smith wrote: > In article <5150e900$0$29998$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> Also, speaking as somebody who remembers a time when ints where not >> automatically promoted to longs (introduced in, Python 2.2, I think?) >> let me say that having a single unified int type is *fantastic*, > > And incredibly useful when solving Project Euler problems :-) > > [I remember when strings didn't have methods] No string methods? You were lucky. When I were a lad, you couldn't even use "" delimiters for strings. >>> "b string" Parsing error: file , line 1: "b string" ^ Unhandled exception: run-time error: syntax error Python 0.9.1. -- Steven From rosuav at gmail.com Tue Mar 26 02:12:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 17:12:06 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <51512bb5$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> <51512bb5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 26, 2013 at 4:01 PM, Steven D'Aprano > No string methods? You were lucky. When I were a lad, you couldn't even > use "" delimiters for strings. > >>>> "b string" > Parsing error: file , line 1: > "b string" > ^ > Unhandled exception: run-time error: syntax error > > > Python 0.9.1. Well of course that's an error. Anyone can see it should have been: >>> "a string" *duck* ChrisA From roy at panix.com Tue Mar 26 09:18:25 2013 From: roy at panix.com (Roy Smith) Date: Tue, 26 Mar 2013 09:18:25 -0400 Subject: Performance of int/long in Python 3 References: <5150e900$0$29998$c3e8da3$5496439d@news.astraweb.com> <51512bb5$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51512bb5$0$29973$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Mon, 25 Mar 2013 20:55:03 -0400, Roy Smith wrote: > > > In article <5150e900$0$29998$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> Also, speaking as somebody who remembers a time when ints where not > >> automatically promoted to longs (introduced in, Python 2.2, I think?) > >> let me say that having a single unified int type is *fantastic*, > > > > And incredibly useful when solving Project Euler problems :-) > > > > [I remember when strings didn't have methods] > > No string methods? You were lucky. When I were a lad, you couldn't even > use "" delimiters for strings. > > >>> "b string" > Parsing error: file , line 1: > "b string" > ^ > Unhandled exception: run-time error: syntax error > > > Python 0.9.1. OK, you've got me beat. For Python. Am I going to have to go dig out my old IBM-1130 assembler decks? From i at introo.me Tue Mar 26 00:24:11 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 12:24:11 +0800 Subject: python3 string format Message-ID: HI. one thing confuses me. It is said in the pep3101 that "{}".format (x) will invoke the method x.__format__ However, I looked at the src of python3 and found: in class str(object), the format simply contains a pass statement in class int(object), things is the same. So, what's the mechanism that "{}" works? Thx -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Mar 26 02:16:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Mar 2013 00:16:48 -0600 Subject: python3 string format In-Reply-To: References: Message-ID: On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma wrote: > HI. > one thing confuses me. > It is said in the pep3101 that "{}".format (x) will invoke the method > x.__format__ > However, I looked at the src of python3 and found: > in class str(object), the format simply contains a pass statement > in class int(object), things is the same. I don't know what source you're looking at. In CPython, both of those types are implemented in C, not Python, so there would be no pass statements involved. The int.__format__ method is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373 It mainly just calls the _PyLong_FormatAdvancedWriter function, which is at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399 The str.__format__ method similarly is implemented at: http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851 and calls the _PyUnicode_FormatAdvancedWriter function at: http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363 From i at introo.me Tue Mar 26 06:51:10 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 18:51:10 +0800 Subject: python3 string format In-Reply-To: References: Message-ID: Thx for your reply. I am using pycharm and simply press "go to declaration" which directs me to a py file, containing the following code: def format(*args, **kwargs): # known special case of str.format """ S.format(*args, **kwargs) -> string Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). """ pass I am curious how you find the corresponding c source code. On Tue, Mar 26, 2013 at 2:16 PM, Ian Kelly wrote: > On Mon, Mar 25, 2013 at 10:24 PM, Shiyao Ma wrote: > > HI. > > one thing confuses me. > > It is said in the pep3101 that "{}".format (x) will invoke the method > > x.__format__ > > However, I looked at the src of python3 and found: > > in class str(object), the format simply contains a pass statement > > in class int(object), things is the same. > > I don't know what source you're looking at. In CPython, both of those > types are implemented in C, not Python, so there would be no pass > statements involved. > > The int.__format__ method is implemented at: > > http://hg.python.org/cpython/file/3c437e591499/Objects/longobject.c#l4373 > > It mainly just calls the _PyLong_FormatAdvancedWriter function, which is > at: > > > http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1399 > > The str.__format__ method similarly is implemented at: > > > http://hg.python.org/cpython/file/3c437e591499/Objects/unicodeobject.c#l12851 > > and calls the _PyUnicode_FormatAdvancedWriter function at: > > > http://hg.python.org/cpython/file/3c437e591499/Python/formatter_unicode.c#l1363 > -- > http://mail.python.org/mailman/listinfo/python-list > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Mar 26 11:07:13 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 26 Mar 2013 09:07:13 -0600 Subject: python3 string format In-Reply-To: References: Message-ID: On Tue, Mar 26, 2013 at 4:51 AM, Shiyao Ma wrote: > Thx for your reply. > I am using pycharm and simply press "go to declaration" which directs me to > a py file, containing the following code: > def format(*args, **kwargs): # known special case of str.format > """ > S.format(*args, **kwargs) -> string > > Return a formatted version of S, using substitutions from args and > kwargs. > The substitutions are identified by braces ('{' and '}'). > """ > pass I would guess that Python declaration is maintained and used by PyCharm for code intelligence. > I am curious how you find the corresponding c source code. The str object is mostly implemented in Objects/unicodeobject.c. The int object is mostly implemented in Objects/longobject.c. Other built-in types can also be found in that directory. Each has a PyMethodDef[] global array that declares the implementations of the object's methods. Finding the implementation is then just a matter of grepping the source for its name. The function I pointed you to before implements the str.__format__ method. The str.format method itself is at: http://hg.python.org/cpython/file/84e73ace3d7e/Objects/stringlib/unicode_format.h#l942 I'm not sure why that one is implemented in a .h file. From i at introo.me Tue Mar 26 02:17:27 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 14:17:27 +0800 Subject: At a loss on python scoping. Message-ID: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r) # this should print 5, but where does py store the name of r a.func(3) print(a.s) # this should print 3, also where does py store this name. what's the underlying difference between the above example? -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From i at introo.me Tue Mar 26 02:19:21 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 14:19:21 +0800 Subject: At a loss on python scoping. In-Reply-To: References: Message-ID: PS, I now python's scoping rule is lexical rule (aka static rule). How does LEGB apply to class? On Tue, Mar 26, 2013 at 2:17 PM, Shiyao Ma wrote: > Hi, > suppose I have a file like this: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r) # this should print 5, but where does py store the name of r > > a.func(3) > print(a.s) # this should print 3, also where does py store this name. > what's the underlying difference between the above example? > > > -- > My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 > > More on: http://about.me/introom > > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Mar 26 02:29:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 17:29:04 +1100 Subject: At a loss on python scoping. In-Reply-To: References: Message-ID: On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma wrote: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r) # this should print 5, but where does py store the name of r What do you mean by "the name of r"? ChrisA From i at introo.me Tue Mar 26 06:35:28 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 18:35:28 +0800 Subject: At a loss on python scoping. In-Reply-To: References: Message-ID: Sorry for my obscure description. "the name of r" , AFAIK, everything in python is just a reference. For example, a = 3, means a points to a small integer; b= [] means b points to a list somewhere in the memory. So I call r as the name of r. To clarify my question. say I wanna look up a.r I guess the first step is to look inside a, maybe in the __dict__? As proved in my ipython, the __dict__ is empty. So, it will look up in A.__dict__ Here comes my first question, where does the scope of class A falls in when considering LEGB. On Tue, Mar 26, 2013 at 2:29 PM, Chris Angelico wrote: > On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma wrote: > > class A: > > r = 5 > > def func(self, s): > > self.s = s > > a = A() > > print(a.r) # this should print 5, but where does py store the name of > r > > What do you mean by "the name of r"? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Mar 26 03:19:17 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Mar 2013 03:19:17 -0400 Subject: At a loss on python scoping. In-Reply-To: References: Message-ID: On 3/26/2013 2:17 AM, Shiyao Ma wrote: > Hi, > suppose I have a file like this: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r) # this should print 5, but where does py store the name of r > > a.func(3) > print(a.s) # this should print 3, also where does py store this name. > what's the underlying difference between the above example? For CPython, both the class A and the instance a have a .__dict__ attribute that stores names and values. But that is intended to be hidden and transparent for normal usage. -- Terry Jan Reedy From davea at davea.name Tue Mar 26 06:07:44 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 06:07:44 -0400 Subject: At a loss on python scoping. In-Reply-To: References: Message-ID: <51517370.4060305@davea.name> On 03/26/2013 02:17 AM, Shiyao Ma wrote: > Hi, > suppose I have a file like this: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r) # this should print 5, but where does py store the name of r > > a.func(3) > print(a.s) # this should print 3, also where does py store this name. > what's the underlying difference between the above example? > I don't think this is a scoping question at all. These references are fully qualified, so scoping doesn't enter in. The class A has a dictionary containing the names of r and func. These are class attributes. Each instance has a dictionary which will contain the name s AFTER the A.func() is called. Ideally such an attribute will be assigned in the __init__() method, in which case every instance will have s in its dictionary. When you use a.qqq the attribute qqq is searched for in the instance dictionary and, if not found, in the class dictionary. If still not found, in the parent classes' dictionary(s). You can use dir(A) and dir(a) to look at these dictionaries, but it shows you the combination of them, so it's not as clear. In other words, dir(a) shows you both dictionaries, merged. (Seems to me dir also sometimes censors some of the names, but that's a vague memory. It's never left out anything I cared about, so maybe it's things like single-underscore names, or maybe just a poor memory.) -- DaveA From i at introo.me Tue Mar 26 07:03:40 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 19:03:40 +0800 Subject: At a loss on python scoping. In-Reply-To: <51517370.4060305@davea.name> References: <51517370.4060305@davea.name> Message-ID: Thx, really a nice and detailed explanation. On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > On 03/26/2013 02:17 AM, Shiyao Ma wrote: > >> Hi, >> suppose I have a file like this: >> class A: >> r = 5 >> def func(self, s): >> self.s = s >> a = A() >> print(a.r) # this should print 5, but where does py store the name of r >> >> a.func(3) >> print(a.s) # this should print 3, also where does py store this name. >> what's the underlying difference between the above example? >> >> > I don't think this is a scoping question at all. These references are > fully qualified, so scoping doesn't enter in. > > The class A has a dictionary containing the names of r and func. These > are class attributes. Each instance has a dictionary which will contain > the name s AFTER the A.func() is called. Ideally such an attribute will be > assigned in the __init__() method, in which case every instance will have s > in its dictionary. > > When you use a.qqq the attribute qqq is searched for in the instance > dictionary and, if not found, in the class dictionary. If still not found, > in the parent classes' dictionary(s). > > You can use dir(A) and dir(a) to look at these dictionaries, but it shows > you the combination of them, so it's not as clear. In other words, dir(a) > shows you both dictionaries, merged. (Seems to me dir also sometimes > censors some of the names, but that's a vague memory. It's never left out > anything I cared about, so maybe it's things like single-underscore names, > or maybe just a poor memory.) > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From i at introo.me Tue Mar 26 07:14:22 2013 From: i at introo.me (Shiyao Ma) Date: Tue, 26 Mar 2013 19:14:22 +0800 Subject: At a loss on python scoping. In-Reply-To: References: <51517370.4060305@davea.name> Message-ID: After read Dave's answer, I think I confused LEGB with attribute lookup. So, a.r has nothing to do with LEGB. On Tue, Mar 26, 2013 at 7:03 PM, Shiyao Ma wrote: > Thx, really a nice and detailed explanation. > > > On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > >> On 03/26/2013 02:17 AM, Shiyao Ma wrote: >> >>> Hi, >>> suppose I have a file like this: >>> class A: >>> r = 5 >>> def func(self, s): >>> self.s = s >>> a = A() >>> print(a.r) # this should print 5, but where does py store the name of >>> r >>> >>> a.func(3) >>> print(a.s) # this should print 3, also where does py store this name. >>> what's the underlying difference between the above example? >>> >>> >> I don't think this is a scoping question at all. These references are >> fully qualified, so scoping doesn't enter in. >> >> The class A has a dictionary containing the names of r and func. These >> are class attributes. Each instance has a dictionary which will contain >> the name s AFTER the A.func() is called. Ideally such an attribute will be >> assigned in the __init__() method, in which case every instance will have s >> in its dictionary. >> >> When you use a.qqq the attribute qqq is searched for in the instance >> dictionary and, if not found, in the class dictionary. If still not found, >> in the parent classes' dictionary(s). >> >> You can use dir(A) and dir(a) to look at these dictionaries, but it shows >> you the combination of them, so it's not as clear. In other words, dir(a) >> shows you both dictionaries, merged. (Seems to me dir also sometimes >> censors some of the names, but that's a vague memory. It's never left out >> anything I cared about, so maybe it's things like single-underscore names, >> or maybe just a poor memory.) >> >> >> -- >> DaveA >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > > -- > My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 > > More on: http://about.me/introom > > -- My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736 More on: http://about.me/introom -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Mar 26 08:43:29 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2013 12:43:29 GMT Subject: At a loss on python scoping. References: Message-ID: <515197f1$0$29998$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Mar 2013 14:19:21 +0800, Shiyao Ma wrote: > PS, I now python's scoping rule is lexical rule (aka static rule). How > does LEGB apply to class? It doesn't. Python does not use the same lookup rules for attributes and unqualified names. Attribute lookups follow inheritance rules. `instance.name` searches in this order, from first to last: if it exists, call instance.__class__.__getattribute__(name); look in the instance __dict__; look in the class __dict__; for each superclass in the inheritance chain: look in the superclass __dict__; if it exists, call instance.__class__.__getattr__(name) (the above is a little simplified, but is close enough for ordinary work). Unqualified `name` follow this lookup rule: if name is recognised by the compiler as a local name: look in the local function namespace; otherwise: look in any enclosing function scopes; look in the global scope; look in the builtins. -- Steven From georg at python.org Tue Mar 26 02:47:38 2013 From: georg at python.org (Georg Brandl) Date: Tue, 26 Mar 2013 07:47:38 +0100 Subject: [RELEASED] Python 3.2.4 rc 1 and Python 3.3.1 rc 1 Message-ID: <5151448A.2010103@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the first release candidates of Python 3.2.4 and 3.3.1. Python 3.2.4 will be the last regular maintenance release for the Python 3.2 series, while Python 3.3.1 is the first maintenance release for the 3.3 series. Both releases include hundreds of bugfixes. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. These releases do not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml These are testing releases: Please consider trying them with your code and reporting any bugs you may notice to: http://bugs.python.org/ To download Python 3.2.4 or Python 3.3.1, visit: http://www.python.org/download/releases/3.2.4/ or http://www.python.org/download/releases/3.3.1/ respectively. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and all contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlFRRIoACgkQN9GcIYhpnLD6jACgnzYdYRKZ4kwkKeN3zSLSZ3Zr M/IAn17vlpxI3a3xk+i/ODOrCkMnRZro =B5sA -----END PGP SIGNATURE----- From timothy.crosley at gmail.com Tue Mar 26 04:54:15 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Tue, 26 Mar 2013 01:54:15 -0700 (PDT) Subject: Screencast: Creating and deploying an advanced python web application in under 15 minutes! Message-ID: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> Hi, I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI I hope some of you find it useful, Thanks! Timothy From timothy.crosley at gmail.com Fri Mar 29 09:53:21 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 29 Mar 2013 06:53:21 -0700 (PDT) Subject: Screencast: Creating and deploying an advanced python web application in under 15 minutes! In-Reply-To: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> References: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> Message-ID: I apologize for the audio from the original screen cast, it was really sub-par. I bought a new microphone and re-recorded it: http://www.youtube.com/watch?v=0L8TsmrZPLg&feature=youtu.be Thanks! Timothy On Tuesday, March 26, 2013 4:54:15 AM UTC-4, timothy crosley wrote: > Hi, > > > > I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI > > > > I hope some of you find it useful, > > > > Thanks! > > > > Timothy From kliateni at gmail.com Fri Mar 29 10:47:41 2013 From: kliateni at gmail.com (Karim) Date: Fri, 29 Mar 2013 15:47:41 +0100 Subject: Screencast: Creating and deploying an advanced python web application in under 15 minutes! In-Reply-To: References: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> Message-ID: <5155A98D.3090104@gmail.com> On 29/03/2013 14:53, timothy crosley wrote: > I apologize for the audio from the original screen cast, it was really sub-par. I bought a new microphone and re-recorded it: http://www.youtube.com/watch?v=0L8TsmrZPLg&feature=youtu.be > > Thanks! > > Timothy > > On Tuesday, March 26, 2013 4:54:15 AM UTC-4, timothy crosley wrote: >> Hi, >> >> >> >> I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI >> >> >> >> I hope some of you find it useful, >> >> >> >> Thanks! >> >> >> >> Timothy Hi Timothy, Very interesting! Thx a lot! Cheers Karim From timothy.crosley at gmail.com Fri Mar 29 21:14:40 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 29 Mar 2013 18:14:40 -0700 (PDT) Subject: Screencast: Creating and deploying an advanced python web application in under 15 minutes! In-Reply-To: References: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> Message-ID: <591914fc-4c33-4970-a11f-460748cd2399@googlegroups.com> Thanks Karim! On Friday, March 29, 2013 10:47:41 AM UTC-4, Karim wrote: > On 29/03/2013 14:53, timothy crosley wrote: > > > I apologize for the audio from the original screen cast, it was really sub-par. I bought a new microphone and re-recorded it: http://www.youtube.com/watch?v=0L8TsmrZPLg&feature=youtu.be > > > > > > Thanks! > > > > > > Timothy > > > > > > On Tuesday, March 26, 2013 4:54:15 AM UTC-4, timothy crosley wrote: > > >> Hi, > > >> > > >> > > >> > > >> I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI > > >> > > >> > > >> > > >> I hope some of you find it useful, > > >> > > >> > > >> > > >> Thanks! > > >> > > >> > > >> > > >> Timothy > > Hi Timothy, > > > > Very interesting! > > > > Thx a lot! > > Cheers > > Karim From timothy.crosley at gmail.com Fri Mar 29 21:14:40 2013 From: timothy.crosley at gmail.com (timothy crosley) Date: Fri, 29 Mar 2013 18:14:40 -0700 (PDT) Subject: Screencast: Creating and deploying an advanced python web application in under 15 minutes! In-Reply-To: References: <0c2af3b0-1864-46f5-b93d-6cb0ec12e210@googlegroups.com> Message-ID: <591914fc-4c33-4970-a11f-460748cd2399@googlegroups.com> Thanks Karim! On Friday, March 29, 2013 10:47:41 AM UTC-4, Karim wrote: > On 29/03/2013 14:53, timothy crosley wrote: > > > I apologize for the audio from the original screen cast, it was really sub-par. I bought a new microphone and re-recorded it: http://www.youtube.com/watch?v=0L8TsmrZPLg&feature=youtu.be > > > > > > Thanks! > > > > > > Timothy > > > > > > On Tuesday, March 26, 2013 4:54:15 AM UTC-4, timothy crosley wrote: > > >> Hi, > > >> > > >> > > >> > > >> I've created a screen cast showing how a message board with live-validation and Ajax calls written in python can be built and deployed in under 15 minutes. You can view it here: http://www.youtube.com/watch?v=ucougrZK9wI > > >> > > >> > > >> > > >> I hope some of you find it useful, > > >> > > >> > > >> > > >> Thanks! > > >> > > >> > > >> > > >> Timothy > > Hi Timothy, > > > > Very interesting! > > > > Thx a lot! > > Cheers > > Karim From svenito at gmail.com Tue Mar 26 06:07:00 2013 From: svenito at gmail.com (Sven) Date: Tue, 26 Mar 2013 10:07:00 +0000 Subject: Processing user input as it's entered Message-ID: Hello, Is there a way (ideally cross platform but a *nix OS solution would be great) to process user input as they type? What I aim to achieve is to count the number of characters a user has entered and display it while they are typing. The entered text will also need to be captured once the user has finished typing. This is a gui-less CLI tool for python 2.7 I've seen some information on tty.setraw but I'm not sure how you'd go about wiring that up. Thanks -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Tue Mar 26 10:41:32 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 26 Mar 2013 14:41:32 +0000 Subject: Processing user input as it's entered In-Reply-To: References: Message-ID: On 26 March 2013 10:07, Sven wrote: > Hello, > > Is there a way (ideally cross platform but a *nix OS solution would be > great) to process user input as they type? > What I aim to achieve is to count the number of characters a user has > entered and display it while they are typing. The entered text will also > need to be captured once the user has finished typing. > > This is a gui-less CLI tool for python 2.7 > > I've seen some information on tty.setraw but I'm not sure how you'd go about > wiring that up. Can you use curses (http://docs.python.org/2/library/curses.html) -- Arnaud From svenito at gmail.com Tue Mar 26 11:19:59 2013 From: svenito at gmail.com (Sven) Date: Tue, 26 Mar 2013 15:19:59 +0000 Subject: Processing user input as it's entered In-Reply-To: References: Message-ID: On 26 March 2013 14:41, Arnaud Delobelle wrote: > On 26 March 2013 10:07, Sven wrote: > > Hello, > > > > Is there a way (ideally cross platform but a *nix OS solution would be > > great) to process user input as they type? > > What I aim to achieve is to count the number of characters a user has > > entered and display it while they are typing. The entered text will also > > need to be captured once the user has finished typing. > > > > This is a gui-less CLI tool for python 2.7 > > > > I've seen some information on tty.setraw but I'm not sure how you'd go > about > > wiring that up. > > Can you use curses (http://docs.python.org/2/library/curses.html This could work. I've not used it before so I am having some issues echoing out the text. I assume I can use this without having to create an ncurses UI? -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From kidoman3 at gmail.com Tue Mar 26 06:30:13 2013 From: kidoman3 at gmail.com (kidoman3 at gmail.com) Date: Tue, 26 Mar 2013 03:30:13 -0700 (PDT) Subject: JES account balance function help urgent! Message-ID: I am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction. You'll also need a global variable (balance?) to maintain the running balance of the account. 1. def setBalance(amt): # Defines (but doesn't print) the value of the account balance 2. def printBalance(): # Displays current balance as a money value with a heading 3. def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted 4. def deposit (date, details, amount): # Alter the balance and print ledger line 5. def withdraw(date, details, amount): # Alter the balance and print ledger line Your task is to: complete the five (very short) functions by creating the code for the body of each function, and demonstrate that you code works by calling the functions, as is demonstrated below. So when these functions are called e.g. setBalance(500) printBalance() withdraw("17-12-2012", "BP - petrol", 72.50) withdraw("19-12-2012", "Countdown", 55.50) withdraw("20-12-2012", "munchies", 1.99) withdraw("22-12-2012", "Vodafone", 20) deposit ("23-12-2012", "Income", 225) withdraw("24-12-2012", "Presents", 99.02) printBalance() The output is something like this: Current Balance is $ 500.00 17-12-2012 BP - petrol $ 72.50 $ 427.50 19-12-2012 Countdown $ 55.50 $ 372.00 20-12-2012 munchies $ 1.99 $ 370.01 22-12-2012 Vodafone $ 20.00 $ 350.01 23-12-2012 Income $ 225.00 $ 575.01 24-12-2012 Presents $ 99.02 $ 475.99 Current Balance is $ 475.99 So far i got: def setBalance(amount): global balance assert isinstance(amount,numbers.number) balance = euros printNow(balance) Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment thnx From davea at davea.name Tue Mar 26 06:56:13 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 06:56:13 -0400 Subject: JES account balance function help urgent! In-Reply-To: References: Message-ID: <51517ECD.4010506@davea.name> On 03/26/2013 06:30 AM, kidoman3 at gmail.com wrote: > I am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help > > The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction. > > You'll also need a global variable (balance?) to maintain the running balance of the account. > > 1. def setBalance(amt): # Defines (but doesn't print) the value of the account balance > > 2. def printBalance(): # Displays current balance as a money value with a heading > > 3. def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted > > 4. def deposit (date, details, amount): # Alter the balance and print ledger line > > 5. def withdraw(date, details, amount): # Alter the balance and print ledger line > > Your task is to: > complete the five (very short) functions by creating the code for the body of each function, and > demonstrate that you code works by calling the functions, as is demonstrated below. > > So when these functions are called > e.g. > > setBalance(500) > printBalance() > withdraw("17-12-2012", "BP - petrol", 72.50) > withdraw("19-12-2012", "Countdown", 55.50) > withdraw("20-12-2012", "munchies", 1.99) > withdraw("22-12-2012", "Vodafone", 20) > deposit ("23-12-2012", "Income", 225) > withdraw("24-12-2012", "Presents", 99.02) > printBalance() > The output is something like this: > > Current Balance is $ 500.00 > 17-12-2012 BP - petrol $ 72.50 $ 427.50 > 19-12-2012 Countdown $ 55.50 $ 372.00 > 20-12-2012 munchies $ 1.99 $ 370.01 > 22-12-2012 Vodafone $ 20.00 $ 350.01 > 23-12-2012 Income $ 225.00 $ 575.01 > 24-12-2012 Presents $ 99.02 $ 475.99 > Current Balance is $ 475.99 > > So far i got: > def setBalance(amount): > global balance > assert isinstance(amount,numbers.number) > balance = euros > printNow(balance) > > Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment > thnx > I'm not sure how literally to take your proposal. You have no indentation in the function body, so that's one serious problem. And you're apparently calling printNow() from within that function, which is NOT what was called for. And the function takes "amount" as its parameter, but then uses 'euros' in the body. That's a big spelling error. You're also going to need to import numbers, if you want that isinstance to work. The layout of your code should be something like: shebang line (optional) imports global variables def's testing code (supplied by instructor) Write all the functions, making sure each takes the expected parameters, even if the function does nothing more than print its name and parameters. Then when the code runs, refine the function bodies till they're all correct. -- DaveA From nospam at nospam.com Tue Mar 26 08:26:14 2013 From: nospam at nospam.com (Gilles) Date: Tue, 26 Mar 2013 13:26:14 +0100 Subject: [WSGI] Tell Python to listen to LAN interface? Message-ID: Hello I'm following this tutorial to learn about writing Python apps in WSGI: http://webpython.codepoint.net/wsgi_tutorial On a Linux host with Python 2.6.6 installed, I launched the "Environment dictionary" sample, but can't connect to it from my remote Windows host since the application only accepts local queries: # netstat -tunlp ... tcp 0 0 127.0.0.1:8051 0.0.0.0:* LISTEN 13110/python How can I tell the Python interpreter to listen on 0.0.0.0 or at least 192.168.0.0/24? Thank you. From rosuav at gmail.com Tue Mar 26 08:50:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2013 23:50:36 +1100 Subject: [WSGI] Tell Python to listen to LAN interface? In-Reply-To: References: Message-ID: On Tue, Mar 26, 2013 at 11:26 PM, Gilles wrote: > Hello > > I'm following this tutorial to learn about writing Python apps in > WSGI: > > http://webpython.codepoint.net/wsgi_tutorial I'm guessing you're using the initialization code from here? http://webpython.codepoint.net/wsgi_environment_dictionary According to the docstring, the first argument to make_server() is the host name to bind to. Using "localhost" means you're bound to 127.0.0.1, as you see. Use your LAN IP address there, or "" to bind to all local addresses - or possibly "::" to bind to all IPv6 addresses (try it and see - some systems work with one or the other, others work happily with both together). ChrisA From nospam at nospam.com Tue Mar 26 08:59:31 2013 From: nospam at nospam.com (Gilles) Date: Tue, 26 Mar 2013 13:59:31 +0100 Subject: [WSGI] Tell Python to listen to LAN interface? References: Message-ID: <6s63l8d4d79nofp7467uofldspmu5j4fbh@4ax.com> On Tue, 26 Mar 2013 23:50:36 +1100, Chris Angelico wrote: >According to the docstring, the first argument to make_server() is the >host name to bind to. Using "localhost" means you're bound to >127.0.0.1, as you see. Use your LAN IP address there, or "" to bind to >all local addresses - or possibly "::" to bind to all IPv6 addresses >(try it and see - some systems work with one or the other, others work >happily with both together). Thanks Chris. I was thinking it was due to how Python was configured, and didn't first check that it could be some instruction in the script itself. It works fine now. From cl at isbd.net Tue Mar 26 10:03:19 2013 From: cl at isbd.net (cl at isbd.net) Date: Tue, 26 Mar 2013 14:03:19 +0000 Subject: Is it me or is the python-vobject documentation rather lacking? Message-ID: <7em82a-2uj.ln1@chris.zbmc.eu> I'm trying to use the python vobject package instead of what I use at the moment (the icalendar package) because it's more widely supported and available from my Linux repository. However I'm having a really hard time actually working out how to use it. The 'Usage examples' at http://vobject.skyhouseconsulting.com/usage.html have very little about parsing existing .ics files and say "More examples can be found in source code doctests." I can't find those examples at all. The only test code I can see comprises direct data entry using the python interpreter directly and is just a mess. I can open a .ics file and vobject parses it:- >>> f = open("orage.ics") >>> p = vobject.readOne(f) >>> p.vevent.dtstart.value datetime.date(2012, 3, 16) ... but then I need to know how to iterate through the .ics file and how to get all the other fields out of an event entry. Can anyone point me at some examples that do something rather more extensive than the above example? Alternatively where do I find how to extract other fields from a vevent as values like vevent.dtstart.value? These don't seem to be documented anywhere obvious in http://vobject.skyhouseconsulting.com/epydoc/. -- Chris Green From cl at isbd.net Tue Mar 26 11:50:11 2013 From: cl at isbd.net (cl at isbd.net) Date: Tue, 26 Mar 2013 15:50:11 +0000 Subject: I need a neat way to print nothing or a number Message-ID: What's a neat way to print columns of numbers with blanks where a number is zero or None? E.g. I want to output something like:- Credit Debit Description 100.00 Initial balance 123.45 Payment for cabbages 202.00 Telephone bill For each line I have either the credit or the debit amount and the other is 0 or None. However you can't get number formatting (old or new) to output a blank for 0 and it barfs on None. -- Chris Green From rosuav at gmail.com Tue Mar 26 12:08:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 03:08:16 +1100 Subject: I need a neat way to print nothing or a number In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 2:50 AM, wrote: > What's a neat way to print columns of numbers with blanks where a number > is zero or None? > > E.g. I want to output something like:- > > Credit Debit Description > 100.00 Initial balance > 123.45 Payment for cabbages > 202.00 Telephone bill > > > For each line I have either the credit or the debit amount and the other > is 0 or None. However you can't get number formatting (old or new) to > output a blank for 0 and it barfs on None. Try printing out this expression: "%.2f"%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA From wolfgang.maier at biologie.uni-freiburg.de Tue Mar 26 13:06:10 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 26 Mar 2013 17:06:10 +0000 (UTC) Subject: I need a neat way to print nothing or a number References: Message-ID: Chris Angelico gmail.com> writes: > > Try printing out this expression: > > "%.2f"%value if value else '' > > Without the rest of your code I can't tell you how to plug that in, > but a ternary expression is a good fit here. > > ChrisA > Unfortunately, that's not working, but gives a TypeError: a float is required when the first value evaluates to False. Apparently it's not that easy to combine number formatting with logical operators - the same happens with my idea ('{:.2f}').format(value or ''). Wolfgang From rosuav at gmail.com Tue Mar 26 13:14:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 04:14:32 +1100 Subject: I need a neat way to print nothing or a number In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 4:06 AM, Wolfgang Maier wrote: > Chris Angelico gmail.com> writes: > >> >> Try printing out this expression: >> >> "%.2f"%value if value else '' >> >> Without the rest of your code I can't tell you how to plug that in, >> but a ternary expression is a good fit here. >> >> ChrisA >> > > Unfortunately, that's not working, but gives a TypeError: a float is required > when the first value evaluates to False. > Apparently it's not that easy to combine number formatting with logical > operators - the same happens with my idea ('{:.2f}').format(value or ''). Really? Works for me in 3.3: >>> value=1.2 >>> "%.2f"%value if value else '' '1.20' >>> value=0 >>> "%.2f"%value if value else '' '' >>> value=None >>> "%.2f"%value if value else '' '' What's the full context? The way I've written the expression, it's guaranteed to return a string (either "%.2f"5value or the literal '', and yes, I'm aware that I was inconsistent with the quotes). I tried it in 2.6 and it worked there, too. Now, if you parenthesize the bit after the percent sign, the TypeError comes up. But that wasn't the intention of the code (and "value if value else something-else" is just "value or something-else", anyway). ChrisA From wolfgang.maier at biologie.uni-freiburg.de Wed Mar 27 04:23:37 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 27 Mar 2013 08:23:37 +0000 (UTC) Subject: I need a neat way to print nothing or a number References: Message-ID: Chris Angelico gmail.com> writes: > > On Wed, Mar 27, 2013 at 4:06 AM, Wolfgang Maier > biologie.uni-freiburg.de> wrote: > > Chris Angelico gmail.com> writes: > > > >> > >> Try printing out this expression: > >> > >> "%.2f"%value if value else '' > >> > >> Without the rest of your code I can't tell you how to plug that in, > >> but a ternary expression is a good fit here. > >> > >> ChrisA > >> > > > > Unfortunately, that's not working, but gives a TypeError: a float is required > > when the first value evaluates to False. > > Apparently it's not that easy to combine number formatting with logical > > operators - the same happens with my idea ('{:.2f}').format(value or ''). > > Really? Works for me in 3.3: > > >>> value=1.2 > >>> "%.2f"%value if value else '' > '1.20' > >>> value=0 > >>> "%.2f"%value if value else '' > '' > >>> value=None > >>> "%.2f"%value if value else '' > '' > > What's the full context? The way I've written the expression, it's > guaranteed to return a string (either "%.2f"5value or the literal '', > and yes, I'm aware that I was inconsistent with the quotes). > > I tried it in 2.6 and it worked there, too. Now, if you parenthesize > the bit after the percent sign, the TypeError comes up. But that > wasn't the intention of the code (and "value if value else > something-else" is just "value or something-else", anyway). > > ChrisA > Hi Chris, yes, I had put parens around your ternary operator expression after the %. Should have read your code more carefully, but I assumed what you tried to do was to obtain a *formatted* string in both cases. Your suggestion as it is really just gives formatting for numbers, but returns an empty string for False values, so it's just a partial solution to the original problem (basically converting everything to strings ready for an additional round of formatting). Anyway, there's a better answer by now, so never mind. Cheers, Wolfgang From __peter__ at web.de Tue Mar 26 13:22:21 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Mar 2013 18:22:21 +0100 Subject: I need a neat way to print nothing or a number References: Message-ID: Wolfgang Maier wrote: > Chris Angelico gmail.com> writes: > >> >> Try printing out this expression: >> >> "%.2f"%value if value else '' >> >> Without the rest of your code I can't tell you how to plug that in, >> but a ternary expression is a good fit here. >> >> ChrisA >> > > Unfortunately, that's not working, but gives a TypeError: a float is > required when the first value evaluates to False. > Apparently it's not that easy to combine number formatting with logical > operators - the same happens with my idea ('{:.2f}').format(value or ''). Here's a round-about way: class Prepare: def __init__(self, value): self.value = value def __format__(self, spec): if self.value is None or self.value == 0: return format(0.0, spec).replace(".", " ").replace("0", " ") elif isinstance(self.value, str): return self.value.rjust(len(format(0.0, spec))) return format(self.value, spec) def prepare(row): return map(Prepare, row) data = [ ("Credit", "Debit", "Description"), (100, 0, "Initial balance"), (123.45, None, "Payment for cabbages"), (0.0, 202.0, "Telephone bill"), ] for row in data: print("{:10.2f} {:10.2f} {}".format(*prepare(row))) From ethan at stoneleaf.us Tue Mar 26 13:21:35 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Mar 2013 10:21:35 -0700 Subject: I need a neat way to print nothing or a number In-Reply-To: References: Message-ID: <5151D91F.8080506@stoneleaf.us> On 03/26/2013 10:06 AM, Wolfgang Maier wrote: > Chris Angelico gmail.com> writes: > >> >> Try printing out this expression: >> >> "%.2f"%value if value else '' >> >> Without the rest of your code I can't tell you how to plug that in, >> but a ternary expression is a good fit here. >> >> ChrisA >> > > Unfortunately, that's not working, but gives a TypeError: a float is required > when the first value evaluates to False. > Apparently it's not that easy to combine number formatting with logical > operators - the same happens with my idea ('{:.2f}').format(value or ''). Use parens then: ("%.2f" % value) if value else '' -- ~Ethan~ From rosuav at gmail.com Tue Mar 26 14:48:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 05:48:39 +1100 Subject: I need a neat way to print nothing or a number In-Reply-To: <5151D91F.8080506@stoneleaf.us> References: <5151D91F.8080506@stoneleaf.us> Message-ID: On Wed, Mar 27, 2013 at 4:21 AM, Ethan Furman wrote: > On 03/26/2013 10:06 AM, Wolfgang Maier wrote: >> >> Chris Angelico gmail.com> writes: >> >>> >>> Try printing out this expression: >>> >>> "%.2f"%value if value else '' >>> >>> Without the rest of your code I can't tell you how to plug that in, >>> but a ternary expression is a good fit here. >>> >>> ChrisA >>> >> >> Unfortunately, that's not working, but gives a TypeError: a float is >> required >> when the first value evaluates to False. >> Apparently it's not that easy to combine number formatting with logical >> operators - the same happens with my idea ('{:.2f}').format(value or ''). > > > Use parens then: > > ("%.2f" % value) if value else '' According to the operator precedence table, the parens are unnecessary there. ChrisA From gordon at panix.com Tue Mar 26 12:29:15 2013 From: gordon at panix.com (John Gordon) Date: Tue, 26 Mar 2013 16:29:15 +0000 (UTC) Subject: I need a neat way to print nothing or a number References: Message-ID: In cl at isbd.net writes: > What's a neat way to print columns of numbers with blanks where a number > is zero or None? print number or ' ' -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From p.f.moore at gmail.com Tue Mar 26 12:23:05 2013 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 26 Mar 2013 09:23:05 -0700 (PDT) Subject: Simple example of how to use importlib to create a loader Message-ID: <91034295-3dd2-4b20-9aea-7183c2a87ff2@googlegroups.com> I'm trying to write my own loader using importlib. And frankly, I'm getting nowhere. I'm struggling to understand precisely which methods of the various ABCs I need to implement, and in some cases what they should do. Could anyone point me to a simple example (say, something that implements zip imports using the zipfile module - that was what I initially tried to get working as a proof of concept). Where I've got to is the following stub implementation to try to log the sequence of calls: from importlib.abc import PathEntryFinder, SourceLoader class MyFinder(PathEntryFinder): def __init__(self, pathentry): """Create a finder for the given `pathentry`""" if pathentry == 'foo': return raise ImportError def find_loader(self, fullname): """Return a loader for the module `fullname`""" print("find_loader('{}')".format(fullname)) return MyLoader(), ['foo'] class MyLoader(SourceLoader): def module_repr(self): print("module_repr()") return True def is_package(self, fullname): print("is_package('{}')".format(fullname)) return True def get_data(self, path): """Return an open binary file object for `path`""" print("get_data('{}')".format(path)) return b"print('hello from foo!')" def get_filename(self, fullname): """Return the filename for module `fullname`""" print("get_filename('{}')".format(fullname)) return '/this/is/foo' if __name__ == '__main__': import sys sys.path_hooks.append(lambda p: MyFinder(p)) sys.path.insert(0, 'foo') import a import a.b from a.b.c import x It prints out >py .\loader.py find_loader('a') is_package('a') get_filename('a') get_data('/this/is/foo') get_filename('a') is_package('a') hello from foo! Traceback (most recent call last): File ".\loader.py", line 46, in import a.b ImportError: No module named 'a.b' which is a good start, but I don't know why it isn't willing to check for 'a.b' (after all, I tell it that 'a' is a package). I'm quite probably doing something trivially wrong here - after all, I'm not even *trying* to implement a sane view of a package structure here. But I'd have expected at least a find_loader('a.b') call... Thanks for any help, Paul. From hossamalagmy at gmail.com Tue Mar 26 12:29:37 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Tue, 26 Mar 2013 09:29:37 -0700 (PDT) Subject: Samsung Galaxy Mini Message-ID: <07d0d052-ff7d-4784-944b-65f8437c8f53@f5g2000yqp.googlegroups.com> Samsung Galaxy Mini http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-mini.html From luggw1 at elpasotel.net Tue Mar 26 13:06:09 2013 From: luggw1 at elpasotel.net (luggw1 at elpasotel.net) Date: Tue, 26 Mar 2013 10:06:09 -0700 (PDT) Subject: Help with zip in a Python exercise Message-ID: <6d95376b-1c56-4710-b81b-87177b189c5a@googlegroups.com> I've been working through a Python tutorial online and one of the exercises uses the zip command. The only problem is that the command doesn't work. I've read through the man page for zip and it looks like what I'm attempting should work, but it doesn't. The command is: zip -qr /media/backup/backups/test/20130326100218.zip -i /home/luggw1/Documents/ /home/luggw1/Code/ The error it produces is: zip error: Invalid command arguments (nothing to select from) Can anybody point out the error of my ways? Thanks. Bill Lugg From joel.goldstick at gmail.com Tue Mar 26 13:22:44 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 26 Mar 2013 13:22:44 -0400 Subject: Help with zip in a Python exercise In-Reply-To: <6d95376b-1c56-4710-b81b-87177b189c5a@googlegroups.com> References: <6d95376b-1c56-4710-b81b-87177b189c5a@googlegroups.com> Message-ID: On Tue, Mar 26, 2013 at 1:06 PM, wrote: > I've been working through a Python tutorial online and one of the > exercises uses the zip command. The only problem is that the command > doesn't work. I've read through the man page for zip and it looks like > what I'm attempting should work, but it doesn't. > > The command is: > > zip -qr /media/backup/backups/test/20130326100218.zip -i > /home/luggw1/Documents/ /home/luggw1/Code/ > > The error it produces is: > > zip error: Invalid command arguments (nothing to select from) > > Can anybody point out the error of my ways? > Not sure what os you are using. If linux, then the zip command looks odd. -q is quiet mode, you might want to remove that til it works. Also not sure your -i is set up propery. Try to google zip tutorial as this isn't a python question at all > > Thanks. > Bill Lugg > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From as at sci.fi Thu Mar 28 09:35:32 2013 From: as at sci.fi (Anssi Saari) Date: Thu, 28 Mar 2013 15:35:32 +0200 Subject: Help with zip in a Python exercise References: <6d95376b-1c56-4710-b81b-87177b189c5a@googlegroups.com> Message-ID: luggw1 at elpasotel.net writes: > I've been working through a Python tutorial online and one of the exercises uses the zip command. The only problem is that the command doesn't work. I've read through the man page for zip and it looks like what I'm attempting should work, but it doesn't. > > The command is: > > zip -qr /media/backup/backups/test/20130326100218.zip -i /home/luggw1/Documents/ /home/luggw1/Code/ -i simply isn't used to to specify which directories you want to zip. You can use it to specify filenames that you want in your zip, regardless of where they are. Not exactly an option I've ever had use for in over a decade of using zip... Just leave -i out of the command and you'll probably get what you intended. From l.selmi at icloud.com Tue Mar 26 13:26:00 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Tue, 26 Mar 2013 18:26:00 +0100 Subject: problem with sys import argv Message-ID: hi python community, i wrote the following programm: from sys import argv script, userName = argv prompt = '> ' print 'hi %s, i am the %s script' % (userName, script) print "i'd like to ask you a few questions." print 'do you like me %s' % userName likes = raw_input(prompt) print "where do you live %s?" % userName lives = raw_input(prompt) print 'what kind of computer do you have?' computer = raw_input(prompt) print """ alright so you said %r about liking me. you live in %r. not sure where that is. and you have a %r computer. nice """ % (likes, lives, computer) and i got the following error: Traceback (most recent call last): File "/var/folders/89/84z7tw3d3rv39gny3n2p963m0000gn/T/pythonInTerm.GUF6PWCM", line 3, in script, userName = argv ValueError: need more than 1 value to unpack what can i do? thanks! From breamoreboy at yahoo.co.uk Tue Mar 26 13:42:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 26 Mar 2013 17:42:09 +0000 Subject: problem with sys import argv In-Reply-To: References: Message-ID: On 26/03/2013 17:26, leonardo selmi wrote: > hi python community, > > i wrote the following programm: > > from sys import argv > > script, userName = argv > prompt = '> ' > > print 'hi %s, i am the %s script' % (userName, script) > print "i'd like to ask you a few questions." > print 'do you like me %s' % userName > likes = raw_input(prompt) > > print "where do you live %s?" % userName > lives = raw_input(prompt) > > print 'what kind of computer do you have?' > computer = raw_input(prompt) > > print """ > alright so you said %r about liking me. > you live in %r. not sure where that is. > and you have a %r computer. nice > """ % (likes, lives, computer) > > and i got the following error: Traceback (most recent call last): > File "/var/folders/89/84z7tw3d3rv39gny3n2p963m0000gn/T/pythonInTerm.GUF6PWCM", line 3, in > script, userName = argv > ValueError: need more than 1 value to unpack > > what can i do? > > thanks! > Write some error handling to allow for the script being run without the user name. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From davea at davea.name Tue Mar 26 13:55:07 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 13:55:07 -0400 Subject: problem with sys import argv In-Reply-To: References: Message-ID: <5151E0FB.50204@davea.name> On 03/26/2013 01:26 PM, leonardo selmi wrote: > hi python community, > > i wrote the following programm: > > from sys import argv > > script, userName = argv > prompt = '> ' > > print 'hi %s, i am the %s script' % (userName, script) > print "i'd like to ask you a few questions." > print 'do you like me %s' % userName > likes = raw_input(prompt) > > print "where do you live %s?" % userName > lives = raw_input(prompt) > > print 'what kind of computer do you have?' > computer = raw_input(prompt) > > print """ > alright so you said %r about liking me. > you live in %r. not sure where that is. > and you have a %r computer. nice > """ % (likes, lives, computer) > > and i got the following error: Traceback (most recent call last): > File "/var/folders/89/84z7tw3d3rv39gny3n2p963m0000gn/T/pythonInTerm.GUF6PWCM", line 3, in > script, userName = argv > ValueError: need more than 1 value to unpack > > what can i do? > > thanks! > Since the script takes a mandatory argument, run it with one. python myscript.py Dave Better would be to change the script to check len(argv) for exactly 2, and tell the user how he should have run it. -- DaveA From PointedEars at web.de Tue Mar 26 16:12:42 2013 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Tue, 26 Mar 2013 21:12:42 +0100 Subject: problem with sys import argv References: Message-ID: <7378582.EtEbenrJl9@PointedEars.de> Dave Angel wrote: > Since the script takes a mandatory argument, run it with one. > > python myscript.py Dave > > Better would be to change the script to check len(argv) for exactly 2, > and tell the user how he should have run it. I would use argparse.ArgumentParser instead. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. From davea at davea.name Tue Mar 26 16:48:36 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 16:48:36 -0400 Subject: problem with sys import argv In-Reply-To: <7378582.EtEbenrJl9@PointedEars.de> References: <7378582.EtEbenrJl9@PointedEars.de> Message-ID: <515209A4.4060709@davea.name> On 03/26/2013 04:12 PM, Thomas 'PointedEars' Lahn wrote: > Dave Angel wrote: > >> Since the script takes a mandatory argument, run it with one. >> >> python myscript.py Dave >> >> Better would be to change the script to check len(argv) for exactly 2, >> and tell the user how he should have run it. > > I would use argparse.ArgumentParser instead. > > > As would I. But that would be out of proportion of the rest of the code, and therefore presumably beyond the needs or interest of the OP. -- DaveA From lana.greene.cmp at gmail.com Tue Mar 26 14:51:10 2013 From: lana.greene.cmp at gmail.com (Lana) Date: Tue, 26 Mar 2013 18:51:10 -0000 Subject: [job] Python & AWS /Back-End Developer in New York, NY Message-ID: We are looking for a strong Python Developer to work with our young and energetic team on the Next generation of clients website. This project is the first to implement the modern concepts of Cloud and MongoDB. Job Responsibilities - Creates new and modifies existing software, integrates software applications and modules based on specifications created in partnership with others - Designs and runs unit and integration tests to ensure that software meets requirements - Contributes and leads in the design process for less complex components - Provides technical support to operations and/or to other development teams - Creates, reviews, and maintains technical documentation related to assigned software - Reviews work of both peers and more junior developers - Helps identify and implement short- and long-term solution options including risk assessments - Participates in devising and implementing solutions for problem remediation - Participates in project planning sessions with team members - Provides work breakdown and estimates for small software development tasks - Provides timely status updates for areas of individual responsibilities in projects - Develops software using disciplined software development processes, adhering to team/company standards and software best practice guidelines, and corporate policies - Works independently with limited technical and management guidance, taking ownership of problems within own area of knowledge - Makes decisions within ambiguous guidelines with limited review by appropriate people - Is accountable for the quality of work - Delivers results within agreed procedures and timeframes - Attends to the needs of internal and/or external customer - Reviews and may approve decisions of junior engineers Qualifications: - Development experience with object-oriented languages - 1-2 years of Python development experience - Knowledge of HTML5 concepts is a plus to coordinate with the front-end development - Agile development experience a plus - Demonstrated ability to work in a team environment - Good unit testing practices - Good communication and documentation skills - Willingness to interact and work with different teams across organizations in different time zones - Willingness to work overtime and weekends if required - Bachelors degree in Computer Science is an added advantage Required Skills: - Strong in object-oriented concepts and Python language - Proficient with concepts of virtual environments and familiarity with Fabric tool - Knowledgeable about MVC pattern - Experienced working with Tornado web server - Familiar with REST API and JSON - Familiar with asynchronous programming - Familiar with AWS infrastructure - Knowledgeable about NoSQL concepts From nikos.gr33k at gmail.com Tue Mar 26 17:24:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 26 Mar 2013 14:24:00 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? Message-ID: Hello today i deiced to go form python 2.6 to python 3.2.3 although in 2.6 my script runs in the ht enewest python i ge this error: Traceback (most recent call last): File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute r = self._query(query) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query rowcount = self._do_query(q) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "metrites.py", line 193, in cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute self.errorhandler(self, exc, value) File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass(errorvalue) _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") you can also see it at http://superhost.gr Any ideas what might be the problem? My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server. Can you please tell me what's the nature of this error? Thank you. From python at mrabarnett.plus.com Tue Mar 26 20:41:19 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 27 Mar 2013 00:41:19 +0000 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: Message-ID: <5152402F.6070800@mrabarnett.plus.com> On 26/03/2013 21:24, ????? ???33? wrote: > Hello today i deiced to go form python 2.6 to python 3.2.3 > > although in 2.6 my script runs in the ht enewest python i ge this error: > > > Traceback (most recent call last): > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute > r = self._query(query) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query > rowcount = self._do_query(q) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query > db.query(q) > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "metrites.py", line 193, in > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute > self.errorhandler(self, exc, value) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler > raise errorclass(errorvalue) > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") > > > > you can also see it at http://superhost.gr > > Any ideas what might be the problem? > > My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server. > > Can you please tell me what's the nature of this error? > > Thank you. > The error's in the SQL. From rurpy at yahoo.com Wed Mar 27 00:26:06 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Tue, 26 Mar 2013 21:26:06 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: Message-ID: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> On 03/26/2013 03:24 PM, ????? ???33? wrote:> Hello today i deiced to go form python 2.6 to python 3.2.3 > > although in 2.6 my script runs in the ht enewest python i ge this error: > > > Traceback (most recent call last): > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute > r = self._query(query) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query > rowcount = self._do_query(q) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query > db.query(q) > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "metrites.py", line 193, in > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 184, in execute > self.errorhandler(self, exc, value) > File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler > raise errorclass(errorvalue) > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1") > > > > you can also see it at http://superhost.gr > > Any ideas what might be the problem? > > My webhost (hostgator.com) says that The MySQLdb module is already installed for python 3 on this server. > > Can you please tell me what's the nature of this error? > > Thank you. This seems to be the problem line of code: > File "metrites.py", line 193, in > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) If 'page' is not a string as you expect, but is None or (for example) a list or something else, you might well end up with invalid SQL when MySQLdb tries to build the executable sql statement. Sorry I can't be more specific -- I haven't used MySQLdb and I'm suggesting what I'd try for any generic DBI module. If MySQLdb has a way to turn on debugging so that it prints SQL statements before execution, you might want do that. Then it may be obvious what is wrong, or if the SQL still looks ok, try copying it and pasting it in a interactive database session to see what error occurs. If not, maybe you can try adding a print statement to your code that will print the value of 'page'. This will be easier to do if you can run you code interactively. If you have to run it via a webserver than maybe you'll need wrap the print output in html commands to make it visible on the page, or to write it to a file. From nikos.gr33k at gmail.com Wed Mar 27 02:42:20 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 26 Mar 2013 23:42:20 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> Message-ID: <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> ?? ???????, 27 ??????? 2013 6:26:06 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > If not, maybe you can try adding a print statement to your code that > will print the value of 'page'. This will be easier to do if you > can run you code interactively. If you have to run it via a webserver > than maybe you'll need wrap the print output in html commands to make > it visible on the page, or to write it to a file. I tried what you suggested by doign the following: print( page ) sys.exit(0) cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) and the result is printed in the webpage as 'index.html' so page seem s to be a string but the error is still persistant. Anything else i need to try? From nikos.gr33k at gmail.com Wed Mar 27 03:26:31 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 00:26:31 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <77c04488-6e61-4fb5-84b1-03335845b851@googlegroups.com> And also i must show you that 'page' values are calculated by: # detect how 'index.html' is called and validate variables 'htmlpage' & 'page' if page and os.path.isfile( '/home/nikos/www/cgi-bin/' + page ): page = page elif form.getvalue('show') and os.path.isfile( htmlpage ): page = htmlpage.replace( '/home/nikos/public_html/', '' ) else: page = 'index.html' so in all cases theya re string. i just dont see whats worng.... From nikos.gr33k at gmail.com Wed Mar 27 05:58:36 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 02:58:36 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <77c04488-6e61-4fb5-84b1-03335845b851@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <77c04488-6e61-4fb5-84b1-03335845b851@googlegroups.com> Message-ID: any help here please? From python at mrabarnett.plus.com Wed Mar 27 12:48:44 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 27 Mar 2013 16:48:44 +0000 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <515322EC.9080602@mrabarnett.plus.com> On 27/03/2013 06:42, ????? ???33? wrote: > ?? ???????, 27 ??????? 2013 6:26:06 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > >> If not, maybe you can try adding a print statement to your code that >> will print the value of 'page'. This will be easier to do if you >> can run you code interactively. If you have to run it via a webserver >> than maybe you'll need wrap the print output in html commands to make >> it visible on the page, or to write it to a file. > > > I tried what you suggested by doign the following: > > print( page ) > sys.exit(0) > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) > > > and the result is printed in the webpage as 'index.html' > > so page seem s to be a string but the error is still persistant. > Anything else i need to try? > A brief look at the documentation tells me that MySQL uses '?' as the placeholder instead of '%s': cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) From nikos.gr33k at gmail.com Wed Mar 27 22:17:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:17:34 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> Message-ID: <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> ?? ??????, 28 ??????? 2013 12:48:54 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Wed, 27 Mar 2013 16:48:44 +0000, MRAB > > declaimed the following in gmane.comp.python.general: > > > > > > > A brief look at the documentation tells me that MySQL uses '?' as the > > > placeholder instead of '%s': > > > > > > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) > > > > What documentation is that from... MySQLdb has used %s for ages (if > > you look at the source code of the adapter, it actually uses Python's > > string interpolation to fill in the SQL /after/ it has escaped/quoted > > each parameter. > > > > Now, I don't know about the recent "pure Python" MySQL adapter... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ So dod i have to use '%s' or (?) what is better? and as for the synatx that i asked in my previous post? what is the correct one? From nikos.gr33k at gmail.com Wed Mar 27 22:17:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:17:34 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> Message-ID: <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> ?? ??????, 28 ??????? 2013 12:48:54 ?.?. UTC+2, ? ??????? Dennis Lee Bieber ??????: > On Wed, 27 Mar 2013 16:48:44 +0000, MRAB > > declaimed the following in gmane.comp.python.general: > > > > > > > A brief look at the documentation tells me that MySQL uses '?' as the > > > placeholder instead of '%s': > > > > > > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) > > > > What documentation is that from... MySQLdb has used %s for ages (if > > you look at the source code of the adapter, it actually uses Python's > > string interpolation to fill in the SQL /after/ it has escaped/quoted > > each parameter. > > > > Now, I don't know about the recent "pure Python" MySQL adapter... > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ So dod i have to use '%s' or (?) what is better? and as for the synatx that i asked in my previous post? what is the correct one? From nikos.gr33k at gmail.com Wed Mar 27 22:19:27 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:19:27 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: The following works in python 3.2 [code] cur.execute( '''SELECT hits FROM counters WHERE url = ?''') , (page,) [/code] is there a difefrence between the above and the follwong which works in python 2.6 [code] cur.execute( '''SELECT hits FROM counters WHERE url = ?''' , (page,) ) [/code] Also whats better? use '%s' or '?' and why? I'am confused. Which one is the correct? Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From nikos.gr33k at gmail.com Wed Mar 27 22:24:05 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:24:05 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: I think i have figured this out: cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,) is a tuple of two objects. The first is the result of cur.execute( '''SELECT hits FROM counters WHERE url = %s''') and the second is (page,) cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) ) is the result of the execute method of the cur object called with two arguments. >>> int('10010110101', 2) 1205 >>> int('10010110101'), 2 (10010110101, 2) >>> Is this correct? From nikos.gr33k at gmail.com Wed Mar 27 22:24:05 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:24:05 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: I think i have figured this out: cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,) is a tuple of two objects. The first is the result of cur.execute( '''SELECT hits FROM counters WHERE url = %s''') and the second is (page,) cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) ) is the result of the execute method of the cur object called with two arguments. >>> int('10010110101', 2) 1205 >>> int('10010110101'), 2 (10010110101, 2) >>> Is this correct? From rosuav at gmail.com Wed Mar 27 22:33:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 13:33:20 +1100 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 1:24 PM, ????? ???33? wrote: > I think i have figured this out: > > cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,) > > is a tuple of two objects. The first is the result of > cur.execute( '''SELECT hits FROM counters WHERE url = %s''') > and the second is > (page,) > > > cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) ) > is the result of the execute method of the cur object called with two arguments. > > > >>>> int('10010110101', 2) > 1205 >>>> int('10010110101'), 2 > (10010110101, 2) >>>> > > Is this correct? Ah, crossed in the post. Yes, this is correct, as you can confirm with the operator precedence table that I posted above. (Experienced programmers would have the universal precedences in their heads, but the same applies.) ChrisA From nikos.gr33k at gmail.com Wed Mar 27 22:36:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:36:44 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: Thank you for verifying this, Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From nikos.gr33k at gmail.com Wed Mar 27 22:36:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:36:44 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: Thank you for verifying this, Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From rosuav at gmail.com Wed Mar 27 22:46:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 13:46:48 +1100 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 1:36 PM, ????? ???33? wrote: > Thank you for verifying this, > > Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. Your quotes file isn't ASCII. Read the error message, Python is being very helpful. ChrisA From nikos.gr33k at gmail.com Wed Mar 27 22:57:23 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:57:23 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 4:46:48 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 1:36 PM, ????? ???33? wrote: > > > Thank you for verifying this, > > > > > > Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. > > > > Your quotes file isn't ASCII. Read the error message, Python is being > > very helpful. Then how come the same .txt file opens normally in Python 2.6 i also tried to save ti as .ascii istead of utf-8 file and still same error also if i quote it out same things happen in those liens too. f = open( "/home/nikos/www/" + page ) htmldata = f.read() f.read produced the same kind of error. why? From nikos.gr33k at gmail.com Wed Mar 27 22:57:23 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:57:23 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 4:46:48 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 1:36 PM, ????? ???33? wrote: > > > Thank you for verifying this, > > > > > > Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. > > > > Your quotes file isn't ASCII. Read the error message, Python is being > > very helpful. Then how come the same .txt file opens normally in Python 2.6 i also tried to save ti as .ascii istead of utf-8 file and still same error also if i quote it out same things happen in those liens too. f = open( "/home/nikos/www/" + page ) htmldata = f.read() f.read produced the same kind of error. why? From nikos.gr33k at gmail.com Wed Mar 27 23:54:13 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 20:54:13 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: <07780f4e-62ec-430f-a0cf-fb551336ac18@googlegroups.com> this worked quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", 'rb') ) ) and also this f = open( "/home/nikos/www/" + page, 'rb' ) i dont know why python 3 needs 'rb' though. Now ima having problem with this: htmldata = htmldata % (quote, music) it says soemthign about wrong operand.... From nikos.gr33k at gmail.com Wed Mar 27 23:54:13 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 20:54:13 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: <07780f4e-62ec-430f-a0cf-fb551336ac18@googlegroups.com> this worked quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", 'rb') ) ) and also this f = open( "/home/nikos/www/" + page, 'rb' ) i dont know why python 3 needs 'rb' though. Now ima having problem with this: htmldata = htmldata % (quote, music) it says soemthign about wrong operand.... From rosuav at gmail.com Wed Mar 27 23:57:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 14:57:15 +1100 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <07780f4e-62ec-430f-a0cf-fb551336ac18@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> <07780f4e-62ec-430f-a0cf-fb551336ac18@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 2:54 PM, ????? ???33? wrote: > this worked > > quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", 'rb') ) ) > > and also this > > f = open( "/home/nikos/www/" + page, 'rb' ) > > i dont know why python 3 needs 'rb' though. > > Now ima having problem with this: > > htmldata = htmldata % (quote, music) > > it says soemthign about wrong operand.... http://www.joelonsoftware.com/articles/Unicode.html Read it. ChrisA From nikos.gr33k at gmail.com Wed Mar 27 22:19:27 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:19:27 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: The following works in python 3.2 [code] cur.execute( '''SELECT hits FROM counters WHERE url = ?''') , (page,) [/code] is there a difefrence between the above and the follwong which works in python 2.6 [code] cur.execute( '''SELECT hits FROM counters WHERE url = ?''' , (page,) ) [/code] Also whats better? use '%s' or '?' and why? I'am confused. Which one is the correct? Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From rosuav at gmail.com Wed Mar 27 22:31:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 13:31:20 +1100 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <515322EC.9080602@mrabarnett.plus.com> <64b1d68a-7cc2-4039-b550-7f4970442aec@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 1:19 PM, ????? ???33? wrote: > The following works in python 3.2 > > [code] > cur.execute( '''SELECT hits FROM counters WHERE url = ?''') , (page,) > [/code] This is an email list and newsgroup. You don't need tags like that. I don't know what you mean by "works". Check out the operator precedence table: http://docs.python.org/3.3/reference/expressions.html#operator-precedence Figure out what the above expression will do, then decide for yourself whether page is having any effect on it. ChrisA From nagia.retsina at gmail.com Wed Mar 27 14:15:03 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 27 Mar 2013 11:15:03 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: ?? ???????, 27 ??????? 2013 6:48:44 ?.?. UTC+2, ? ??????? MRAB ??????: > On 27/03/2013 06:42, ????? ???33? wrote: > > > ?? ???????, 27 ??????? 2013 6:26:06 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > > > > > >> If not, maybe you can try adding a print statement to your code that > > >> will print the value of 'page'. This will be easier to do if you > > >> can run you code interactively. If you have to run it via a webserver > > >> than maybe you'll need wrap the print output in html commands to make > > >> it visible on the page, or to write it to a file. > > > > > > > > > I tried what you suggested by doign the following: > > > > > > print( page ) > > > sys.exit(0) > > > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) > > > > > > > > > and the result is printed in the webpage as 'index.html' > > > > > > so page seem s to be a string but the error is still persistant. > > > Anything else i need to try? > > > > > A brief look at the documentation tells me that MySQL uses '?' as the > > placeholder instead of '%s': > > > > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) But as i have it used to work withour problem with pyhton 2.6 Why would it be a problem now? From nagia.retsina at gmail.com Wed Mar 27 14:15:03 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 27 Mar 2013 11:15:03 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: ?? ???????, 27 ??????? 2013 6:48:44 ?.?. UTC+2, ? ??????? MRAB ??????: > On 27/03/2013 06:42, ????? ???33? wrote: > > > ?? ???????, 27 ??????? 2013 6:26:06 ?.?. UTC+2, ? ??????? ru... at yahoo.com ??????: > > > > > >> If not, maybe you can try adding a print statement to your code that > > >> will print the value of 'page'. This will be easier to do if you > > >> can run you code interactively. If you have to run it via a webserver > > >> than maybe you'll need wrap the print output in html commands to make > > >> it visible on the page, or to write it to a file. > > > > > > > > > I tried what you suggested by doign the following: > > > > > > print( page ) > > > sys.exit(0) > > > cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) > > > > > > > > > and the result is printed in the webpage as 'index.html' > > > > > > so page seem s to be a string but the error is still persistant. > > > Anything else i need to try? > > > > > A brief look at the documentation tells me that MySQL uses '?' as the > > placeholder instead of '%s': > > > > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) But as i have it used to work withour problem with pyhton 2.6 Why would it be a problem now? From nikos.gr33k at gmail.com Wed Mar 27 14:27:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 11:27:00 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <3feaeaff-65c7-4a7f-ac04-b5deede798c0@googlegroups.com> => 187 print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2]) excepinfo is probably mis-spelled---I have no idea what you intend.l Python3 raised exceptions in an except: clause giving the double exception message that I don't think you'd have seen in python2. Maybe the purpose is to help novice python programmers who haven't learned to make try: except: clause trap a specific statement looking for specific Errors. Maybe this line which iuses to work in python 2.6 doesnt in python 3.2.3 ? do i have to switch it to soemthing else? From nikos.gr33k at gmail.com Wed Mar 27 14:27:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 11:27:00 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <3feaeaff-65c7-4a7f-ac04-b5deede798c0@googlegroups.com> => 187 print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2]) excepinfo is probably mis-spelled---I have no idea what you intend.l Python3 raised exceptions in an except: clause giving the double exception message that I don't think you'd have seen in python2. Maybe the purpose is to help novice python programmers who haven't learned to make try: except: clause trap a specific statement looking for specific Errors. Maybe this line which iuses to work in python 2.6 doesnt in python 3.2.3 ? do i have to switch it to soemthing else? From nikos.gr33k at gmail.com Wed Mar 27 14:48:53 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 11:48:53 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> I had encoding isseus as well! Now i tried your suggestion changing comma with '%' and now the error is more clear. [code] _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") [/code] loook at http://superhost.gr please to see the whoel traceback From nikos.gr33k at gmail.com Wed Mar 27 14:48:53 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 11:48:53 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> Message-ID: <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> I had encoding isseus as well! Now i tried your suggestion changing comma with '%' and now the error is more clear. [code] _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") [/code] loook at http://superhost.gr please to see the whoel traceback From joel.goldstick at gmail.com Wed Mar 27 15:06:27 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 27 Mar 2013 15:06:27 -0400 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 2:48 PM, ????? ???33? wrote: > I had encoding isseus as well! > > Now i tried your suggestion changing comma with '%' and now the error is > more clear. > > [code] > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in > 'where clause'") > [/code] > > > loook at http://superhost.gr please to see the whoel traceback > -- > http://mail.python.org/mailman/listinfo/python-list > You should print the sql statement to see what is being created. Create the sql, and assign it to a variable name. Print that. Then execute the command. -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Wed Mar 27 15:13:48 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:13:48 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <3e7d6332-5ad6-4c86-8bed-c1ee63de9489@googlegroups.com> ?? ???????, 27 ??????? 2013 9:06:27 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > You should print the sql statement to see what is being created.? Create the > > >sql, and assign it to a variable name.? Print that.? Then execute the command. Ok Joe, i just tried the followinf as you suggested to me: try: sql = '''SELECT hits FROM counters WHERE url = %s''' print( sql ) cur.execute( sql , (page,) ) data = cur.fetchone() except MySQLdb.ProgrammingError as e: print ( "Query Error: ", dir( sys.exc_info()[1] ) ) ========= please look at http://supethost.gr now, weird errors! encoding issues perhaps?! From nikos.gr33k at gmail.com Wed Mar 27 15:13:48 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:13:48 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <3e7d6332-5ad6-4c86-8bed-c1ee63de9489@googlegroups.com> ?? ???????, 27 ??????? 2013 9:06:27 ?.?. UTC+2, ? ??????? Joel Goldstick ??????: > You should print the sql statement to see what is being created.? Create the > > >sql, and assign it to a variable name.? Print that.? Then execute the command. Ok Joe, i just tried the followinf as you suggested to me: try: sql = '''SELECT hits FROM counters WHERE url = %s''' print( sql ) cur.execute( sql , (page,) ) data = cur.fetchone() except MySQLdb.ProgrammingError as e: print ( "Query Error: ", dir( sys.exc_info()[1] ) ) ========= please look at http://supethost.gr now, weird errors! encoding issues perhaps?! From nikos.gr33k at gmail.com Wed Mar 27 15:23:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:23:11 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <5cc2bd2c-ec83-4881-97ce-e8e91ce72993@googlegroups.com> Even better: try: sql = '''SELECT hits FROM counters WHERE url = %s''' % page print( sql ) cur.execute( sql ) data = cur.fetchone() except MySQLdb.ProgrammingError as e: print ( "Query Error: ", dir( sys.exc_info()[1] ) ) ======== sql statement seems okey... From nikos.gr33k at gmail.com Wed Mar 27 15:23:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:23:11 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <5cc2bd2c-ec83-4881-97ce-e8e91ce72993@googlegroups.com> Even better: try: sql = '''SELECT hits FROM counters WHERE url = %s''' % page print( sql ) cur.execute( sql ) data = cur.fetchone() except MySQLdb.ProgrammingError as e: print ( "Query Error: ", dir( sys.exc_info()[1] ) ) ======== sql statement seems okey... From rosuav at gmail.com Wed Mar 27 15:28:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 06:28:35 +1100 Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 5:48 AM, ????? ???33? wrote: > I had encoding isseus as well! > > Now i tried your suggestion changing comma with '%' and now the error is more clear. > > [code] > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") > [/code] No, don't do that, that opens you up to SQL injection attacks. Read the responses you've been given: On Thu, Mar 28, 2013 at 3:48 AM, MRAB wrote: > A brief look at the documentation tells me that MySQL uses '?' as the > placeholder instead of '%s': > > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) This is what you need to do. ChrisA From nikos.gr33k at gmail.com Wed Mar 27 15:42:22 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:42:22 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <89df4430-3b67-4e9b-bcce-4a0777df620f@googlegroups.com> ?? ???????, 27 ??????? 2013 9:28:35 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 3:48 AM, MRAB wrote: > > A brief look at the documentation tells me that MySQL uses '?' as the > > placeholder instead of '%s': > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) > This is what you need to do. The following works in python 2.6 [code] cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,) [/code] is there a difefrence between the above and the follwong which works in python 3.x [code] cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) ) [/code] I'am confused. Which one is the correct? Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From nikos.gr33k at gmail.com Wed Mar 27 15:42:22 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 12:42:22 -0700 (PDT) Subject: MySQLdbd error. Perhpas it isn't installed? In-Reply-To: References: <9c01c631-77e8-4104-ae1f-5cccfaaea10d@googlegroups.com> <22f50ec2-7d20-47af-a793-5cf801b6a23e@googlegroups.com> <8ada8de4-1cb2-4fbb-ae4f-8c0d47c1cf40@googlegroups.com> Message-ID: <89df4430-3b67-4e9b-bcce-4a0777df620f@googlegroups.com> ?? ???????, 27 ??????? 2013 9:28:35 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 3:48 AM, MRAB wrote: > > A brief look at the documentation tells me that MySQL uses '?' as the > > placeholder instead of '%s': > cur.execute('''SELECT hits FROM counters WHERE url = ?''', (page, )) > This is what you need to do. The following works in python 2.6 [code] cur.execute( '''SELECT hits FROM counters WHERE url = %s''') , (page,) [/code] is there a difefrence between the above and the follwong which works in python 3.x [code] cur.execute( '''SELECT hits FROM counters WHERE url = %s''' , (page,) ) [/code] I'am confused. Which one is the correct? Also now http://superhost.gr seems to stuck in the following line which i try to open an acii file to slect a random line, please take a look. From rahulreddy24 at hotmail.com Tue Mar 26 19:59:39 2013 From: rahulreddy24 at hotmail.com (rahulreddy24 at hotmail.com) Date: Tue, 26 Mar 2013 16:59:39 -0700 (PDT) Subject: how do you make a loop run in reverse? Message-ID: So i have a set of for loops that create this : *************************************** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *************************************** * *** ***** ******* ********* but i want to nest all the loops under one BIG loop that'll run in reverse to make this: *************************************** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *************************************** * *** ***** ******* ********* ******* ***** *** * *************************************** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *************************************** Is this possible? From davea at davea.name Tue Mar 26 20:08:08 2013 From: davea at davea.name (Dave Angel) Date: Tue, 26 Mar 2013 20:08:08 -0400 Subject: how do you make a loop run in reverse? In-Reply-To: References: Message-ID: <51523868.1010008@davea.name> On 03/26/2013 07:59 PM, rahulreddy24 at hotmail.com wrote: > So i have a set of for loops that create this : > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > > but i want to nest all the loops under one BIG loop that'll run in reverse to make this: > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > ******* > ***** > *** > * > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > Is this possible? > tes -- DaveA From breamoreboy at yahoo.co.uk Tue Mar 26 20:18:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 27 Mar 2013 00:18:13 +0000 Subject: how do you make a loop run in reverse? In-Reply-To: References: Message-ID: On 26/03/2013 23:59, rahulreddy24 at hotmail.com wrote: > So i have a set of for loops that create this : > snipped the art > > but i want to nest all the loops under one BIG loop that'll run in reverse to make this: > snipped the art > > Is this possible? > Yes read http://docs.python.org/3/library/stdtypes.html#range and http://docs.python.org/3/library/functions.html#reversed -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From contact at xavierho.com Tue Mar 26 20:19:44 2013 From: contact at xavierho.com (Xavier Ho) Date: Wed, 27 Mar 2013 11:19:44 +1100 Subject: how do you make a loop run in reverse? In-Reply-To: References: Message-ID: There is a built-in function that reverses an iterable. Have a look at the documentation. xav On 27 March 2013 10:59, wrote: > So i have a set of for loops that create this : > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > > but i want to nest all the loops under one BIG loop that'll run in reverse > to make this: > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > ******* > ***** > *** > * > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > Is this possible? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Mar 26 21:08:45 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 27 Mar 2013 01:08:45 +0000 Subject: how do you make a loop run in reverse? In-Reply-To: References: Message-ID: > On 27 March 2013 10:59, wrote: >> >> So i have a set of for loops that create this : >> [snip] >> but i want to nest all the loops under one BIG loop that'll run in reverse >> to make this: [snip] >> Is this possible? On 27 March 2013 00:19, Xavier Ho wrote: > There is a built-in function that reverses an iterable. Have a look at the > documentation. I assume you mean the reversed function. It does not in general reverse an iterable. From the docs: """ reversed(seq) Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). New in version 2.4. Changed in version 2.6: Added the possibility to write a custom __reversed__() method. """ So it reverses a sequence (having the __len__ and __getitem__ methods) or an object that advertises reversibility (having a __reversed__ method). It does not reverse anything else including generators, iterators and most non-sequence iterables. To the OP: To reverse a "set of for loops" as requested is not possible using the reversed function. It is, however, possible to reverse a list of strings. So if you have a function that returns the list of strings you show as output then you can easily reverse that list with reversed(mylist) or mylist[::-1]. Oscar From arnodel at gmail.com Wed Mar 27 17:18:34 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 27 Mar 2013 21:18:34 +0000 Subject: how do you make a loop run in reverse? In-Reply-To: References: Message-ID: On 26 March 2013 23:59, wrote: > So i have a set of for loops that create this : > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > > but i want to nest all the loops under one BIG loop that'll run in reverse to make this: > > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > * > *** > ***** > ******* > ********* > ******* > ***** > *** > * > *************************************** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *** *** *** *** *** *** *** > *************************************** > > Is this possible? Let's have a look at a simple example. Imagine you have a function: >>> def print_pretty_pattern(): ... for i in range(1, 6): ... print '*'*i ... >>> print_pretty_pattern() * ** *** **** ***** You can't reverse the pattern because it's not data so you need to turn it into data: >>> def generate_pretty_pattern(): ... for i in range(1, 6): ... yield '*'*i It's the same as above, but the 'print' statement has been replace with a 'yield' statement, making the function into a generator function, so that when you call it you get an iterable of all the lines. You can now make a function to print a pattern: >>> def print_pattern(lines): ... for line in lines: ... print line Or if you want to be concise: >>> def print_pattern(lines): ... print "\n".join(lines) So you can print any pattern: >>> print_pattern(generate_pretty_pattern()) * ** *** **** ***** So now you can write another generator that makes the mirror pattern of a given pattern: >>> def mirror_pattern(pattern): ... lines = [] ... for line in pattern: ... yield line ... lines.append(line) ... if lines: ... lines.pop() # don't repeat the last line ... for line in reversed(lines): ... yield line ... >>> print_pattern(mirror_pattern(generate_pretty_pattern())) * ** *** **** ***** **** *** ** * Here's another example: >>> print_pattern(mirror_pattern(''.join(mirror_pattern("*".ljust(i).rjust(15))) for i in range(1,16,2))) * * * * * * * * * * * * * * * * * * * * * * * * * * * * -- Arnaud From ether.joe at gmail.com Tue Mar 26 21:30:32 2013 From: ether.joe at gmail.com (Sean Felipe Wolfe) Date: Tue, 26 Mar 2013 18:30:32 -0700 Subject: honking great ideas Message-ID: So I have been re-reading some of the python intro stuffs after a time away philandering with other languages. I have been thinking about the Zen of Python piece where it says 'namespaces are a honking great idea - let's do more of those'. A question -- since then do we have any sort of list of major innovations like that? Do we keep any sort of 'honking great idea list' anywhere? Or maybe folks could suggest what some of those milestones have been over time? I think a 'honking great list' of python innovations would be fun ... maybe presumptuous, but fun anyways. :P -- A musician must make music, an artist must paint, a poet must write, if he is to be ultimately at peace with himself. - Abraham Maslow From nad at acm.org Tue Mar 26 22:25:51 2013 From: nad at acm.org (Ned Deily) Date: Tue, 26 Mar 2013 19:25:51 -0700 Subject: honking great ideas References: Message-ID: In article , Sean Felipe Wolfe wrote: > So I have been re-reading some of the python intro stuffs after a time > away philandering with other languages. I have been thinking about the > Zen of Python piece where it says 'namespaces are a honking great idea > - let's do more of those'. > > A question -- since then do we have any sort of list of major > innovations like that? Do we keep any sort of 'honking great idea > list' anywhere? Or maybe folks could suggest what some of those > milestones have been over time? One suggestion: take a look at Raymond Hettinger's keynote address from the recent PyCon. Any of Raymond's talks are worth viewing but this one in particular is a higher-level sales pitch for Python: "Show the specific features that make Python more than just another scripting language." http://pyvideo.org/video/1669/keynote-3 -- Ned Deily, nad at acm.org From ether.joe at gmail.com Wed Mar 27 01:58:10 2013 From: ether.joe at gmail.com (Sean Felipe Wolfe) Date: Tue, 26 Mar 2013 22:58:10 -0700 Subject: honking great ideas In-Reply-To: References: Message-ID: On Tue, Mar 26, 2013 at 7:25 PM, Ned Deily wrote: > One suggestion: take a look at Raymond Hettinger's keynote address from > the recent PyCon. Any of Raymond's talks are worth viewing but this one > in particular is a higher-level sales pitch for Python: "Show the > specific features that make Python more than just another scripting > language." > > http://pyvideo.org/video/1669/keynote-3 Great! I'm taking a look now. From joan4eric at gmail.com Wed Mar 27 01:44:28 2013 From: joan4eric at gmail.com (Eric Parry) Date: Tue, 26 Mar 2013 22:44:28 -0700 (PDT) Subject: Sudoku Message-ID: I downloaded the following program from somewhere using a link from Wikipedia and inserted the ?most difficult Sudoku puzzle ever? string into it and ran it. It worked fine and solved the puzzle in about 4 seconds. However I cannot understand how it works. It seems to go backwards and forwards at random. Can anyone explain how it works in simple terms? Eric. def same_row(i,j): return (i/9 == j/9) def same_col(i,j): return (i-j) % 9 == 0 def same_block(i,j): return (i/27 == j/27 and i%9/3 == j%9/3) def r(a): i = a.find('0') if i == -1: print a exit(a) excluded_numbers = set() for j in range(81): if same_row(i,j) or same_col(i,j) or same_block(i,j): excluded_numbers.add(a[j]) for m in '123456789': if m not in excluded_numbers: # At this point, m is not excluded by any row, column, or block, so let's place it and recurse r(a[:i]+m+a[i+1:]) r('800000000003600000070090200050007000000045700000100030001000068008500010090000400') Sudoku solver where the puzzle is an 81 character string representing the puzzle read left-to-right, top-to-bottom, and 0 is a blank. ? From ulrich.eckhardt at dominolaser.com Wed Mar 27 03:58:01 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 27 Mar 2013 08:58:01 +0100 Subject: Sudoku In-Reply-To: References: Message-ID: <9dla2a-kql.ln1@satorlaser.homedns.org> Am 27.03.2013 06:44, schrieb Eric Parry: > I downloaded the following program from somewhere using a link from > Wikipedia and inserted the ?most difficult Sudoku puzzle ever? string > into it and ran it. It worked fine and solved the puzzle in about 4 > seconds. However I cannot understand how it works. In simple terms, it is using a depth-first search and backtracking. If you really want to understand this, get a book on algorithms and graphs (or locate an online source). I can try to give you an idea though. > It seems to go backwards and forwards at random. Can anyone explain > how it works in simple terms? I think your interpretation of what it does is wrong or at least flawed. It does try different combinations, but some don't lead to a solution. In that case, it goes back to a previous solution and tries the next one. I'll try to document the program to make it easier to understand... > def same_row(i,j): return (i/9 == j/9) > def same_col(i,j): return (i-j) % 9 == 0 > def same_block(i,j): return (i/27 == j/27 and i%9/3 == j%9/3) > > def r(a): # find an empty cell # If no empty cells are found, we have a solution that we print # and then terminate. > i = a.find('0') > if i == -1: > print a > exit(a) # find excluded numbers # Some numbers are blocked because they are already used in # the current column, row or block. This means they can't # possibly be used for the current empty cell. > excluded_numbers = set() > for j in range(81): > if same_row(i,j) or same_col(i,j) or same_block(i,j): > excluded_numbers.add(a[j]) # create possible solutions # Try all possibly numbers for the current empty cell in turn. # With the resulting modifications to the sodoku, use # recursion to find a full solution. > for m in '123456789': > if m not in excluded_numbers: > # At this point, m is not excluded by any row, column, or block, so let's place it and recurse > r(a[:i]+m+a[i+1:]) # no solution found # If we come here, there was no solution for the input data. # We return to the caller (should be the recursion above), # which will try a different solution instead. return Note: * The program is not ideal. It makes sense to find the cell with the least amount of possible numbers you could fill in, i.e. the most restricted cell. This is called "pruning" and should be explained in any good book, too. * The style is a bit confusing. Instead of the excluded numbers, use a set with the possible numbers (starting with 1-9) and then remove those that are excluded. Then, iterate over the remaining elements with "for m in possible_numbers". This double negation and also using exit() in the middle isn't really nice. Good luck! Uli From joan4eric at gmail.com Wed Mar 27 23:00:30 2013 From: joan4eric at gmail.com (Eric Parry) Date: Wed, 27 Mar 2013 20:00:30 -0700 (PDT) Subject: Sudoku In-Reply-To: <9dla2a-kql.ln1@satorlaser.homedns.org> References: <9dla2a-kql.ln1@satorlaser.homedns.org> Message-ID: <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> On Wednesday, March 27, 2013 6:28:01 PM UTC+10:30, Ulrich Eckhardt wrote: > Am 27.03.2013 06:44, schrieb Eric Parry: > > > I downloaded the following program from somewhere using a link from > > > Wikipedia and inserted the ?most difficult Sudoku puzzle ever? string > > > into it and ran it. It worked fine and solved the puzzle in about 4 > > > seconds. However I cannot understand how it works. > > > > > > In simple terms, it is using a depth-first search and backtracking. If > > you really want to understand this, get a book on algorithms and graphs > > (or locate an online source). I can try to give you an idea though. > > > > > > > It seems to go backwards and forwards at random. Can anyone explain > > > how it works in simple terms? > > > > I think your interpretation of what it does is wrong or at least flawed. > > It does try different combinations, but some don't lead to a solution. > > In that case, it goes back to a previous solution and tries the next one. > > > > > > I'll try to document the program to make it easier to understand... > > > > > def same_row(i,j): return (i/9 == j/9) > > > def same_col(i,j): return (i-j) % 9 == 0 > > > def same_block(i,j): return (i/27 == j/27 and i%9/3 == j%9/3) > > > > > > def r(a): > > # find an empty cell > > # If no empty cells are found, we have a solution that we print > > # and then terminate. > > > i = a.find('0') > > > if i == -1: > > > print a > > > exit(a) > > > > # find excluded numbers > > # Some numbers are blocked because they are already used in > > # the current column, row or block. This means they can't > > # possibly be used for the current empty cell. > > > excluded_numbers = set() > > > for j in range(81): > > > if same_row(i,j) or same_col(i,j) or same_block(i,j): > > > excluded_numbers.add(a[j]) > > > > # create possible solutions > > # Try all possibly numbers for the current empty cell in turn. > > # With the resulting modifications to the sodoku, use > > # recursion to find a full solution. > > > for m in '123456789': > > > if m not in excluded_numbers: > > > # At this point, m is not excluded by any row, column, or block, so let's place it and recurse > > > r(a[:i]+m+a[i+1:]) > > > > # no solution found > > # If we come here, there was no solution for the input data. > > # We return to the caller (should be the recursion above), > > # which will try a different solution instead. > > return > > > > > > Note: > > > > * The program is not ideal. It makes sense to find the cell with the > > least amount of possible numbers you could fill in, i.e. the most > > restricted cell. This is called "pruning" and should be explained in any > > good book, too. > > > > * The style is a bit confusing. Instead of the excluded numbers, use a > > set with the possible numbers (starting with 1-9) and then remove those > > that are excluded. Then, iterate over the remaining elements with "for m > > in possible_numbers". This double negation and also using exit() in the > > middle isn't really nice. > > > > > > Good luck! > > > > Uli Thank you for your explanation. I noticed that in this particular puzzle when it ran out of candidates in a particular cycle, it then changed the last entry to the next one in line in the previous cycle. But I cannot find any code to do this. I was hoping to understand the logic so that I could re-write it in VBA for excel which would enable any puzzle to be entered directly. Your comments are a big help especially the double negative aspect. Eric. From davea at davea.name Thu Mar 28 00:36:02 2013 From: davea at davea.name (Dave Angel) Date: Thu, 28 Mar 2013 00:36:02 -0400 Subject: Sudoku In-Reply-To: <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: <5153C8B2.1010608@davea.name> On 03/27/2013 11:00 PM, Eric Parry wrote: > On Wednesday, March 27, 2013 6:28:01 PM UTC+10:30, Ulrich Eckhardt wrote: >> > > Thank you for your explanation. > I noticed that in this particular puzzle when it ran out of candidates in a particular cycle, it then changed the last entry to the next one in line in the previous cycle. But I cannot find any code to do this. > I was hoping to understand the logic so that I could re-write it in VBA for excel which would enable any puzzle to be entered directly. > Your comments are a big help especially the double negative aspect. > Are you familiar with recursion? Notice the last line in the function r() calls the function r() inside a for loop. So when r() returns, you're back inside the next level up of the function, and doing a "backtrack." When the function succeeds, it will be many levels of recursion deep. For example, if the original pattern had 30 nonzero items in it, or 51 zeroes, you'll be 51 levels of recursion when you discover a solution. If you don't already understand recursion at all, then say so, and one or more of us will try to explain it in more depth. -- DaveA From joan4eric at gmail.com Thu Mar 28 18:11:14 2013 From: joan4eric at gmail.com (Eric Parry) Date: Thu, 28 Mar 2013 15:11:14 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: On Thursday, March 28, 2013 3:06:02 PM UTC+10:30, Dave Angel wrote: > On 03/27/2013 11:00 PM, Eric Parry wrote: > > > On Wednesday, March 27, 2013 6:28:01 PM UTC+10:30, Ulrich Eckhardt wrote: > > >> > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > > > > Thank you for your explanation. > > > I noticed that in this particular puzzle when it ran out of candidates in a particular cycle, it then changed the last entry to the next one in line in the previous cycle. But I cannot find any code to do this. > > > I was hoping to understand the logic so that I could re-write it in VBA for excel which would enable any puzzle to be entered directly. > > > Your comments are a big help especially the double negative aspect. > > > > > > > Are you familiar with recursion? Notice the last line in the function > > r() calls the function r() inside a for loop. > > > > So when r() returns, you're back inside the next level up of the > > function, and doing a "backtrack." > > > > When the function succeeds, it will be many levels of recursion deep. > > For example, if the original pattern had 30 nonzero items in it, or 51 > > zeroes, you'll be 51 levels of recursion when you discover a solution. > > > > If you don't already understand recursion at all, then say so, and one > > or more of us will try to explain it in more depth. > > > > -- > > DaveA Thank you for that explanation. No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. Eric. From joan4eric at gmail.com Thu Mar 28 18:11:14 2013 From: joan4eric at gmail.com (Eric Parry) Date: Thu, 28 Mar 2013 15:11:14 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: On Thursday, March 28, 2013 3:06:02 PM UTC+10:30, Dave Angel wrote: > On 03/27/2013 11:00 PM, Eric Parry wrote: > > > On Wednesday, March 27, 2013 6:28:01 PM UTC+10:30, Ulrich Eckhardt wrote: > > >> > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > > > > Thank you for your explanation. > > > I noticed that in this particular puzzle when it ran out of candidates in a particular cycle, it then changed the last entry to the next one in line in the previous cycle. But I cannot find any code to do this. > > > I was hoping to understand the logic so that I could re-write it in VBA for excel which would enable any puzzle to be entered directly. > > > Your comments are a big help especially the double negative aspect. > > > > > > > Are you familiar with recursion? Notice the last line in the function > > r() calls the function r() inside a for loop. > > > > So when r() returns, you're back inside the next level up of the > > function, and doing a "backtrack." > > > > When the function succeeds, it will be many levels of recursion deep. > > For example, if the original pattern had 30 nonzero items in it, or 51 > > zeroes, you'll be 51 levels of recursion when you discover a solution. > > > > If you don't already understand recursion at all, then say so, and one > > or more of us will try to explain it in more depth. > > > > -- > > DaveA Thank you for that explanation. No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. Eric. From rosuav at gmail.com Thu Mar 28 18:45:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 09:45:36 +1100 Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 9:11 AM, Eric Parry wrote: > Thank you for that explanation. > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is. :) Recursion is a form of self-referential code. Take this simple, and rather silly, means of calculating the sum of numbers in a list (like the sum() function): # The sum of numbers in an empty list is 0. # Otherwise it is the first number plus the sum of the rest of the list. def list_sum(lst): if not lst: return 0 return lst[0] + list_sum(lst[1:]) >>> list_sum([1,2,3,4,5,6]) 21 Note how the function calls itself - but not always. That's critical to recursion - a termination condition. In this case, it's quite obvious that the list will eventually have nothing left in it, so the function will terminate. Sometimes it's less obvious. Sometimes a bug results in infinite recursion... and: RuntimeError: maximum recursion depth exceeded in comparison Hope that helps! ChrisA From davea at davea.name Thu Mar 28 19:28:27 2013 From: davea at davea.name (Dave Angel) Date: Thu, 28 Mar 2013 19:28:27 -0400 Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: <5154D21B.8090902@davea.name> On 03/28/2013 06:11 PM, Eric Parry wrote: > On Thursday, March 28, 2013 3:06:02 PM UTC+10:30, Dave Angel wrote: >> >> >> Are you familiar with recursion? Notice the last line in the function >> r() calls the function r() inside a for loop. >> >> So when r() returns, you're back inside the next level up of the >> function, and doing a "backtrack." >> >> When the function succeeds, it will be many levels of recursion deep. >> For example, if the original pattern had 30 nonzero items in it, or 51 >> zeroes, you'll be 51 levels of recursion when you discover a solution. >> >> If you don't already understand recursion at all, then say so, and one >> or more of us will try to explain it in more depth. >> > > Thank you for that explanation. > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > Eric. > Recursion is not limited to Python. It's a general programming term, and indeed applies in other situations as well. Suppose you wanted to explain what the -r switch meant in the cp command. "r" stands for recursion. (example is from Linux. But if you're more familiar with Windows, it's the /s switch in the DIR command.) The cp command copies all the matching files in one directory to another one. If the -r switch is specified, it then does the same thing to each subdirectory. Notice we did NOT have to specify sub-subdirectories, since they're recursively implied by the first description. Closer to the current problem, suppose you defined factorial in the following way: factorial(0) is 1, by definition. And for all n>0, factorial(n) is n*factorial(n-1). So to directly translate this definition to code, you write a function factorial() which takes an integer and returns an integer. If the parameter is zero, return one. If the parameter is bigger than zero, then the function calls itself with a smaller integer, building up the answer as needed (untested). def factorial(n): if n==0: return 1 val = n *factorial(n-1) return val -- DaveA From joan4eric at gmail.com Fri Mar 29 01:07:27 2013 From: joan4eric at gmail.com (Eric Parry) Date: Thu, 28 Mar 2013 22:07:27 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: On Friday, March 29, 2013 9:58:27 AM UTC+10:30, Dave Angel wrote: > On 03/28/2013 06:11 PM, Eric Parry wrote: > > > On Thursday, March 28, 2013 3:06:02 PM UTC+10:30, Dave Angel wrote: > > > > > > > > >> > > >> > > >> Are you familiar with recursion? Notice the last line in the function > > >> r() calls the function r() inside a for loop. > > >> > > >> So when r() returns, you're back inside the next level up of the > > >> function, and doing a "backtrack." > > >> > > >> When the function succeeds, it will be many levels of recursion deep. > > >> For example, if the original pattern had 30 nonzero items in it, or 51 > > >> zeroes, you'll be 51 levels of recursion when you discover a solution. > > >> > > >> If you don't already understand recursion at all, then say so, and one > > >> or more of us will try to explain it in more depth. > > >> > > > > > > > > Thank you for that explanation. > > > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > > > Eric. > > > > > > > Recursion is not limited to Python. It's a general programming term, > > and indeed applies in other situations as well. Suppose you wanted to > > explain what the -r switch meant in the cp command. "r" stands for > > recursion. > > > > (example is from Linux. But if you're more familiar with Windows, it's > > the /s switch in the DIR command.) > > > > The cp command copies all the matching files in one directory to another > > one. If the -r switch is specified, it then does the same thing to each > > subdirectory. > > > > Notice we did NOT have to specify sub-subdirectories, since they're > > recursively implied by the first description. > > > > > > Closer to the current problem, suppose you defined factorial in the > > following way: factorial(0) is 1, by definition. And for all n>0, > > factorial(n) is n*factorial(n-1). > > > > So to directly translate this definition to code, you write a function > > factorial() which takes an integer and returns an integer. If the > > parameter is zero, return one. If the parameter is bigger than zero, > > then the function calls itself with a smaller integer, building up the > > answer as needed (untested). > > > > def factorial(n): > > if n==0: > > return 1 > > val = n *factorial(n-1) > > return val > > > > > > > > > > -- > > DaveA Thank you for that Dave, I've started writing the VBA code. Eric. From joan4eric at gmail.com Fri Mar 29 01:07:27 2013 From: joan4eric at gmail.com (Eric Parry) Date: Thu, 28 Mar 2013 22:07:27 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: On Friday, March 29, 2013 9:58:27 AM UTC+10:30, Dave Angel wrote: > On 03/28/2013 06:11 PM, Eric Parry wrote: > > > On Thursday, March 28, 2013 3:06:02 PM UTC+10:30, Dave Angel wrote: > > > > > > > > >> > > >> > > >> Are you familiar with recursion? Notice the last line in the function > > >> r() calls the function r() inside a for loop. > > >> > > >> So when r() returns, you're back inside the next level up of the > > >> function, and doing a "backtrack." > > >> > > >> When the function succeeds, it will be many levels of recursion deep. > > >> For example, if the original pattern had 30 nonzero items in it, or 51 > > >> zeroes, you'll be 51 levels of recursion when you discover a solution. > > >> > > >> If you don't already understand recursion at all, then say so, and one > > >> or more of us will try to explain it in more depth. > > >> > > > > > > > > Thank you for that explanation. > > > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > > > Eric. > > > > > > > Recursion is not limited to Python. It's a general programming term, > > and indeed applies in other situations as well. Suppose you wanted to > > explain what the -r switch meant in the cp command. "r" stands for > > recursion. > > > > (example is from Linux. But if you're more familiar with Windows, it's > > the /s switch in the DIR command.) > > > > The cp command copies all the matching files in one directory to another > > one. If the -r switch is specified, it then does the same thing to each > > subdirectory. > > > > Notice we did NOT have to specify sub-subdirectories, since they're > > recursively implied by the first description. > > > > > > Closer to the current problem, suppose you defined factorial in the > > following way: factorial(0) is 1, by definition. And for all n>0, > > factorial(n) is n*factorial(n-1). > > > > So to directly translate this definition to code, you write a function > > factorial() which takes an integer and returns an integer. If the > > parameter is zero, return one. If the parameter is bigger than zero, > > then the function calls itself with a smaller integer, building up the > > answer as needed (untested). > > > > def factorial(n): > > if n==0: > > return 1 > > val = n *factorial(n-1) > > return val > > > > > > > > > > -- > > DaveA Thank you for that Dave, I've started writing the VBA code. Eric. From joan4eric at gmail.com Fri Mar 29 17:47:31 2013 From: joan4eric at gmail.com (Eric Parry) Date: Fri, 29 Mar 2013 14:47:31 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> On Friday, March 29, 2013 9:15:36 AM UTC+10:30, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 9:11 AM, Eric Parry wrote: > > > Thank you for that explanation. > > > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > > > > If you already know what recursion is, just remember the answer. > > Otherwise, find someone who is standing closer to Douglas Hofstadter > > than you are; then ask him or her what recursion is. > > > > :) > > > > Recursion is a form of self-referential code. Take this simple, and > > rather silly, means of calculating the sum of numbers in a list (like > > the sum() function): > > > > # The sum of numbers in an empty list is 0. > > # Otherwise it is the first number plus the sum of the rest of the list. > > def list_sum(lst): > > if not lst: return 0 > > return lst[0] + list_sum(lst[1:]) > > > > >>> list_sum([1,2,3,4,5,6]) > > 21 > > > > Note how the function calls itself - but not always. That's critical > > to recursion - a termination condition. In this case, it's quite > > obvious that the list will eventually have nothing left in it, so the > > function will terminate. Sometimes it's less obvious. Sometimes a bug > > results in infinite recursion... and: > > > > RuntimeError: maximum recursion depth exceeded in comparison > > > > Hope that helps! > > > > ChrisA Thank you for that example Chris. That explains why the program keeps running after a solution is found. Eric From joan4eric at gmail.com Fri Mar 29 17:47:31 2013 From: joan4eric at gmail.com (Eric Parry) Date: Fri, 29 Mar 2013 14:47:31 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> Message-ID: <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> On Friday, March 29, 2013 9:15:36 AM UTC+10:30, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 9:11 AM, Eric Parry wrote: > > > Thank you for that explanation. > > > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > > > > If you already know what recursion is, just remember the answer. > > Otherwise, find someone who is standing closer to Douglas Hofstadter > > than you are; then ask him or her what recursion is. > > > > :) > > > > Recursion is a form of self-referential code. Take this simple, and > > rather silly, means of calculating the sum of numbers in a list (like > > the sum() function): > > > > # The sum of numbers in an empty list is 0. > > # Otherwise it is the first number plus the sum of the rest of the list. > > def list_sum(lst): > > if not lst: return 0 > > return lst[0] + list_sum(lst[1:]) > > > > >>> list_sum([1,2,3,4,5,6]) > > 21 > > > > Note how the function calls itself - but not always. That's critical > > to recursion - a termination condition. In this case, it's quite > > obvious that the list will eventually have nothing left in it, so the > > function will terminate. Sometimes it's less obvious. Sometimes a bug > > results in infinite recursion... and: > > > > RuntimeError: maximum recursion depth exceeded in comparison > > > > Hope that helps! > > > > ChrisA Thank you for that example Chris. That explains why the program keeps running after a solution is found. Eric From davea at davea.name Fri Mar 29 18:11:08 2013 From: davea at davea.name (Dave Angel) Date: Fri, 29 Mar 2013 18:11:08 -0400 Subject: Sudoku In-Reply-To: <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> Message-ID: <5156117C.1080604@davea.name> On 03/29/2013 05:47 PM, Eric Parry wrote: > >> >> > That explains why the program keeps running after a solution is found. A recursive function can be designed to find all solutions, in which case it would (as you say) keep running. The function you posted in the first place uses exit() to avoid keeping running. It stops as soon as a solution is found. Sometimes a problem cannot be solved in the number of stack entries supplied by Python. So even though such a function will terminate, it may crash first if the problem is too big. Example, the factorial problem I described earlier, if you pass it 2000 as a parameter. If this is a problem, one can tell the Python to give you more stack entries. Given a 9x9 matrix, and at least some of them filled in, the maximum depth your code can use is less than 81. So it won't get a stack overflow in any implementation of Python I've seen. Perhaps in an 8051. Sometimes a bug in such a function will cause it to run indefinitely, and/or to overflow the stack. I don't see such a bug in this function. -- DaveA From joan4eric at gmail.com Sat Mar 30 18:06:19 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sat, 30 Mar 2013 15:06:19 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> Message-ID: <95807259-513b-430a-80d1-2db853426159@googlegroups.com> On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > On 03/29/2013 05:47 PM, Eric Parry wrote: > > > > > >> > > >> > > > That explains why the program keeps running after a solution is found. > > > > A recursive function can be designed to find all solutions, in which > > case it would (as you say) keep running. > > > > The function you posted in the first place uses exit() to avoid keeping > > running. It stops as soon as a solution is found. > > > > Sometimes a problem cannot be solved in the number of stack entries > > supplied by Python. So even though such a function will terminate, it > > may crash first if the problem is too big. Example, the factorial > > problem I described earlier, if you pass it 2000 as a parameter. If > > this is a problem, one can tell the Python to give you more stack entries. > > > > Given a 9x9 matrix, and at least some of them filled in, the maximum > > depth your code can use is less than 81. So it won't get a stack > > overflow in any implementation of Python I've seen. Perhaps in an 8051. > > > > Sometimes a bug in such a function will cause it to run indefinitely, > > and/or to overflow the stack. I don't see such a bug in this function. > > > > > > -- > > DaveA The exit() did not work. I replaced it with return = 0, and that does work. Eric. From joan4eric at gmail.com Sat Mar 30 18:06:19 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sat, 30 Mar 2013 15:06:19 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> Message-ID: <95807259-513b-430a-80d1-2db853426159@googlegroups.com> On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > On 03/29/2013 05:47 PM, Eric Parry wrote: > > > > > >> > > >> > > > That explains why the program keeps running after a solution is found. > > > > A recursive function can be designed to find all solutions, in which > > case it would (as you say) keep running. > > > > The function you posted in the first place uses exit() to avoid keeping > > running. It stops as soon as a solution is found. > > > > Sometimes a problem cannot be solved in the number of stack entries > > supplied by Python. So even though such a function will terminate, it > > may crash first if the problem is too big. Example, the factorial > > problem I described earlier, if you pass it 2000 as a parameter. If > > this is a problem, one can tell the Python to give you more stack entries. > > > > Given a 9x9 matrix, and at least some of them filled in, the maximum > > depth your code can use is less than 81. So it won't get a stack > > overflow in any implementation of Python I've seen. Perhaps in an 8051. > > > > Sometimes a bug in such a function will cause it to run indefinitely, > > and/or to overflow the stack. I don't see such a bug in this function. > > > > > > -- > > DaveA The exit() did not work. I replaced it with return = 0, and that does work. Eric. From davea at davea.name Sat Mar 30 19:15:36 2013 From: davea at davea.name (Dave Angel) Date: Sat, 30 Mar 2013 19:15:36 -0400 Subject: Sudoku In-Reply-To: <95807259-513b-430a-80d1-2db853426159@googlegroups.com> References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: <51577218.7030507@davea.name> On 03/30/2013 06:06 PM, Eric Parry wrote: > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: >> On 03/29/2013 05:47 PM, Eric Parry wrote: >> >>> >> >> Sometimes a bug in such a function will cause it to run indefinitely, >> >> and/or to overflow the stack. I don't see such a bug in this function. >> >> >> >> >> >> -- >> >> DaveA > > The exit() did not work. Would you like to elaborate? exit() is supposed to take an int parameter, but the author apparently didn't notice that. So perhaps you got an exception of some sort. Change it to exit() or exit(0) and it might solve the problem, depending on what the problem was. > I replaced it with return = 0, and that does work. No it doesn't. return = 0 is a syntax error in both Python 2.x and 3.x But if you changed it to a valid return statement, then that's why it doesn't stop on the first solution. -- DaveA From joan4eric at gmail.com Sun Mar 31 18:03:47 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sun, 31 Mar 2013 15:03:47 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote: > On 03/30/2013 06:06 PM, Eric Parry wrote: > > > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > > >> On 03/29/2013 05:47 PM, Eric Parry wrote: > > >> > > >>> > > >> > > >> Sometimes a bug in such a function will cause it to run indefinitely, > > >> > > >> and/or to overflow the stack. I don't see such a bug in this function. > > >> > > >> > > >> > > >> > > >> > > >> -- > > >> > > >> DaveA > > > > > > The exit() did not work. > > > > Would you like to elaborate? exit() is supposed to take an int > > parameter, but the author apparently didn't notice that. So perhaps you > > got an exception of some sort. Change it to exit() or exit(0) and it > > might solve the problem, depending on what the problem was. > > > > > I replaced it with return = 0, and that does work. > > > > No it doesn't. return = 0 is a syntax error in both Python 2.x and 3.x > > > > But if you changed it to a valid return statement, then that's why it > > doesn't stop on the first solution. > > > > > > -- > > DaveA I think in the original it was exit(a). That did not work either. I'll try the others. Eric. From joan4eric at gmail.com Sun Mar 31 18:03:47 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sun, 31 Mar 2013 15:03:47 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote: > On 03/30/2013 06:06 PM, Eric Parry wrote: > > > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > > >> On 03/29/2013 05:47 PM, Eric Parry wrote: > > >> > > >>> > > >> > > >> Sometimes a bug in such a function will cause it to run indefinitely, > > >> > > >> and/or to overflow the stack. I don't see such a bug in this function. > > >> > > >> > > >> > > >> > > >> > > >> -- > > >> > > >> DaveA > > > > > > The exit() did not work. > > > > Would you like to elaborate? exit() is supposed to take an int > > parameter, but the author apparently didn't notice that. So perhaps you > > got an exception of some sort. Change it to exit() or exit(0) and it > > might solve the problem, depending on what the problem was. > > > > > I replaced it with return = 0, and that does work. > > > > No it doesn't. return = 0 is a syntax error in both Python 2.x and 3.x > > > > But if you changed it to a valid return statement, then that's why it > > doesn't stop on the first solution. > > > > > > -- > > DaveA I think in the original it was exit(a). That did not work either. I'll try the others. Eric. From davea at davea.name Sun Mar 31 18:34:19 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 18:34:19 -0400 Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: <5158B9EB.3050307@davea.name> On 03/31/2013 06:03 PM, Eric Parry wrote: > >> >> > > I think in the original it was exit(a). That did not work either. There you go again. "Did not work" tells us very little. With my Python 2.7.2, exit(something) with something being a string prints the string and then exits. Nowhere have I seen that documented, and I thought it either took an int or nothing. So please be much more specific. Did it give some exception, or did it not print the right result (I don't see any print statement in the code), or what? -- DaveA From arnodel at gmail.com Sun Mar 31 18:59:38 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 31 Mar 2013 23:59:38 +0100 Subject: Sudoku In-Reply-To: <5158B9EB.3050307@davea.name> References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> <5158B9EB.3050307@davea.name> Message-ID: On 31 March 2013 23:34, Dave Angel wrote: >[...] With my Python > 2.7.2, exit(something) with something being a string prints the string and > then exits. Nowhere have I seen that documented, and I thought it either > took an int or nothing. It is documented, just not exactly where you'd expect it (exit is a constant, not a function): http://docs.python.org/2/library/constants.html#constants-added-by-the-site-module As for the behaviour when you pass a string, it's documented here: http://docs.python.org/2/library/exceptions.html#exceptions.SystemExit -- Arnaud From joan4eric at gmail.com Sun Mar 31 18:27:44 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sun, 31 Mar 2013 15:27:44 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: On Monday, April 1, 2013 8:33:47 AM UTC+10:30, Eric Parry wrote: > On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote: > > > On 03/30/2013 06:06 PM, Eric Parry wrote: > > > > > > > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > > > > > > >> On 03/29/2013 05:47 PM, Eric Parry wrote: > > > > > > >> > > > > > > >>> > > > > > > >> > > > > > > >> Sometimes a bug in such a function will cause it to run indefinitely, > > > > > > >> > > > > > > >> and/or to overflow the stack. I don't see such a bug in this function. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> -- > > > > > > >> > > > > > > >> DaveA > > > > > > > > > > > > > > The exit() did not work. > > > > > > > > > > > > Would you like to elaborate? exit() is supposed to take an int > > > > > > parameter, but the author apparently didn't notice that. So perhaps you > > > > > > got an exception of some sort. Change it to exit() or exit(0) and it > > > > > > might solve the problem, depending on what the problem was. > > > > > > > > > > > > > I replaced it with return = 0, and that does work. > > > > > > > > > > > > No it doesn't. return = 0 is a syntax error in both Python 2.x and 3.x > > > > > > > > > > > > But if you changed it to a valid return statement, then that's why it > > > > > > doesn't stop on the first solution. > > > > > > > > > > > > > > > > > > -- > > > > > > DaveA > > > > I think in the original it was exit(a). That did not work either. > > I'll try the others. > > Eric. I tried all those things. The program keeps running after the solution in every case. Never mind. It won't do that in VBA when I finish it. Eric. From joan4eric at gmail.com Sun Mar 31 18:27:44 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sun, 31 Mar 2013 15:27:44 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: On Monday, April 1, 2013 8:33:47 AM UTC+10:30, Eric Parry wrote: > On Sunday, March 31, 2013 9:45:36 AM UTC+10:30, Dave Angel wrote: > > > On 03/30/2013 06:06 PM, Eric Parry wrote: > > > > > > > On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote: > > > > > > >> On 03/29/2013 05:47 PM, Eric Parry wrote: > > > > > > >> > > > > > > >>> > > > > > > >> > > > > > > >> Sometimes a bug in such a function will cause it to run indefinitely, > > > > > > >> > > > > > > >> and/or to overflow the stack. I don't see such a bug in this function. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> -- > > > > > > >> > > > > > > >> DaveA > > > > > > > > > > > > > > The exit() did not work. > > > > > > > > > > > > Would you like to elaborate? exit() is supposed to take an int > > > > > > parameter, but the author apparently didn't notice that. So perhaps you > > > > > > got an exception of some sort. Change it to exit() or exit(0) and it > > > > > > might solve the problem, depending on what the problem was. > > > > > > > > > > > > > I replaced it with return = 0, and that does work. > > > > > > > > > > > > No it doesn't. return = 0 is a syntax error in both Python 2.x and 3.x > > > > > > > > > > > > But if you changed it to a valid return statement, then that's why it > > > > > > doesn't stop on the first solution. > > > > > > > > > > > > > > > > > > -- > > > > > > DaveA > > > > I think in the original it was exit(a). That did not work either. > > I'll try the others. > > Eric. I tried all those things. The program keeps running after the solution in every case. Never mind. It won't do that in VBA when I finish it. Eric. From rosuav at gmail.com Sun Mar 31 18:35:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 09:35:20 +1100 Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 9:27 AM, Eric Parry wrote: > [ chomp 128 lines of quoted text ] > > I tried all those things. The program keeps running after the solution in every case. Never mind. It won't do that in VBA when I finish it. > Eric. You have just spammed us with, and I counted them, one hundred and twenty-eight lines of quoted text. And you posted to both comp.lang.python and python-list, so some of us will have seen those lines twice. Please don't do this. If you MUST use Google Groups, check out this page, and try to adjust your posts to be more courteous. http://wiki.python.org/moin/GoogleGroupsPython Thanks! ChrisA From joan4eric at gmail.com Sun Mar 31 23:58:42 2013 From: joan4eric at gmail.com (Eric Parry) Date: Sun, 31 Mar 2013 20:58:42 -0700 (PDT) Subject: Sudoku In-Reply-To: References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> <17da5afc-7a9b-40ea-a544-6012dfeef3ce@googlegroups.com> <95807259-513b-430a-80d1-2db853426159@googlegroups.com> Message-ID: <94e2667b-3317-483f-869f-8038cc5a3d6a@googlegroups.com> Sorry. Won't happen again. signing off this topic. Eric. From damien.wyart at free.fr Wed Mar 27 04:49:38 2013 From: damien.wyart at free.fr (Damien Wyart) Date: Wed, 27 Mar 2013 09:49:38 +0100 Subject: Sudoku References: Message-ID: <5152b2a3$0$2128$426a34cc@news.free.fr> * Eric Parry in comp.lang.python: > I downloaded the following program from somewhere using a link from > Wikipedia and inserted the ?most difficult Sudoku puzzle ever? string > into it and ran it. It worked fine and solved the puzzle in about > 4 seconds. However I cannot understand how it works. It seems to go > backwards and forwards at random. Can anyone explain how it works in > simple terms? You might also be interested in the following: http://norvig.com/sudoku.html http://norvig.com/sudopy.shtml -- DW From davea at davea.name Wed Mar 27 05:38:48 2013 From: davea at davea.name (Dave Angel) Date: Wed, 27 Mar 2013 05:38:48 -0400 Subject: Sudoku In-Reply-To: References: Message-ID: <5152BE28.6090809@davea.name> On 03/27/2013 01:44 AM, Eric Parry wrote: > I downloaded the following program from somewhere It'd be good to show where you found it, and credit the apparent author. Bill Barksdale posted this in 2008 at: http://stackoverflow.com/questions/201461/shortest-sudoku-solver-in-python-how-does-it-work I don't know if there are older ones somewhere, but I didn't find any. I did find places that quoted his code without attribution. Another thing worth pointing out is that it's only valid for Python 2.x (naturally, since I don't think Python 3 was out at that point) using a link from Wikipedia and inserted the ?most difficult Sudoku puzzle ever? string into it and ran it. It worked fine and solved the puzzle in about 4 seconds. However I cannot understand how it works. It seems to go backwards and forwards at random. Can anyone explain how it works in simple terms? > Eric. > > > def same_row(i,j): return (i/9 == j/9) > def same_col(i,j): return (i-j) % 9 == 0 > def same_block(i,j): return (i/27 == j/27 and i%9/3 == j%9/3) > > def r(a): > i = a.find('0') > if i == -1: > print a > exit(a) > > excluded_numbers = set() > for j in range(81): > if same_row(i,j) or same_col(i,j) or same_block(i,j): > excluded_numbers.add(a[j]) > > for m in '123456789': > if m not in excluded_numbers: > # At this point, m is not excluded by any row, column, or block, so let's place it and recurse > r(a[:i]+m+a[i+1:]) > > r('800000000003600000070090200050007000000045700000100030001000068008500010090000400') > Sudoku solver where the puzzle is an 81 character string representing the puzzle read left-to-right, top-to-bottom, and 0 is a blank. > ? > -- DaveA From joan4eric at gmail.com Wed Mar 27 22:49:44 2013 From: joan4eric at gmail.com (Eric Parry) Date: Wed, 27 Mar 2013 19:49:44 -0700 (PDT) Subject: Sudoku In-Reply-To: References: Message-ID: <6fca647e-c671-4954-a2c1-bb6cb4a88d03@googlegroups.com> Thank you all for your help and suggestions. Eric From nh.jones01 at gmail.com Wed Mar 27 04:06:04 2013 From: nh.jones01 at gmail.com (Norah Jones) Date: Wed, 27 Mar 2013 08:06:04 +0000 Subject: Splitting a list into even size chunks in python? Message-ID: Hi, I have a list of arbitrary length, and I need to split it up into equal size chunks. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list fills up, add it to the first list and empty the second list for the next round of data, but this is potentially extremely expensive. I was wondering if anyone had a good solution to this for lists of any length This should work: l = range(1, 1000) print chunks(l, 10) -> [ [ 1..10 ], [ 11..20 ], .., [ 991..999 ] ] I was looking for something useful in itertools but I couldn't find anything obviously useful. Appretiate your help. From __peter__ at web.de Wed Mar 27 04:27:49 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Mar 2013 09:27:49 +0100 Subject: Splitting a list into even size chunks in python? References: Message-ID: Norah Jones wrote: > I have a list of arbitrary length, and I need to split it up into equal > size chunks. There are some obvious ways to do this, like keeping a > counter and two lists, and when the second list fills up, add it to the > first list and empty the second list for the next round of data, but this > is potentially extremely expensive. > > I was wondering if anyone had a good solution to this for lists of any > length > > This should work: > > l = range(1, 1000) > print chunks(l, 10) -> [ [ 1..10 ], [ 11..20 ], .., [ 991..999 ] ] > > I was looking for something useful in itertools but I couldn't find > anything obviously useful. Look again, for the grouper() recipe. For lists you can also use slicing: >>> items ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> n = 3 >>> [items[start:start+n] for start in range(0, len(items), n)] [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] From arnodel at gmail.com Wed Mar 27 16:19:05 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 27 Mar 2013 20:19:05 +0000 Subject: Splitting a list into even size chunks in python? In-Reply-To: References: Message-ID: On 27 March 2013 08:27, Peter Otten <__peter__ at web.de> wrote: > Look again, for the grouper() recipe. For lists you can also use slicing: > >>>> items > ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>>> n = 3 >>>> [items[start:start+n] for start in range(0, len(items), n)] > [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] Another way with islice (so it works for any iterable): >>> from itertools import islice >>> items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> n = 3 >>> list(iter(lambda i=iter(items):list(islice(i, n)),[])) [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] Not too readable though :) -- Arnaud From roy at panix.com Wed Mar 27 08:51:36 2013 From: roy at panix.com (Roy Smith) Date: Wed, 27 Mar 2013 08:51:36 -0400 Subject: Splitting a list into even size chunks in python? References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Look again, for the grouper() recipe. Grouper() is good tty.cooked() with just a little time.time() and crypt.salt() From rosuav at gmail.com Wed Mar 27 08:59:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 23:59:41 +1100 Subject: Splitting a list into even size chunks in python? In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 11:51 PM, Roy Smith wrote: > In article , > Peter Otten <__peter__ at web.de> wrote: > >> Look again, for the grouper() recipe. > > Grouper() is good tty.cooked() with just a little time.time() and > crypt.salt() Huh, an inversion of http://xkcd.com/282/ ChrisA From roy at panix.com Wed Mar 27 19:42:36 2013 From: roy at panix.com (Roy Smith) Date: Wed, 27 Mar 2013 19:42:36 -0400 Subject: Splitting a list into even size chunks in python? References: Message-ID: In article , Chris Angelico wrote: > On Wed, Mar 27, 2013 at 11:51 PM, Roy Smith wrote: > > In article , > > Peter Otten <__peter__ at web.de> wrote: > > > >> Look again, for the grouper() recipe. > > > > Grouper() is good tty.cooked() with just a little time.time() and > > crypt.salt() > > Huh, an inversion of http://xkcd.com/282/ > > ChrisA Thyme is an herb, not a spice. Randall should know better. From rosuav at gmail.com Wed Mar 27 20:15:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 11:15:08 +1100 Subject: Splitting a list into even size chunks in python? In-Reply-To: References: Message-ID: On Thu, Mar 28, 2013 at 10:42 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Wed, Mar 27, 2013 at 11:51 PM, Roy Smith wrote: >> > In article , >> > Peter Otten <__peter__ at web.de> wrote: >> > >> >> Look again, for the grouper() recipe. >> > >> > Grouper() is good tty.cooked() with just a little time.time() and >> > crypt.salt() >> >> Huh, an inversion of http://xkcd.com/282/ >> >> ChrisA > > Thyme is an herb, not a spice. Randall should know better. And in case this wasn't off topic enough already... That statement shows that you are, almost certainly, American - out here, I would say instead that thyme is a herb. ChrisA From frank at chagford.com Wed Mar 27 04:40:19 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 27 Mar 2013 10:40:19 +0200 Subject: True/False formats as 1/0 in a fixed width string Message-ID: Hi all This is a bit of trivia, really, as I don't need a solution. But someone might need it one day, so it is worth mentioning. >>> '{}'.format(True) 'True' >>> '{:<10}'.format(True) '1 ' One might want to format True/False in a fixed width string, but it returns 1/0 instead. Is there any way to make this work? Frank Millman From __peter__ at web.de Wed Mar 27 04:52:47 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Mar 2013 09:52:47 +0100 Subject: True/False formats as 1/0 in a fixed width string References: Message-ID: Frank Millman wrote: > >>> '{}'.format(True) > 'True' > >>> '{:<10}'.format(True) > '1 ' > > One might want to format True/False in a fixed width string, but it > returns 1/0 instead. Is there any way to make this work? >>> "{!s:<10}".format(True) 'True ' From frank at chagford.com Wed Mar 27 05:14:00 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 27 Mar 2013 11:14:00 +0200 Subject: True/False formats as 1/0 in a fixed width string In-Reply-To: References: Message-ID: On 27/03/2013 10:52, Peter Otten wrote: > Frank Millman wrote: > >> >>> '{}'.format(True) >> 'True' >> >>> '{:<10}'.format(True) >> '1' >> >> One might want to format True/False in a fixed width string, but it >> returns 1/0 instead. Is there any way to make this work? > >>>> "{!s:<10}".format(True) > 'True' > > Works perfectly. Thanks, Peter Frank From davea at davea.name Wed Mar 27 04:55:35 2013 From: davea at davea.name (Dave Angel) Date: Wed, 27 Mar 2013 04:55:35 -0400 Subject: True/False formats as 1/0 in a fixed width string In-Reply-To: References: Message-ID: <5152B407.50801@davea.name> On 03/27/2013 04:40 AM, Frank Millman wrote: > Hi all > > This is a bit of trivia, really, as I don't need a solution. > > But someone might need it one day, so it is worth mentioning. > > >>> '{}'.format(True) > 'True' > >>> '{:<10}'.format(True) > '1 ' > > One might want to format True/False in a fixed width string, but it > returns 1/0 instead. Is there any way to make this work? > > Frank Millman > Easiest way is to surround the boolean variable with repr() flag = True '{:<10}'.format(repr(flag)) An alternative is to just use something like: ["False ","True "][flag] making sure the two strings are of the same length. (You didn't specify version, but I tested these with CPython 2.7.3) -- DaveA From frank at chagford.com Wed Mar 27 05:22:16 2013 From: frank at chagford.com (Frank Millman) Date: Wed, 27 Mar 2013 11:22:16 +0200 Subject: True/False formats as 1/0 in a fixed width string In-Reply-To: <5152B407.50801@davea.name> References: <5152B407.50801@davea.name> Message-ID: On 27/03/2013 10:55, Dave Angel wrote: > On 03/27/2013 04:40 AM, Frank Millman wrote: >> Hi all >> >> This is a bit of trivia, really, as I don't need a solution. >> >> But someone might need it one day, so it is worth mentioning. >> >> >>> '{}'.format(True) >> 'True' >> >>> '{:<10}'.format(True) >> '1 ' >> >> One might want to format True/False in a fixed width string, but it >> returns 1/0 instead. Is there any way to make this work? >> >> Frank Millman >> > > Easiest way is to surround the boolean variable with repr() > > flag = True > '{:<10}'.format(repr(flag)) > > An alternative is to just use something like: > > ["False ","True "][flag] > > making sure the two strings are of the same length. > > (You didn't specify version, but I tested these with CPython 2.7.3) > Thanks, Dave. I am using CPython 3.3.0, which behaves the same for this purpose. Your solutions work, but in my case I am reading in data from a database, so I want to create a format string, and then just call print(format_string.format(*row)) so I can't easily modify the contents of a single column. Peter's solution works perfectly for this scenario - >>> '{!s:<10}'.format(True) 'True ' I had to look up what '!s' means. From the manual - "Three conversion flags are currently supported: '!s' which calls str() on the value, '!r' which calls repr() and '!a' which calls ascii()." Another obscure but useful tip to store away somewhere. Frank From nospam at nospam.com Wed Mar 27 07:22:03 2013 From: nospam at nospam.com (Gilles) Date: Wed, 27 Mar 2013 12:22:03 +0100 Subject: What web server for WSGI? Recommended book? Message-ID: Hello After going through multiple articles about the advantage of using WSGI instead of FastCGI + Flup to run Python web apps, I have a couple of questions: 1. Which server + WSGI module would you recommend? I know about Apache and Graham Dumpleton's mod_wsgi, but what about Lighttpd and Nginx? I read that Nginx's mod_wsgi written by Manlio Perillo is not recommended. 2. At this point, is there a recommended book to learn how to write web applications in Python, preferably one that would first show the underlying mechanics before showing the main frameworks (web.py, Pylons, TurboGears, Django, etc.) so that I understand what's going on under the hood. Thank you. From lelli.luca at googlemail.com Wed Mar 27 07:29:50 2013 From: lelli.luca at googlemail.com (neurino) Date: Wed, 27 Mar 2013 12:29:50 +0100 Subject: From Perl to Python: restructuring a HPC workflow Message-ID: In the need for restructuring our daily workflow, i think it might be a good idea to ask the Python community and hopefully initiate a thread about pros and cons. We are a small group of people (approx. 10), working separetely on their own projects (each employee manages approx. 2-3 projects). We deal with high loads of data everyday. While the processing is accomplished with fortran and C programs mainly on three systems (one cluster, two standalone IBM HPCs, 8852 and p770, all managed by a grid-Engine), networking, pre/postprocessing, jobs queue administration and numerical analysis have been accomplished with Perl. This workflow has been flawless now for at least 15 years. New generations of employees have been given Perl scripts and they developed the tools further. If i think at the actual situation of Perl, i can't see a shiny time ahead. Perl 6 is far to be a reliable solution, the CPAN archive is slowing down. My idea is to persuade my colleagues to move toward Python-based solutions. But our concerns are that, in 3-4 years from now, the tools we are going to develop must be still scalable, mantainable, portable and of high-performance. We don't have any solid in-house know-how on Python. We just have to start everything from scracth. Where do you see advantages and drawbacks in switching from Perl to Python, given the work picture above? Thanks in advance for any opinions you might have. From rustompmody at gmail.com Wed Mar 27 07:51:10 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Mar 2013 04:51:10 -0700 (PDT) Subject: From Perl to Python: restructuring a HPC workflow References: Message-ID: <8a301e20-9de8-4563-bcd9-478b0a9a20f6@z4g2000pbw.googlegroups.com> On Mar 27, 4:29?pm, neurino wrote: > In the need for restructuring our daily workflow, i think it might be a > good idea to ask the Python community and hopefully initiate a thread > about pros and cons. > > We are a small group of people (approx. 10), working separetely on > their own projects (each employee manages approx. 2-3 projects). We > deal with high loads of data everyday. > > While the processing is accomplished with fortran and C programs mainly > on three systems (one cluster, two standalone IBM HPCs, ?8852 and p770, > all managed by a grid-Engine), networking, pre/postprocessing, jobs > queue administration and numerical analysis have been accomplished with > Perl. > > This workflow has been flawless now for at least 15 years. New > generations of employees have been given Perl scripts and they > developed the tools further. > > If i think at the actual situation of Perl, i can't see a shiny time > ahead. Perl 6 is far to be a reliable solution, the CPAN archive is > slowing down. My idea is to persuade my colleagues to move toward > Python-based solutions. But our concerns are that, in 3-4 years from > now, the tools we are going to develop must be still scalable, > mantainable, portable and of high-performance. > > We don't have any solid in-house know-how on Python. We just have to > start everything from scracth. Where do you see advantages and > drawbacks in switching from Perl to Python, given the work picture > above? > > Thanks in advance for any opinions you might have. Switching is always a con; see http://www.joelonsoftware.com/articles/fog0000000069.html Assuming you have that under your belt - if python is the way to go, asking on the scipy/numpy and ipython lists may give you more specific answers. - And if the 'rewrite-bug' has really got you, remember that if perl is old, C/Fortran are older. There are options today for rewriting the whole system, such as haskell and julia http://julialang.org/ WARNING: If the Spolsky warning above for perl->python is X units, take it 2X for Haskell and 4X for Julia! From joel.goldstick at gmail.com Wed Mar 27 08:23:55 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 27 Mar 2013 08:23:55 -0400 Subject: From Perl to Python: restructuring a HPC workflow In-Reply-To: <8a301e20-9de8-4563-bcd9-478b0a9a20f6@z4g2000pbw.googlegroups.com> References: <8a301e20-9de8-4563-bcd9-478b0a9a20f6@z4g2000pbw.googlegroups.com> Message-ID: On Wed, Mar 27, 2013 at 7:51 AM, rusi wrote: > On Mar 27, 4:29 pm, neurino wrote: > > In the need for restructuring our daily workflow, i think it might be a > > good idea to ask the Python community and hopefully initiate a thread > > about pros and cons. > > > > We are a small group of people (approx. 10), working separetely on > > their own projects (each employee manages approx. 2-3 projects). We > > deal with high loads of data everyday. > > > > While the processing is accomplished with fortran and C programs mainly > > on three systems (one cluster, two standalone IBM HPCs, 8852 and p770, > > all managed by a grid-Engine), networking, pre/postprocessing, jobs > > queue administration and numerical analysis have been accomplished with > > Perl. > > > > This workflow has been flawless now for at least 15 years. New > > generations of employees have been given Perl scripts and they > > developed the tools further. > So for 15 years the workflow is flawless, yet you want to throw it all out? I don't understand that > > > > If i think at the actual situation of Perl, i can't see a shiny time > > ahead. Perl 6 is far to be a reliable solution, the CPAN archive is > > slowing down. My idea is to persuade my colleagues to move toward > > Python-based solutions. > So you want to change things but your colleagues don't? > But our concerns are that, in 3-4 years from > > now, the tools we are going to develop must be still scalable, > > mantainable, portable and of high-performance. > > > > > We don't have any solid in-house know-how on Python. We just have to > > start everything from scracth. Where do you see advantages and > > drawbacks in switching from Perl to Python, given the work picture > > above? > > > > Thanks in advance for any opinions you might have. > > Python is a lot easier to read than perl. > Switching is always a con; see > http://www.joelonsoftware.com/articles/fog0000000069.html > Assuming you have that under your belt > - if python is the way to go, asking on the scipy/numpy and ipython > lists may give you more specific answers. > - And if the 'rewrite-bug' has really got you, remember that if perl > is old, C/Fortran are older. > There are options today for rewriting the whole system, such as > haskell and julia http://julialang.org/ > > WARNING: If the Spolsky warning above for perl->python is X units, > take it 2X for Haskell and 4X for Julia! > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Mar 27 08:58:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Mar 2013 23:58:16 +1100 Subject: From Perl to Python: restructuring a HPC workflow In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 10:29 PM, neurino wrote: > We are a small group of people (approx. 10), working separetely on their own > projects (each employee manages approx. 2-3 projects). We deal with high > loads of data everyday. > > This workflow has been flawless now for at least 15 years. New generations > of employees have been given Perl scripts and they developed the tools > further. I would recommend making sure the tools can all interoperate regardless of language, and then you can change any one at any time. Chances are that's already the case - working with stdin/stdout is one of the easiest ways to do that, for instance. With a structure that lets anyone use any language, you can then switch some of your things to Python, and demonstrate the readability advantages (which would you rather code in, pseudocode or line noise?). Make the switch as smooth as possible, and people will take it when it feels right. ChrisA From rustompmody at gmail.com Fri Mar 29 08:20:00 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 05:20:00 -0700 (PDT) Subject: From Perl to Python: restructuring a HPC workflow References: Message-ID: <9923c974-b0f7-402e-9610-dd9963f799ef@ou9g2000pbb.googlegroups.com> On Mar 27, 5:58?pm, Chris Angelico wrote: > On Wed, Mar 27, 2013 at 10:29 PM, neurino wrote: > > We are a small group of people (approx. 10), working separetely on their own > > projects (each employee manages approx. 2-3 projects). We deal with high > > loads of data everyday. > > > This workflow has been flawless now for at least 15 years. New generations > > of employees have been given Perl scripts and they developed the tools > > further. > > I would recommend making sure the tools can all interoperate > regardless of language, and then you can change any one at any time. > Chances are that's already the case - working with stdin/stdout is one > of the easiest ways to do that, for instance. With a structure that > lets anyone use any language, you can then switch some of your things > to Python, and demonstrate the readability advantages (which would you > rather code in, pseudocode or line noise?). Make the switch as smooth > as possible, and people will take it when it feels right. > > ChrisA What Chris says is fine in the technical sphere. It seems to me however that your problems are as much human as technical -- convincing entrenched old fogeys to change. No I dont have any cooked answers for that? You just need to keep your eyes and ears open to see where you want a smooth painless transition and when you want to 'do it with a bang.' If you look at some of the stuff here http://blog.explainmydata.com/2012/07/expensive-lessons-in-python-performance.html you may find that these packages do much of what you want (And add matplotlib to the set) This may add some pizzazz to your case. Warning: In my experience, this can often backfire! From jcasale at activenetwerx.com Wed Mar 27 15:49:54 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 27 Mar 2013 19:49:54 +0000 Subject: Decorator help Message-ID: I have a class?which?sets up some class vars, then several methods that are passed in data and do work?referencing the class vars. I want to decorate these methods, the decorator needs access to the class vars, so I thought about making the decorator its own class and allowing it to accept args. I was hoping to do all the work on?in_data from within the decorator, which requires access to several?MyClass vars. Not clear on the syntax/usage with this approach here, any guidance would be greatly appreciated! Class MyDecorator(object): ? ? def __init__(self, arg1, arg2): ? ? ? ? self.arg1?=?arg1 ? ? ? ? self.arg2?=?arg2 ? ? ... Class MyClass(object): ? ? def __init__(self): ? ? ? ? self.var_a = .... ? ? .... ? ? @MyDecorator(...) ? ? def meth_one(self, in_data): ? ? ? ? ... Thanks! jlc From arnodel at gmail.com Wed Mar 27 16:21:37 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 27 Mar 2013 20:21:37 +0000 Subject: Decorator help In-Reply-To: References: Message-ID: On 27 March 2013 19:49, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that are passed in data > and do work referencing the class vars. > > > I want to decorate these methods, the decorator needs access to the class vars, so I thought > about making the decorator its own class and allowing it to accept args. > > > I was hoping to do all the work on in_data from within the decorator, which requires access > to several MyClass vars. Not clear on the syntax/usage with this approach here, any guidance > would be greatly appreciated! > > > Class MyDecorator(object): > > def __init__(self, arg1, arg2): > self.arg1 = arg1 > self.arg2 = arg2 > ... > > > Class MyClass(object): > def __init__(self): > self.var_a = .... > .... > @MyDecorator(...) > def meth_one(self, in_data): > ... I don't really understand what you are trying to do. It would be easier if you had some code that tried to do something (even if it doesn't quite work). -- Arnaud From jason.swails at gmail.com Wed Mar 27 16:33:08 2013 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 27 Mar 2013 16:33:08 -0400 Subject: Decorator help In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 3:49 PM, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that > are passed in data > and do work referencing the class vars. > > > I want to decorate these methods, the decorator needs access to the class > vars, so I thought > about making the decorator its own class and allowing it to accept args. > > > I was hoping to do all the work on in_data from within the decorator, > which requires access > to several MyClass vars. Not clear on the syntax/usage with this approach > here, any guidance > would be greatly appreciated! > My guess is that you don't quite 'get' decorators yet (since I remember similar types of questions when trying to learn them myself). Decorators execute when the class type itself is being built (e.g., when a module is first imported at runtime). So decorators will never take instance variables as arguments (nor should they, since no instance can possibly exist when they execute). Bear in mind, a decorator should take a callable as an argument (and any number of 'static' parameters you want to assign it), and return another callable. I provide an example decorator using the format the I typically adopt below (where the decorator is a simple function, not a class): def my_decorator(fcn): """ Decorator for a function """ def new_fcn(self, *args, **kwargs): """ This is the new function that we will return. """ # You can access any instance variables here returnval = fcn(self, *args, **kwargs) # Do anything else here with instance variables return returnval # or any other return value you want return new_fcn Notice here I define a new_fcn callable function that takes self and an arbitrary argument/keyword-argument list, and I return this function (which does not get called) to replace the function I passed in. You can use instance variables inside new_fcn since new_fcn is called by instances of MyClass. This is a very simple type of decorator, but hopefully helps illustrate what decorators are. There is a particularly good thread on SO with information about decorators here: http://stackoverflow.com/questions/739654/understanding-python-decorators Hope this helps, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcasale at activenetwerx.com Wed Mar 27 16:41:48 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Wed, 27 Mar 2013 20:41:48 +0000 Subject: Decorator help In-Reply-To: References: , Message-ID: >?So decorators will never take instance variables as arguments (nor should they, since no instance > can possibly exist when they execute). Right, I never thought of it that way, my only use of them has been trivial, in non class?scenarios?so far. > Bear in mind, a decorator should take a callable as an argument (and any number of 'static' parameters > you want to assign it), and return another callable. Got it, and thanks for the detail as well! jlc From steve+comp.lang.python at pearwood.info Wed Mar 27 19:29:56 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2013 23:29:56 GMT Subject: Decorator help References: Message-ID: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 19:49:54 +0000, Joseph L. Casale wrote: > I have a class?which?sets up some class vars, then several methods that > are passed in data and do work?referencing the class vars. When you say "class vars", do you mean variables which hold classes? Like "string vars" are variables which hold strings, and "int vars" are variables that hold ints? Classes (also known as types) are first-class objects in Python (no pun intended), unlike Java, and so you can store them in lists, returns them from functions, and bind them in variables. for aclass in list_of_classes: do_something_with(aclass) Consequently, when people talk about "class variables", it is ambiguous, which is why we prefer to use "class attribute" to refer to attributes on the class. For example: class Parrot(object): breed = "Norwegian Blue" # this is a class attribute def __init__(self, name="Polly"): self.name = name # this is an instance attribute def speak(self): s = "%s the %s says, 'Hello sailor!'" print(s % (self.name, self.breed)) Class attributes are attached to the class object itself, and are shared between all instances. Instance attributes are attached to the instance, where they over-ride any class attribute of the same name, and are not shared. In the following I am going to assume that you actually are talking about attributes, rather than an actual variable holding a class. > I want to decorate these methods, the decorator needs access to the > class vars, so I thought about making the decorator its own class and > allowing it to accept args. The one doesn't follow from the other. Writing decorators as classes is fairly unusual. Normally, they will be regular functions. If your decorator needs to store so much state that it needs to be a class, you're probably trying to do too much from a single decorator. There's more that you need to describe, such as what it is that the decorator actually does, and whether it does it once, when the decorator is called, or repeatedly, when the decorated method is called. The second case is the easiest. Suppose you have a class like this, with many methods which have code in common. Here's a toy example: def MyClass(object): x = "class attribute" def __init__(self, y): self.y = y def spam(self): do_stuff(self.x) do_stuff(self.y) print("spam spam spam spam") def ham(self): do_stuff(self.x) do_stuff(self.y) return "ham, a growing boy's best friend" def eggs(self, food="bacon"): do_stuff(self.x) do_stuff(self.y) return "green eggs and %s" % food A simple decorator function can simplify the common code: import functools def decorate(func): @functools.wraps(func) def inner(self, *args, **kwargs): # call the common, repeated, code do_stuff(self.x) do_stuff(self.y) # call the function being wrapped return func(self, *args, **kwargs) return inner def MyClass(object): x = "class attribute" def __init__(self, y): self.y = y @decorate def spam(self): print("spam spam spam spam") @decorate def ham(self): return "ham, a growing boy's best friend" @decorate def eggs(self, food="bacon"): return "green eggs and %s" % food Notice that because the decorator doesn't do any work until the decorated function is called, there is no difficulty in accessing attributes regardless of whether they are attached to the class or the instance. They won't be looked up until self is known. A more complicated case is where you need to do some pre-processing, and you *don't* want that calculation repeated every time the method is called. Decorators are fantastic for that case too, but here you cannot access instance attributes, since the instance doesn't exist yet. But you can access *class attributes*, as more-or-less ordinary local variables *inside* the class definition. Here's a working sketch of the sort of thing you can do. Copy and paste the following into a Python interactive session, and then see if you can follow what is being done when. # === cut === import functools def decorator_factory(a, b): # This is a factory function that returns a decorator. # First we do so pre-processing. This gets called only once (per # usage of the decorator). value = a*10 + b - 1 print("precalculation of value = %s" % value) def decorator(func): print("decorator called on method '%s'" % func.__name__) @functools.wraps(func) def inner(self, fe, fi, fo): return func(self, fe, fi, fo, fum=value) return inner # return the decorator return decorator class MyClass(object): spam = 42 ham = 23 @decorator_factory(spam, ham) def my_method(self, fe, fi, fo, fum): print(fe, fi, fo, fum) x = MyClass() x.my_method(1, 2, 3) # === end cut == Is your mind boggled yet? :-) Of course, decorators don't *have* to be functions, they can be any callable object, such as an instance with a __call__ method. But beware of making your code too clever. Decorators are powerful, but you can over do it, and make your code unreadable. > I was hoping to do all the work on?in_data from within the decorator, > which requires access to several?MyClass vars. Not clear on the > syntax/usage with this approach here, any guidance would be greatly > appreciated! It's not clear what you actually need to do, so I can't give you any more guidance apart from the sort of thing that is possible with decorators. -- Steven From jason.swails at gmail.com Wed Mar 27 22:38:11 2013 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 27 Mar 2013 22:38:11 -0400 Subject: Decorator help In-Reply-To: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 27, 2013 at 7:29 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > > The one doesn't follow from the other. Writing decorators as classes is > fairly unusual. Normally, they will be regular functions. If your > decorator needs to store so much state that it needs to be a class, > you're probably trying to do too much from a single decorator. > > There's more that you need to describe, such as what it is that the > decorator actually does, and whether it does it once, when the decorator > is called, or repeatedly, when the decorated method is called. > > The second case is the easiest. Suppose you have a class like this, with > many methods which have code in common. Here's a toy example: > > > def MyClass(object): > x = "class attribute" > > def __init__(self, y): > self.y = y > In the spirit of nit-picking, I'll point out that Steven meant to use the 'class' keyword instead of 'def' for MyClass. > def MyClass(object): > x = "class attribute" > > def __init__(self, y): > self.y = y > And here as well. It's potentially worth pointing out that this code will actually compile. It will even run, assuming you provide MyClass with a single argument. But it will always return None :). As per usual, the response was thorough and helpful -- I appreciate responses like these and how they've helped improve my command of Python. All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Mar 28 00:58:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 04:58:23 GMT Subject: Decorator help References: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5153cdef$0$29984$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Mar 2013 22:38:11 -0400, Jason Swails wrote: >> The second case is the easiest. Suppose you have a class like this, >> with many methods which have code in common. Here's a toy example: >> >> >> def MyClass(object): >> x = "class attribute" >> >> def __init__(self, y): >> self.y = y >> >> > In the spirit of nit-picking, I'll point out that Steven meant to use > the 'class' keyword instead of 'def' for MyClass. /face-palm So I did. Thanks for picking the nit. -- Steven From jcasale at activenetwerx.com Sat Mar 30 20:06:01 2013 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sun, 31 Mar 2013 00:06:01 +0000 Subject: Decorator help In-Reply-To: <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> References: , <515380f4$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: > When you say "class vars", do you mean variables which hold classes? You guessed correctly, and thanks for pointing out the ambiguity in my references. > The one doesn't follow from the other. Writing decorators as classes is? >?fairly unusual. Normally, they will be regular functions. I see, this I didn't know. I'll stick to this guideline now. >?A more complicated case is where you need to do some pre-processing, and? > you *don't* want that calculation repeated every time the method is > called. Decorators are fantastic for that case too, but here you cannot > access instance attributes, since the instance doesn't exist yet. But you >?can access *class attributes*, as more-or-less ordinary local variables >?*inside* the class definition. Here's a working sketch of the sort of >?thing you can do. Copy and paste the following into a Python interactive >?session, and then see if you can follow what is being done when. >?Is your mind boggled yet? :-) Steven, That was some of the coolest stuff I have seen a while. I had to wait until I had enough time to actually run this through and utilize it my own work. I haven't enjoyed Python this much since I first started using it. Can't thank you enough for the time and thorough example, that imparted loads of insight. jlc From dihedral88888 at googlemail.com Sat Mar 30 23:06:25 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 30 Mar 2013 20:06:25 -0700 (PDT) Subject: Decorator help In-Reply-To: References: Message-ID: <5b7e5dae-f651-4f83-b306-aa9facc7bcfb@googlegroups.com> Jason Swails? 2013?3?28????UTC+8??4?33?08???? > On Wed, Mar 27, 2013 at 3:49 PM, Joseph L. Casale wrote: > > I have a class?which?sets up some class vars, then several methods that are passed in data > > and do work?referencing the class vars. > > > > > > I want to decorate these methods, the decorator needs access to the class vars, so I thought > > about making the decorator its own class and allowing it to accept args. > > > > > > I was hoping to do all the work on?in_data from within the decorator, which requires access > > to several?MyClass vars. Not clear on the syntax/usage with this approach here, any guidance > > would be greatly appreciated! > > > > My guess is that you don't quite 'get' decorators yet (since I remember similar types of questions when trying to learn them myself). ?Decorators execute when the class type itself is being built (e.g., when a module is first imported at runtime). ?So decorators will never take instance variables as arguments (nor should they, since no instance can possibly exist when they execute). ?Bear in mind, a decorator should take a callable as an argument (and any number of 'static' parameters you want to assign it), and return another callable. > > > > I provide an example decorator using the format the I typically adopt below (where the decorator is a simple function, not a class): > > > def my_decorator(fcn): I might add default parameters here if I am programming in python to save the troubles of subclassing similar decorators. But that is only the stylish problem in python. I might need to translate the decorator part into cython or c/c++ in the future. > ? ?""" Decorator for a function """ > > ? ?def new_fcn(self, *args, **kwargs): > ? ? ? """ This is the new function that we will return. """ > ? ? ? # You can access any instance variables here > ? ? ? returnval = fcn(self, *args, **kwargs) > > ? ? ? # Do anything else here with instance variables > ? ? ? return returnval # or any other return value you want > ? ? > ? ?return new_fcn > > > Notice here I define a new_fcn callable function that takes self and an arbitrary argument/keyword-argument list, and I return this function (which does not get called) to replace the function I passed in. ?You can use instance variables inside new_fcn since new_fcn is called by instances of MyClass. ?This is a very simple type of decorator, but hopefully helps illustrate what decorators are. ?There is a particularly good thread on SO with information about decorators here:?http://stackoverflow.com/questions/739654/understanding-python-decorators > > > > Hope this helps, > Jason From dihedral88888 at googlemail.com Sat Mar 30 23:06:25 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 30 Mar 2013 20:06:25 -0700 (PDT) Subject: Decorator help In-Reply-To: References: Message-ID: <5b7e5dae-f651-4f83-b306-aa9facc7bcfb@googlegroups.com> Jason Swails? 2013?3?28????UTC+8??4?33?08???? > On Wed, Mar 27, 2013 at 3:49 PM, Joseph L. Casale wrote: > > I have a class?which?sets up some class vars, then several methods that are passed in data > > and do work?referencing the class vars. > > > > > > I want to decorate these methods, the decorator needs access to the class vars, so I thought > > about making the decorator its own class and allowing it to accept args. > > > > > > I was hoping to do all the work on?in_data from within the decorator, which requires access > > to several?MyClass vars. Not clear on the syntax/usage with this approach here, any guidance > > would be greatly appreciated! > > > > My guess is that you don't quite 'get' decorators yet (since I remember similar types of questions when trying to learn them myself). ?Decorators execute when the class type itself is being built (e.g., when a module is first imported at runtime). ?So decorators will never take instance variables as arguments (nor should they, since no instance can possibly exist when they execute). ?Bear in mind, a decorator should take a callable as an argument (and any number of 'static' parameters you want to assign it), and return another callable. > > > > I provide an example decorator using the format the I typically adopt below (where the decorator is a simple function, not a class): > > > def my_decorator(fcn): I might add default parameters here if I am programming in python to save the troubles of subclassing similar decorators. But that is only the stylish problem in python. I might need to translate the decorator part into cython or c/c++ in the future. > ? ?""" Decorator for a function """ > > ? ?def new_fcn(self, *args, **kwargs): > ? ? ? """ This is the new function that we will return. """ > ? ? ? # You can access any instance variables here > ? ? ? returnval = fcn(self, *args, **kwargs) > > ? ? ? # Do anything else here with instance variables > ? ? ? return returnval # or any other return value you want > ? ? > ? ?return new_fcn > > > Notice here I define a new_fcn callable function that takes self and an arbitrary argument/keyword-argument list, and I return this function (which does not get called) to replace the function I passed in. ?You can use instance variables inside new_fcn since new_fcn is called by instances of MyClass. ?This is a very simple type of decorator, but hopefully helps illustrate what decorators are. ?There is a particularly good thread on SO with information about decorators here:?http://stackoverflow.com/questions/739654/understanding-python-decorators > > > > Hope this helps, > Jason From nikos.gr33k at gmail.com Wed Mar 27 16:18:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 13:18:47 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 Message-ID: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Hello folks, With what do i need to replace: ----------- print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) --------- and ---------- date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') ---------- in Python3? because in 2.6 used to work but they dont in Pytho 3 thank you. From rosuav at gmail.com Wed Mar 27 18:55:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 09:55:11 +1100 Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') For a start, figure out what you're trying to do. I'm trying to get my head around this line and I'm not getting anywhere. Is 'date' an instance of datetime.date()? And whatever it is, why do you then immediately rebind it? And why decode an arbitrary string using an arbitrary encoding? And why.... never mind. Start here: http://www.joelonsoftware.com/articles/Unicode.html One of Python 3's big features is that it forces you to distinguish text strings from binary ones. ChrisA From nikos.gr33k at gmail.com Wed Mar 27 22:16:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:16:00 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 12:55:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: > > > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') > > > > For a start, figure out what you're trying to do. I'm trying to get my > > head around this line and I'm not getting anywhere. Is 'date' an > > instance of datetime.date()? And whatever it is, why do you then > > immediately rebind it? And why decode an arbitrary string using an > > arbitrary encoding? And why.... never mind. Start here: > > > > http://www.joelonsoftware.com/articles/Unicode.html > > > > One of Python 3's big features is that it forces you to distinguish > > text strings from binary ones. > > > > ChrisA I had to use it like that in order for date to be appear correctly in greek otherwise it would seem like chinese. So now you mena i dont have to decode anym ore and use it liek that? date = date.strftime('%A, %e %b %Y').encode('utf8') From nikos.gr33k at gmail.com Wed Mar 27 22:16:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:16:00 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 12:55:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: > > > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') > > > > For a start, figure out what you're trying to do. I'm trying to get my > > head around this line and I'm not getting anywhere. Is 'date' an > > instance of datetime.date()? And whatever it is, why do you then > > immediately rebind it? And why decode an arbitrary string using an > > arbitrary encoding? And why.... never mind. Start here: > > > > http://www.joelonsoftware.com/articles/Unicode.html > > > > One of Python 3's big features is that it forces you to distinguish > > text strings from binary ones. > > > > ChrisA I had to use it like that in order for date to be appear correctly in greek otherwise it would seem like chinese. So now you mena i dont have to decode anym ore and use it liek that? date = date.strftime('%A, %e %b %Y').encode('utf8') From rosuav at gmail.com Wed Mar 27 22:28:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 13:28:04 +1100 Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 1:16 PM, ????? ???33? wrote: > ?? ??????, 28 ??????? 2013 12:55:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: >> >> > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') >> >> >> >> For a start, figure out what you're trying to do. I'm trying to get my >> >> head around this line and I'm not getting anywhere. Is 'date' an >> >> instance of datetime.date()? And whatever it is, why do you then >> >> immediately rebind it? And why decode an arbitrary string using an >> >> arbitrary encoding? And why.... never mind. Start here: >> >> >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> >> >> One of Python 3's big features is that it forces you to distinguish >> >> text strings from binary ones. >> >> >> >> ChrisA > > > I had to use it like that in order for date to be appear correctly in greek otherwise it would seem like chinese. > > So now you mena i dont have to decode anym ore and use it liek that? > > date = date.strftime('%A, %e %b %Y').encode('utf8') I mena, or mean, that you have to figure out what you're doing before you try to figure out how to do it. Or if you want help, then try providing context, like what data type 'date' is. (And inb4 someone points out that "it's a date, duh". :) ) ChrisA From nikos.gr33k at gmail.com Wed Mar 27 22:39:33 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:39:33 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: <17e017f0-0ac5-4ee3-b1a9-255005e2dd45@googlegroups.com> ?? ??????, 28 ??????? 2013 4:28:04 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 1:16 PM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 12:55:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: > > >> > > >> > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') > > >> > > >> > > >> > > >> For a start, figure out what you're trying to do. I'm trying to get my > > >> > > >> head around this line and I'm not getting anywhere. Is 'date' an > > >> > > >> instance of datetime.date()? And whatever it is, why do you then > > >> > > >> immediately rebind it? And why decode an arbitrary string using an > > >> > > >> arbitrary encoding? And why.... never mind. Start here: > > >> > > >> > > >> > > >> http://www.joelonsoftware.com/articles/Unicode.html > > >> > > >> > > >> > > >> One of Python 3's big features is that it forces you to distinguish > > >> > > >> text strings from binary ones. > > >> > > >> > > >> > > >> ChrisA > > > > > > > > > I had to use it like that in order for date to be appear correctly in greek otherwise it would seem like chinese. > > > > > > So now you mena i dont have to decode anym ore and use it liek that? > > > > > > date = date.strftime('%A, %e %b %Y').encode('utf8') > > > > I mena, or mean, that you have to figure out what you're doing before > > you try to figure out how to do it. > > > > Or if you want help, then try providing context, like what data type 'date' is. I'am just tryign to print the date with proper greek letters as it uses to work with Python v2.6 date gets calculated here: date = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S' ) I'am not sure but i believe that the decode must be taken out in python 3.x because objexts returned in unicoide now, but i'am not sure. From nikos.gr33k at gmail.com Wed Mar 27 22:39:33 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 19:39:33 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: <17e017f0-0ac5-4ee3-b1a9-255005e2dd45@googlegroups.com> ?? ??????, 28 ??????? 2013 4:28:04 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 1:16 PM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 12:55:11 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Thu, Mar 28, 2013 at 7:18 AM, ????? ???33? wrote: > > >> > > >> > date = date.strftime('%A, %e %b %Y').decode('cp1253').encode('utf8') > > >> > > >> > > >> > > >> For a start, figure out what you're trying to do. I'm trying to get my > > >> > > >> head around this line and I'm not getting anywhere. Is 'date' an > > >> > > >> instance of datetime.date()? And whatever it is, why do you then > > >> > > >> immediately rebind it? And why decode an arbitrary string using an > > >> > > >> arbitrary encoding? And why.... never mind. Start here: > > >> > > >> > > >> > > >> http://www.joelonsoftware.com/articles/Unicode.html > > >> > > >> > > >> > > >> One of Python 3's big features is that it forces you to distinguish > > >> > > >> text strings from binary ones. > > >> > > >> > > >> > > >> ChrisA > > > > > > > > > I had to use it like that in order for date to be appear correctly in greek otherwise it would seem like chinese. > > > > > > So now you mena i dont have to decode anym ore and use it liek that? > > > > > > date = date.strftime('%A, %e %b %Y').encode('utf8') > > > > I mena, or mean, that you have to figure out what you're doing before > > you try to figure out how to do it. > > > > Or if you want help, then try providing context, like what data type 'date' is. I'am just tryign to print the date with proper greek letters as it uses to work with Python v2.6 date gets calculated here: date = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S' ) I'am not sure but i believe that the decode must be taken out in python 3.x because objexts returned in unicoide now, but i'am not sure. From nikos.gr33k at gmail.com Thu Mar 28 05:43:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 02:43:50 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: <340ae7c2-74ca-4167-9bc3-29f232e2cd9e@googlegroups.com> I'am just tryign to print the date with proper greek letters as it uses to work with Python v2.6 date gets calculated here: date = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S' ) I'am not sure but i believe that the decode must be taken out in python 3.x because objexts returned in unicoide now, but i'am not sure. From nikos.gr33k at gmail.com Thu Mar 28 05:43:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 02:43:50 -0700 (PDT) Subject: Altering 2 statements from Python 2.6 => 3.2 In-Reply-To: References: <73865aec-bee1-4aea-b8b4-28a4cad24473@googlegroups.com> Message-ID: <340ae7c2-74ca-4167-9bc3-29f232e2cd9e@googlegroups.com> I'am just tryign to print the date with proper greek letters as it uses to work with Python v2.6 date gets calculated here: date = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S' ) I'am not sure but i believe that the decode must be taken out in python 3.x because objexts returned in unicoide now, but i'am not sure. From chrisjrn at gmail.com Wed Mar 27 19:08:49 2013 From: chrisjrn at gmail.com (Chris Neugebauer) Date: Wed, 27 Mar 2013 16:08:49 -0700 Subject: PyCon Australia 2013 Early Bird registration and Accommodation deals now available! Message-ID: tl;dr: PyCon Australia early bird registrations are now open! Find out more at http://2013.pycon-au.org/register/prices, including details of our accommodation programme. ** PyCon Australia is excited to announce that early bird conference registrations are now available for our 2013 conference, to be held on Saturday 6 and Sunday 6 July in Hobart, Tasmania. Early bird registration will be extended to the first 80 confirmed conference registrations, or until Friday 3 May, whichever comes first. PyCon Australia is the national conference for students, enthusiasts and professionals working with the Python programming language; it represents a unique opportunity for Python developers to meet fellow developers, and gain knowledge from experts and core Python developers from around Australia and the world. Securing your registration during the early bird period ensures your place at all of the events that PyCon Australia has to offer. Early bird registration comes with a substantial discount for tickets at our "Enthusiast" and "Professional" rates. Early bird tickets at both the "Enthusiast" and "Professional" level are guaranteed a seat at our conference dinner. All tickets include access to the CodeWars event on Friday 5 July, and the post-conference sprints on Monday 8 and Tuesday 9 July. Early bird registration starts at $44 for full-time students; $168 for enthusiasts and $420 for professionals. This year's conference also features two single-day miniconfs, being held on Friday 5 July: DjangoCon AU, the first national gathering of Australian Django developers; and the Python on OpenStack Day. Entry to these miniconfs is free for professional delegates, and $44 for students and enthusiasts. PyCon Australia has been working closely with our venue to provide a great conference experience; we're very pleased to be able to offer accommodation to delegates for the duration of the conference. We've secured an allocation of rooms within the Wrest Point complex. Rooms available to delegates start at $135 per night; rooms with wired internet access start at $157 per night. Information on conference registration, including details on how to book delegate accommodation through our preferred provider can be found at the PyCon Australia website (http://2013.pycon-au.org). Our conference Call for Proposals is still open, and will close on Friday 5 April. We can't wait to see you in Hobart in July! === About PyCon Australia === PyCon Australia is the national conference for the Python Programming Community. The fourth PyCon Australia will be held on July 5--7, 2013 in Hobart, Tasmania, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country?s Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2013, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Platinum sponsor: Australian Computer Society (Tasmanian Branch) (www.acs.org.au); and our Gold Sponsor, Google Australia (www.google.com.au). For full details of our sponsors, see our website. -- -- --Christopher Neugebauer Conference Coordinator and Sponsor Liaison PyCon Australia: Hobart 2013 -- http://pycon-au.org -- @pyconau 5?7 July 2013; CFP now open: closes 5 April -- http://pycon-au.org/cfp Jabber: chrisjrn at gmail.com -- IRC: chrisjrn on irc.freenode.net -- WWW: http://chris.neugebauer.id.au -- Twitter/Identi.ca: @chrisjrn From xxy-php at qq.com Wed Mar 27 22:54:43 2013 From: xxy-php at qq.com (=?gb18030?B?0KHRp9SwUEhQ?=) Date: Thu, 28 Mar 2013 10:54:43 +0800 Subject: Curl and python httplib? Message-ID: Guys, I take a project that need send request to Hadoop by curl. But now, the curl and pycurl can't satisfy my project. So i need use the powerful httplib. But failed. my curl request: curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" my return: HTTP/1.1 307 TEMPORARY_REDIRECT Content-Type: application/octet-stream Location: http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false Content-Length: 0 Server: Jetty(6.1.26) Now, i change the curl request to httplib: import httplib import urllib params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) headers={"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn=httplib.HTTPConnection("localhost:50070") conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) response=conn.getresponse() print response.status, response.reason data=response.read() print data conn.close() But it failed: #print response.status, response.reason 500 Internal Server Error #print data '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' Who knows why? It's OK when i use curl, so where is the problem in httplib method? Or some other reasons? Who can help me change the curl request to httplib edition? TIA Levi -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Mar 29 00:58:19 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 28 Mar 2013 21:58:19 -0700 Subject: Curl and python httplib? In-Reply-To: References: Message-ID: On Wed, Mar 27, 2013 at 7:54 PM, ???PHP wrote: > Guys, > > I take a project that need send request to Hadoop by curl. > But now, the curl and pycurl can't satisfy my project. So i need use the > powerful httplib. I would say that `requests` (http://docs.python-requests.org/en/latest/ ) is generally preferable to httplib these days. > But failed. > > my curl request: > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" > > my return: > HTTP/1.1 307 TEMPORARY_REDIRECT > Content-Type: application/octet-stream > Location: > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false > Content-Length: 0 > Server: Jetty(6.1.26) > > Now, i change the curl request to httplib: > import httplib > import urllib > > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) > headers={"Content-type": "application/x-www-form-urlencoded","Accept": > "text/plain"} > conn=httplib.HTTPConnection("localhost:50070") > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) > response=conn.getresponse() > print response.status, response.reason > data=response.read() > print data > conn.close() > > But it failed: > #print response.status, response.reason > 500 Internal Server Error > #print data > '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' > > Who knows why? It's OK when i use curl, so where is the problem in httplib > method? > Or some other reasons? It's rather hard to say when neither the base URL, nor querystring parameters, nor request body are the same between your curl example and your httplib example, making them rather incomparable. Part of the problem may be that you are passing what may have been intended as querystring parameters (`params`) as the `body` argument to HTTPConnection.request(). In any case, I would suggest trying to use the `requests` library instead. Cheers, Chris From nikos.gr33k at gmail.com Wed Mar 27 23:50:48 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 20:50:48 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... Message-ID: I'am about to go nuts with python 3.2.3 Do you see somehtign wrong with the following statement? cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) data = cur.fetchone() because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why. Please help. i'am using MySQLdb From rosuav at gmail.com Thu Mar 28 00:00:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 15:00:17 +1100 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: Message-ID: On Thu, Mar 28, 2013 at 2:50 PM, ????? ???33? wrote: > I'am about to go nuts with python 3.2.3 > > Do you see somehtign wrong with the following statement? > > cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) > data = cur.fetchone() > > because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why. > > Please help. i'am using MySQLdb Is this the docs for the module you're using? http://mysql-python.sourceforge.net/MySQLdb.html """ paramstyle String constant stating the type of parameter marker formatting expected by the interface. Set to 'format' = ANSI C printf format codes, e.g. '...WHERE name=%s'. If a mapping object is used for conn.execute(), then the interface actually uses 'pyformat' = Python extended format codes, e.g. '...WHERE name=%(name)s'. However, the API does not presently allow the specification of more than one style in paramstyle. Note that any literal percent signs in the query string passed to execute() must be escaped, i.e. %%. Parameter placeholders can only be used to insert column values. They can not be used for other parts of SQL, such as table names, statements, etc. """ What paramstyle are you using? ChrisA From nikos.gr33k at gmail.com Thu Mar 28 00:03:14 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:03:14 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: Message-ID: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> ?? ??????, 28 ??????? 2013 6:00:17 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > What paramstyle are you using? Yes it is Chris, but i'am not sure what exactly are you asking me. Please if you cna pout it even simper for me, thank you. From rosuav at gmail.com Thu Mar 28 00:08:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 15:08:28 +1100 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 3:03 PM, ????? ???33? wrote: > ?? ??????, 28 ??????? 2013 6:00:17 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > >> What paramstyle are you using? > > Yes it is Chris, but i'am not sure what exactly are you asking me. > Please if you cna pout it even simper for me, thank you. As it says in that document, paramstyle is a top-level module attribute. Try printing it out. See what it says. Then match your code to it. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 00:08:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:08:11 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <27d81c51-92cc-40bf-b9c3-701c19fca282@googlegroups.com> If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3 both this command fail in python 3.x cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) i dont have a clue why.... From rosuav at gmail.com Thu Mar 28 00:14:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 15:14:44 +1100 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <27d81c51-92cc-40bf-b9c3-701c19fca282@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <27d81c51-92cc-40bf-b9c3-701c19fca282@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 3:08 PM, ????? ???33? wrote: > If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3 Print out the value of that attribute. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 00:08:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:08:11 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <27d81c51-92cc-40bf-b9c3-701c19fca282@googlegroups.com> If you mean if iam using '?' or this '%s' the latter used to work flawlessly with python 2.6 but it does not in pythin 3.2.3 both this command fail in python 3.x cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) cur.execute( '''SELECT hits FROM counters WHERE url = %s''', (page,) ) i dont have a clue why.... From nikos.gr33k at gmail.com Thu Mar 28 00:03:14 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:03:14 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: Message-ID: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> ?? ??????, 28 ??????? 2013 6:00:17 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > What paramstyle are you using? Yes it is Chris, but i'am not sure what exactly are you asking me. Please if you cna pout it even simper for me, thank you. From nikos.gr33k at gmail.com Thu Mar 28 00:18:37 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:18:37 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > As it says in that document, paramstyle is a top-level module > attribute. Try printing it out. See what it says. Then match your code sql = '''SELECT hits FROM counters WHERE url = %s''' % page print( sql ) cur.execute( sql ) Now the error says: _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage From nikos.gr33k at gmail.com Thu Mar 28 00:18:37 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:18:37 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > As it says in that document, paramstyle is a top-level module > attribute. Try printing it out. See what it says. Then match your code sql = '''SELECT hits FROM counters WHERE url = %s''' % page print( sql ) cur.execute( sql ) Now the error says: _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage From rosuav at gmail.com Thu Mar 28 00:26:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 15:26:48 +1100 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 3:18 PM, ????? ???33? wrote: > ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > >> As it says in that document, paramstyle is a top-level module >> attribute. Try printing it out. See what it says. Then match your code > > sql = '''SELECT hits FROM counters WHERE url = %s''' % page > print( sql ) > cur.execute( sql ) > > Now the error says: > > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage http://www.facepalm.de/ Do you understand SQL injection attacks and the concept of parameterized queries? ChrisA From nikos.gr33k at gmail.com Thu Mar 28 00:30:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:30:44 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 6:26:48 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 3:18 PM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > > > > >> As it says in that document, paramstyle is a top-level module > > >> attribute. Try printing it out. See what it says. Then match your code > > > > > > sql = '''SELECT hits FROM counters WHERE url = %s''' % page > > > print( sql ) > > > cur.execute( sql ) > > > > > > Now the error says: > > > > > > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage > > > > http://www.facepalm.de/ > > > > Do you understand SQL injection attacks and the concept of > > parameterized queries? > > > > ChrisA Yes i know i'am not supposed to use "%s" and i dotn want to but you asked me to print the sql statemnt before executing it. please its 6:30am here in greece and didnt had any sleep yet. please tell me whats wrong.... From nikos.gr33k at gmail.com Thu Mar 28 00:30:44 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:30:44 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 6:26:48 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Thu, Mar 28, 2013 at 3:18 PM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > > > > >> As it says in that document, paramstyle is a top-level module > > >> attribute. Try printing it out. See what it says. Then match your code > > > > > > sql = '''SELECT hits FROM counters WHERE url = %s''' % page > > > print( sql ) > > > cur.execute( sql ) > > > > > > Now the error says: > > > > > > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage > > > > http://www.facepalm.de/ > > > > Do you understand SQL injection attacks and the concept of > > parameterized queries? > > > > ChrisA Yes i know i'am not supposed to use "%s" and i dotn want to but you asked me to print the sql statemnt before executing it. please its 6:30am here in greece and didnt had any sleep yet. please tell me whats wrong.... From rosuav at gmail.com Thu Mar 28 00:35:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2013 15:35:14 +1100 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 3:30 PM, ????? ???33? wrote: > ?? ??????, 28 ??????? 2013 6:26:48 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Thu, Mar 28, 2013 at 3:18 PM, ????? ???33? wrote: >> >> > ?? ??????, 28 ??????? 2013 6:08:28 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> >> > >> >> >> As it says in that document, paramstyle is a top-level module >> >> >> attribute. Try printing it out. See what it says. Then match your code >> >> > >> >> > sql = '''SELECT hits FROM counters WHERE url = %s''' % page >> >> > print( sql ) >> >> > cur.execute( sql ) >> >> > >> >> > Now the error says: >> >> > >> >> > _mysql_exceptions.OperationalError: (1054, "Unknown column 'index.html' in 'where clause'") as you cna see at my webpage >> >> >> >> http://www.facepalm.de/ >> >> >> >> Do you understand SQL injection attacks and the concept of >> >> parameterized queries? >> >> >> >> ChrisA > > Yes i know i'am not supposed to use "%s" and i dotn want to but you asked me to print the sql statemnt before executing it. > > please its 6:30am here in greece and didnt had any sleep yet. > please tell me whats wrong.... No. I said to print out the paramstyle attribute. If it's that late and you haven't slept, get some sleep, then reread this thread. You may be able to respond more intelligently. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 00:39:41 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:39:41 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: <28519666-ebd4-485e-b409-3260f2da379d@googlegroups.com> ?? ??????, 28 ??????? 2013 6:35:14 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > No. I said to print out the paramstyle attribute. If it's that late > > and you haven't slept, get some sleep, then reread this thread. You > > may be able to respond more intelligently. What is a paramstyle attribute? Tell me what exactly it is in simple words and i;ll print it for you. I can't get any sleep because ia'am too tense with this issue. From nikos.gr33k at gmail.com Thu Mar 28 00:39:41 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 27 Mar 2013 21:39:41 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> <19fcf06e-8923-410c-9acd-abd4534c77bf@googlegroups.com> Message-ID: <28519666-ebd4-485e-b409-3260f2da379d@googlegroups.com> ?? ??????, 28 ??????? 2013 6:35:14 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > No. I said to print out the paramstyle attribute. If it's that late > > and you haven't slept, get some sleep, then reread this thread. You > > may be able to respond more intelligently. What is a paramstyle attribute? Tell me what exactly it is in simple words and i;ll print it for you. I can't get any sleep because ia'am too tense with this issue. From nikos.gr33k at gmail.com Thu Mar 28 05:44:30 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 02:44:30 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: Can someone else esxcept Chris help me please? I'm strugling with this and cannot see whats wrong. From nikos.gr33k at gmail.com Thu Mar 28 05:44:30 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 02:44:30 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: Can someone else esxcept Chris help me please? I'm strugling with this and cannot see whats wrong. From chess at us.ibm.com Thu Mar 28 10:51:16 2013 From: chess at us.ibm.com (David M Chess) Date: Thu, 28 Mar 2013 10:51:16 -0400 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: ????? ???33? : >> What paramstyle are you using? > >Yes it is Chris, but i'am not sure what exactly are you asking me. >Please if you cna pout it even simper for me, thank you. For instance: >>> import MySQLdb >>> MySQLdb.paramstyle 'format' FWIW and HTH, DC -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Thu Mar 28 15:35:15 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 12:35:15 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <0bcd5977-5275-4812-8922-79d656fc4eed@googlegroups.com> ?? ??????, 28 ??????? 2013 4:51:16 ?.?. UTC+2, ? ??????? David M Chess ??????: > ????? ???33? > : > > > > >> What paramstyle are you using? > > > > > >Yes it is Chris, but i'am not sure what exactly are you asking me. > > >Please if you cna pout it even simper for me, thank you. > > > > For instance: > > > > >>> import MySQLdb > > >>> MySQLdb.paramstyle > > 'format' > > nikos at superhost.gr [~]# /usr/bin/python3 Python 3.2.3 (default, May 23 2012, 18:47:48) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> MySQLdb.paramstyle 'format' >>> From nikos.gr33k at gmail.com Thu Mar 28 15:35:15 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 12:35:15 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <2ac959c6-d169-452f-b622-83fe25fbd8da@googlegroups.com> Message-ID: <0bcd5977-5275-4812-8922-79d656fc4eed@googlegroups.com> ?? ??????, 28 ??????? 2013 4:51:16 ?.?. UTC+2, ? ??????? David M Chess ??????: > ????? ???33? > : > > > > >> What paramstyle are you using? > > > > > >Yes it is Chris, but i'am not sure what exactly are you asking me. > > >Please if you cna pout it even simper for me, thank you. > > > > For instance: > > > > >>> import MySQLdb > > >>> MySQLdb.paramstyle > > 'format' > > nikos at superhost.gr [~]# /usr/bin/python3 Python 3.2.3 (default, May 23 2012, 18:47:48) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> MySQLdb.paramstyle 'format' >>> From ameyer2 at yahoo.com Thu Mar 28 16:54:55 2013 From: ameyer2 at yahoo.com (Alan Meyer) Date: Thu, 28 Mar 2013 16:54:55 -0400 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: Message-ID: <5154AE1F.6010309@yahoo.com> On 3/27/2013 11:50 PM, ????? ???33? wrote: > I'am about to go nuts with python 3.2.3 > > Do you see somehtign wrong with the following statement? > > cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) > data = cur.fetchone() > > because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why. > > Please help. i'am using MySQLdb > Nikos, When I try to connect to that web page I see the following error message: "ImportError: No module named pymysql " If that's what you're getting, there's nothing wrong with your SQL or your cur.execute statement. The problem is that the web server is not finding the pymysql module. Is pymysql installed on the computer that is running your application? Can the web server module find it? I must be missing something because, if that's the problem, your object named "cur" could not have been created successfully. Maybe what I'm seeing is a new problem? Alan From nikos.gr33k at gmail.com Fri Mar 29 03:40:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 29 Mar 2013 00:40:00 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: <5154AE1F.6010309@yahoo.com> References: <5154AE1F.6010309@yahoo.com> Message-ID: ?? ??????, 28 ??????? 2013 10:54:55 ?.?. UTC+2, ? ??????? Alan Meyer ??????: > On 3/27/2013 11:50 PM, ????? ???33? wrote: > > > I'am about to go nuts with python 3.2.3 > > > > > > Do you see somehtign wrong with the following statement? > > > > > > cur.execute( '''SELECT hits FROM counters WHERE url = ?''', (page,) ) > > > data = cur.fetchone() > > > > > > because as you can see by visiting my webpage at http://superhost.gr it produces an error and i dont have aclue why. > > > > > > Please help. i'am using MySQLdb > > > > > Nikos, > > > > When I try to connect to that web page I see the following error message: > > > > "ImportError: No module named pymysql " > > > > If that's what you're getting, there's nothing wrong with your SQL or > > your cur.execute statement. The problem is that the web server is not > > finding the pymysql module. > > > > Is pymysql installed on the computer that is running your application? > > Can the web server module find it? > > > > I must be missing something because, if that's the problem, your object > > named "cur" could not have been created successfully. Maybe what I'm > > seeing is a new problem? > > > > Alan Hello Ala, well nto this is not the error, i uses to had MySQLdb as a conenctor but even withat that i still see a blank webpage without no errros. Then i had a suspision that perhaps MySQLdb isnt't supported in Python 3.2.3 so i decided to try pymysql but it wasnt there. I asked at hstgator support to install that module for me since iam not familiar with linux very much or pip but i got this response just now. Click here to rate this response. > > Hello again, > > Per your request, a virtual environment has been created for you. You can find local Python binaries in: > > /home/nikos/bin > > Unfortunately the pymysql module cannot be installed using pip or easy_install and must be installed manually. There is no indication that this module in any way requires Python 3. Is there a particular reason you must use Python 3 instead of a version which supports the modules that you need? Given that the modules you need are better supported by earlier versions of Python, it's not clear to me why we're trying to use Python 3 instead. > > If you would still like us to proceed with manually installing the pymysql module for the local version of Python under the nikos account, we will be happy to give it a try but there will be a one-time charge of $35.00 for the installation. I would recommend using an earlier version of Python which is compatible with the modules that you need, but it is certainly up to you. Please let us know how you would like to proceed. So, just to make sure that MySQLdb isnt causeing the probkem can someone, perhaps you that is familiar with linxu conenct to my jailed shell account and install manually the 'pymysql' module because i dont know how to do it and i cannot afford to pay ath linux admin because iam unemployed. please i can providr ou with user and pass for my jailed shell access for someone ti install it manually. From ameyer2 at yahoo.com Fri Mar 29 13:32:45 2013 From: ameyer2 at yahoo.com (Alan Meyer) Date: Fri, 29 Mar 2013 13:32:45 -0400 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <5154AE1F.6010309@yahoo.com> Message-ID: On 03/29/2013 03:40 AM, ????? ???33? wrote: ... > So, just to make sure that MySQLdb isnt causeing the probkem can > someone, perhaps you that is familiar with linxu conenct to my jailed > shell account and install manually the 'pymysql' module because i > dont know how to do it and i cannot afford to pay ath linux admin > because iam unemployed. > > please i can providr ou with user and pass for my jailed shell access > for someone ti install it manually. Sorry Nikos, I don't have time to do anything like that. I'm going nuts with my own programming problems and deadlines. However, MySQLdb is a well established module and what you're asking it to do is very simple and very standard. I can think of several obvious possibilities for you to pursue. The first one is, are you successfully connecting to the database at all? I suspect that you are not. You may have an error in your connection string - the host, userid, port number, database name, or password. That's the most likely problem. See if you can find some other program on your server that does successfully connect and look at the connection parameters. Be sure that you're checking the return value from your connect() call. If everything looks good, check to see if you have rights to the database and table you are trying to select from. Good luck. Alan From ameyer2 at yahoo.com Fri Mar 29 13:39:20 2013 From: ameyer2 at yahoo.com (Alan Meyer) Date: Fri, 29 Mar 2013 13:39:20 -0400 Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <5154AE1F.6010309@yahoo.com> Message-ID: On 03/29/2013 01:32 PM, Alan Meyer wrote: > However, MySQLdb is a well established module and what you're asking it > to do is very simple and very standard. Oh, sorry, I see that you already said that mysqldb won't work with python 3. My comments in the last message are irrelevant. Sorry again. Good luck. Alan From nagia.retsina at gmail.com Fri Mar 29 15:24:51 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 12:24:51 -0700 (PDT) Subject: Cannot run a single MySQLdb execute.... In-Reply-To: References: <5154AE1F.6010309@yahoo.com> Message-ID: <3d78c1da-a0a5-4e5a-8fa3-d76966eea5f4@googlegroups.com> ?? ?????????, 29 ??????? 2013 7:39:20 ?.?. UTC+2, ? ??????? Alan Meyer ??????: > On 03/29/2013 01:32 PM, Alan Meyer wrote: > > > > > However, MySQLdb is a well established module and what you're asking it > > > to do is very simple and very standard. > > > > Oh, sorry, I see that you already said that mysqldb won't work with > > python 3. My comments in the last message are irrelevant. > > > > Sorry again. > > > > Good luck. > > > > Alan Thanks Alan i decided to work with 'pymysql' and iam struggling to egt thbis working but i still receive the same blank page for some unknown reason..... From xiaojun.zhong at thomsonreuters.com Thu Mar 28 04:41:51 2013 From: xiaojun.zhong at thomsonreuters.com (xiaojun.zhong at thomsonreuters.com) Date: Thu, 28 Mar 2013 08:41:51 +0000 Subject: Need admin right to install wxPython2.8.win64-unicode-2.8.12.1-py27.exe in Win7 Message-ID: <68EDA06A10BEF344BACBB7A8F08A26B29C2426@SG1P-ERFMMBX01.ERF.thomson.com> Hi, When I using standard user account to install wxPython2.8-win64-unicode-2.8.12.1-py27.exe in Win7, it prompt me must be logged in as an admin when installing. Is there any solution to install wxPython without admin right? Thanks, Scott This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters. -------------- next part -------------- An HTML attachment was scrubbed... URL: From zingbagbamark at gmail.com Thu Mar 28 08:17:36 2013 From: zingbagbamark at gmail.com (zingbagbamark at gmail.com) Date: Thu, 28 Mar 2013 05:17:36 -0700 (PDT) Subject: Differentiation in Python Message-ID: How do I differentiate(first order and 2nd order) the following equations in python. I want to differentiate C wrt Q. C = (Q**3)-15*(Q**2)+ 93*Q + 100 From steve+comp.lang.python at pearwood.info Thu Mar 28 08:35:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2013 12:35:11 GMT Subject: Differentiation in Python References: Message-ID: <515438ff$0$29998$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 05:17:36 -0700, zingbagbamark wrote: > How do I differentiate(first order and 2nd order) the following > equations in python. I want to differentiate C wrt Q. > > C = (Q**3)-15*(Q**2)+ 93*Q + 100 For such a simple case, you don't do it with Python, you do it with maths, and get an exact result. dC/dQ = 3*Q**2 - 30*Q + 93 d?C/dQ? = 6*Q - 30 The rule for differentiating polynomials of the form y = k*x**n is: dy/dx = (k*n)*x**(n-1) Consult a good calculus text book or on-line site for further details. -- Steven From drobinow at gmail.com Thu Mar 28 14:16:08 2013 From: drobinow at gmail.com (David Robinow) Date: Thu, 28 Mar 2013 14:16:08 -0400 Subject: Differentiation in Python In-Reply-To: References: Message-ID: On Thu, Mar 28, 2013 at 8:17 AM, wrote: > How do I differentiate(first order and 2nd order) the following equations in python. I want to differentiate C wrt Q. > > C = (Q**3)-15*(Q**2)+ 93*Q + 100 """ Years ago, when I actually worked for a living, I would have done something like this: """ coeffs = [1, -15, 93, 100] num_coeffs = len(coeffs)-1 deriv = [coeffs[i]*(num_coeffs-i) for i in range(num_coeffs)] print(deriv) """ The above is somewhat obscure and requires one to add some documentation. Who wants to do that? Below is a version using numpy. You get the numpy docs for free. """ import numpy as np p = np.poly1d(coeffs) deriv_np = np.polyder(p) print(deriv_np) # or print(list(deriv_np)) From betatwelve at voila.fr Thu Mar 28 09:17:32 2013 From: betatwelve at voila.fr (betatwelve) Date: Thu, 28 Mar 2013 14:17:32 +0100 Subject: after discussing about the line Message-ID: <2858dcd@news.colorado.edu> Hiya all. it might be appropriate to imagine the remote surveillance of the color using up-to-date methodologies when studying the line with the color remote monitoring; We may also notice that, everybody should applicate this type of guidelines The hairline on the right side of the face creates a sweeping curve as it meets the neckline of the t-shirt. Such an approach was used to build our pencil portrait above. Take care where you choose to position them on the page as this will affect the overall balance of the portrait. The hairline on the right side of the face creates a sweeping curve as it meets the neckline of the t-shirt. The hairline on the right side of the face creates a sweeping curve as it meets the neckline of the t-shirt. Such an approach was used to build our pencil portrait above. Take care where you choose to position them on the page as this will affect the overall balance of the portrait. The hairline on the right side of the face creates a sweeping curve as it meets the neckline of the t-shirt. Such an approach was used to build our pencil portrait above. Take care where you choose to position them on the page as this will affect the overall balance of the portrait. The hairline on the right side of the face creates a sweeping curve as it meets the neckline of the t-shirt. ; would you mind detailing how to increase the focus on the line supervision and the collaboration with the color data analysis? tchao From Kene.Meniru at illom.org Thu Mar 28 09:49:06 2013 From: Kene.Meniru at illom.org (Kene Meniru) Date: Thu, 28 Mar 2013 09:49:06 -0400 Subject: Embed vtk window in a QTabWidget Message-ID: Hi: I know this may not be the right place to post this but I found some other PyQt questions and I am desperate. My app is the Window class object below and I am trying to embed a QVTKRenderWindowInteractor class called ConeWindow in its QTabWidget. First of all running ConeWindow gives out QPainter::begin:, QPainter::save:, QPainter::setClipRegion:, and QPainter::restore: messages. This may be what is crashing the Window class when I embed it. Can somebody help me here? Thanks. ------------------- #!/usr/bin/env python from PyQt4 import QtGui, QtCore import vtk from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor import sys class Window(QtGui.QMainWindow): def __init__(self, parent=None): super(Window, self).__init__(parent) self.treeArea = QtGui.QTreeWidget() self.textArea = QtGui.QTextEdit() self.viewArea = QtGui.QTabWidget() self.msgArea = QtGui.QTextBrowser() # Add tabs self.modelTab = ConeWindow(self) #self.modelTab = QtGui.QTextBrowser() self.reportTab = QtGui.QTextBrowser() self.viewArea.addTab(self.modelTab, "Model") self.viewArea.addTab(self.reportTab, "Report") # Window area splitters self.vSplitter = QtGui.QSplitter(QtCore.Qt.Vertical) self.vSplitter.addWidget(self.viewArea) self.vSplitter.addWidget(self.msgArea) self.hSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal) self.hSplitter.addWidget(self.treeArea) self.hSplitter.addWidget(self.textArea) self.hSplitter.addWidget(self.vSplitter) # Assign mainwindow self.setCentralWidget(self.hSplitter) class ConeWindow(QVTKRenderWindowInteractor): def __init__(self, parent=None): QVTKRenderWindowInteractor.__init__(self, parent) self._parent = parent self.vrenderer = vtk.vtkRenderer() self.renderWindow = self.GetRenderWindow() self.renderWindow.AddRenderer(self.vrenderer) self.iren = self.renderWindow.GetInteractor() # self.cone = vtk.vtkConeSource() self.cone.SetResolution(8) self.coneMapper = vtk.vtkPolyDataMapper() self.coneMapper.SetInput(self.cone.GetOutput()) self.coneActor = vtk.vtkActor() self.coneActor.SetMapper(self.coneMapper) self.vrenderer.AddActor(self.coneActor) self.iren.Initialize() if __name__ == '__main__': app = QtGui.QApplication(sys.argv) widge = Window() widge.show() sys.exit(app.exec_()) -- Kene :::::::::::::::::: KeMeniru at gmail.com From nikos.gr33k at gmail.com Thu Mar 28 10:19:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 07:19:47 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. Message-ID: Fianlly my cgi .py script doesnt produce any more errors, i think i ahve correct them but it present a blank screen http://superhost.gr Any idea why? What should i check? From miki.tebeka at gmail.com Thu Mar 28 10:42:59 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 28 Mar 2013 07:42:59 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: Message-ID: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> > Fianlly my cgi .py script doesnt produce any more errors, i think i ahve correct them but it present a blank screen > Any idea why? Please post the code to the script, otherwise we can't help you. From nikos.gr33k at gmail.com Thu Mar 28 10:46:15 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 07:46:15 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> Message-ID: <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> ?? ??????, 28 ??????? 2013 4:42:59 ?.?. UTC+2, ? ??????? Miki Tebeka ??????: > Please post the code to the script, otherwise we can't help you. I wanted to make my website running Python 3 which is more new and bette:) i treid to execute metrites.py via my jailed shell, please take a look if i'am not tiring you and maybe you can see if there is nothign wrong because i dont see nayhting. The gethostbyaddr at the end its because the script run in cmd instead of in a browser. Please help, its alkmost ready to run correctly! [code] nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py --> -->

    ??????? ?????????? %d
     
     
    KeyError
    Python 3.2.3: /usr/bin/python3
    Thu Mar 28 09:41:53 2013

    A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

     /home/nikos/public_html/cgi-bin/metrites.py in ()
         26 userform = form.getvalue('userform')
         27 
    =>   28 host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
         29 date = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d %H:%M:%S' )
         30 userinfo = os.environ['HTTP_USER_AGENT']
    host undefined, socket = <module 'socket' from '/opt/python3/lib/python3.2/socket.py'>, socket.gethostbyaddr = <built-in function gethostbyaddr>, os = <module 'os' from '/opt/python3/lib/python3.2/os.py'>, os.environ = environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'})
     /opt/python3/lib/python3.2/os.py in __getitem__(self=environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}), key='REMOTE_ADDR')
        448 
        449     def __getitem__(self, key):
    =>  450         value = self._data[self.encodekey(key)]
        451         return self.decodevalue(value)
        452 
    value undefined, self = environ({'PROMPT_COMMAND': 'history -a', 'PERL_M...xa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}), self._data = {b'CLASSPATH': b'.:/usr/local/jdk/lib/classes.zip', b'CVS_RSH': b'ssh', b'EDITOR': b'pico', b'GREP_COLOR': b'1;32', b'GREP_OPTIONS': b'--color', b'G_BROKEN_FILENAMES': b'1', b'HISTSIZE': b'5000', b'HOME': b'/home/nikos', b'HOSTNAME': b'menara.websitewelcome.com', b'INPUTRC': b'/etc/inputrc', ...}, self.encodekey = <function encode>, key = 'REMOTE_ADDR'

    KeyError: b'REMOTE_ADDR'
          args = (b'REMOTE_ADDR',)
          with_traceback = <built-in method with_traceback of KeyError object> [/code] From rosuav at gmail.com Thu Mar 28 10:58:15 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 01:58:15 +1100 Subject: No errors displayed but i blank scren nstead. In-Reply-To: <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 1:46 AM, ????? ???33? wrote: > Oh look, an exception traceback! In all this time of using Python, Nikos, have you learned how to read these? Very courteous of it to provide. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 11:04:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:04:00 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> Message-ID: this is correct when it runs from a browser thats not the issue here othwerise it would prodice an error. the question is why the blank screen... somehting with param style perhaps? From nikos.gr33k at gmail.com Thu Mar 28 11:04:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:04:00 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> Message-ID: this is correct when it runs from a browser thats not the issue here othwerise it would prodice an error. the question is why the blank screen... somehting with param style perhaps? From nikos.gr33k at gmail.com Thu Mar 28 11:20:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:20:47 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> Message-ID: <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py says its ok. From nikos.gr33k at gmail.com Thu Mar 28 11:20:47 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:20:47 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> Message-ID: <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. nikos at superhost.gr [~/www/cgi-bin]# /usr/bin/python3 metrites.py says its ok. From rosuav at gmail.com Thu Mar 28 11:25:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 02:25:26 +1100 Subject: No errors displayed but i blank scren nstead. In-Reply-To: <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. > > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. Quit shouting. You are asking for free help from volunteers. At the moment, you're asking for a killfiling. You have the traceback. Read it. Grok it. Solve it. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 11:51:43 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:51:43 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> Message-ID: <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> ?? ??????, 28 ??????? 2013 5:25:26 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: > > > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. > > > > > > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. > > > > Quit shouting. You are asking for free help from volunteers. > > > > At the moment, you're asking for a killfiling. > > > > You have the traceback. Read it. Grok it. Solve it. What traceback? It displayes no error at all not i cmd not in browser mode at http://superhost.gr i dont see what wrong with it. If you know what wrong with it why not just tell me? From nikos.gr33k at gmail.com Thu Mar 28 11:51:43 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:51:43 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> Message-ID: <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> ?? ??????, 28 ??????? 2013 5:25:26 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: > > > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. > > > > > > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. > > > > Quit shouting. You are asking for free help from volunteers. > > > > At the moment, you're asking for a killfiling. > > > > You have the traceback. Read it. Grok it. Solve it. What traceback? It displayes no error at all not i cmd not in browser mode at http://superhost.gr i dont see what wrong with it. If you know what wrong with it why not just tell me? From rosuav at gmail.com Thu Mar 28 11:59:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 02:59:55 +1100 Subject: No errors displayed but i blank scren nstead. In-Reply-To: <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 2:51 AM, ????? ???33? wrote: > ?? ??????, 28 ??????? 2013 5:25:26 ?.?. UTC+2, ? ??????? Chris Angelico ??????: >> On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: >> >> > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. >> >> > >> >> > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. >> >> >> >> Quit shouting. You are asking for free help from volunteers. >> >> >> >> At the moment, you're asking for a killfiling. >> >> >> >> You have the traceback. Read it. Grok it. Solve it. > > What traceback? It displayes no error at all not i cmd not in browser mode at http://superhost.gr > > i dont see what wrong with it. > > If you know what wrong with it why not just tell me? When you ran it from a shell, it showed you a traceback. Did you solve that issue? I am about done holding your hand like a little child. If you're not going to pay me a salary (with overtime rates, it's Good Friday over here now), you can solve your own problem... or at least demonstrate that you're trying things. So far, you're just making random changes that we can't see to code that we can't see, then expecting us to solve your problems. ChrisA From nikos.gr33k at gmail.com Thu Mar 28 12:10:07 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 09:10:07 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 5:59:55 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 29, 2013 at 2:51 AM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 5:25:26 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: > > >> > > >> > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. > > >> > > >> > > > >> > > >> > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. > > >> > > >> > > >> > > >> Quit shouting. You are asking for free help from volunteers. > > >> > > >> > > >> > > >> At the moment, you're asking for a killfiling. > > >> > > >> > > >> > > >> You have the traceback. Read it. Grok it. Solve it. > > > > > > What traceback? It displayes no error at all not i cmd not in browser mode at http://superhost.gr > > > > > > i dont see what wrong with it. > > > > > > If you know what wrong with it why not just tell me? > > > > When you ran it from a shell, it showed you a traceback. Did you solve > > that issue? > > > > I am about done holding your hand like a little child. If you're not > > going to pay me a salary (with overtime rates, it's Good Friday over > > here now), you can solve your own problem... or at least demonstrate > > that you're trying things. So far, you're just making random changes > > that we can't see to code that we can't see, then expecting us to > > solve your problems. > > > > ChrisA I am trying my best with the little knowledge i have and i expect no help from you. You are more inclinded to criticize that to actually help. And if i pay someone that certainly not gonna be you. And i told you about gethostbyaddr, tht its not an issue its because the script bein run form cmd that canot get hold of an address via browser tis ok. something else is wrong here and the page is displayed blank. From nikos.gr33k at gmail.com Thu Mar 28 12:10:07 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 09:10:07 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <0d4cf0ec-4240-49f3-9a26-1f5c97e8f7d2@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 5:59:55 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Fri, Mar 29, 2013 at 2:51 AM, ????? ???33? wrote: > > > ?? ??????, 28 ??????? 2013 5:25:26 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > > >> On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? wrote: > > >> > > >> > PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. > > >> > > >> > > > >> > > >> > EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE NOT EVEN AN INTERNAL SERVER ERROR. > > >> > > >> > > >> > > >> Quit shouting. You are asking for free help from volunteers. > > >> > > >> > > >> > > >> At the moment, you're asking for a killfiling. > > >> > > >> > > >> > > >> You have the traceback. Read it. Grok it. Solve it. > > > > > > What traceback? It displayes no error at all not i cmd not in browser mode at http://superhost.gr > > > > > > i dont see what wrong with it. > > > > > > If you know what wrong with it why not just tell me? > > > > When you ran it from a shell, it showed you a traceback. Did you solve > > that issue? > > > > I am about done holding your hand like a little child. If you're not > > going to pay me a salary (with overtime rates, it's Good Friday over > > here now), you can solve your own problem... or at least demonstrate > > that you're trying things. So far, you're just making random changes > > that we can't see to code that we can't see, then expecting us to > > solve your problems. > > > > ChrisA I am trying my best with the little knowledge i have and i expect no help from you. You are more inclinded to criticize that to actually help. And if i pay someone that certainly not gonna be you. And i told you about gethostbyaddr, tht its not an issue its because the script bein run form cmd that canot get hold of an address via browser tis ok. something else is wrong here and the page is displayed blank. From jeanmichel at sequans.com Thu Mar 28 12:31:58 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 28 Mar 2013 17:31:58 +0100 (CET) Subject: No errors displayed but i blank scren nstead. In-Reply-To: Message-ID: <1486863593.3067068.1364488318458.JavaMail.root@sequans.com> > I am trying my best with the little knowledge i have and i expect no > help from you. You are more inclinded to criticize that to actually > help. And if i pay someone that certainly not gonna be you. > > And i told you about gethostbyaddr, tht its not an issue its because > the script bein run form cmd that canot get hold of an address via > browser tis ok. > > something else is wrong here and the page is displayed blank. > -- > http://mail.python.org/mailman/listinfo/python-list > This is a traceback Traceback (most recent call last): File "metrites.py", line 28, in <module> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] File "/opt/python3/lib/python3.2/os.py", line 450, in __getitem__ value = self._data[self.encodekey(key)] KeyError: b'REMOTE_ADDR' It tells you that variable REMOTE_ADDR does not exist on your server environment. But Chris already told you that. 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 walterhurry at lavabit.com Thu Mar 28 13:24:28 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 28 Mar 2013 17:24:28 +0000 (UTC) Subject: No errors displayed but i blank scren nstead. References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> Message-ID: On Fri, 29 Mar 2013 02:25:26 +1100, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 2:20 AM, ????? ???33? > wrote: >> PLEASE GIVE ME A CLUE ABOUT THIS SITUATION. >> >> EVEN JAILED SHELL ACCESS SAYS ITS OKEY BUT I CNA ONLY SEE A BLANK PAGE >> NOT EVEN AN INTERNAL SERVER ERROR. > > Quit shouting. You are asking for free help from volunteers. > > At the moment, you're asking for a killfiling. He's got one. From nikos.gr33k at gmail.com Thu Mar 28 13:47:01 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 10:47:01 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> Message-ID: <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Like you werent of any help.... From nikos.gr33k at gmail.com Thu Mar 28 14:37:12 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 11:37:12 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Message-ID: Will someone help me out here please? From breamoreboy at yahoo.co.uk Thu Mar 28 15:02:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 28 Mar 2013 19:02:48 +0000 Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Message-ID: On 28/03/2013 18:37, ????? ???33? wrote: > Will someone help me out here please? > I suggest you take a course in diplomacy, but not one given by me :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From nikos.gr33k at gmail.com Thu Mar 28 15:05:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 12:05:54 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Message-ID: Well i dont like people taking to me this way espceially when iam tryign 2 days for something and thats changing from 2.6 => 3.2.3 I follow advice as long as i can understand whats being said to me. So if someone wants to help by asking me to try things please do. From nikos.gr33k at gmail.com Thu Mar 28 15:05:54 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 12:05:54 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Message-ID: Well i dont like people taking to me this way espceially when iam tryign 2 days for something and thats changing from 2.6 => 3.2.3 I follow advice as long as i can understand whats being said to me. So if someone wants to help by asking me to try things please do. From joel.goldstick at gmail.com Thu Mar 28 15:24:35 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 28 Mar 2013 15:24:35 -0400 Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> <1f7b3a17-8f90-48c8-889c-d60da47a2f47@googlegroups.com> <8dc29dce-d3e6-46f4-9614-942778236bb9@googlegroups.com> <688cf423-c0c3-4b4f-805f-ae10b1346101@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 3:05 PM, ????? ???33? wrote: > Well i dont like people taking to me this way espceially when iam tryign 2 > days for something and thats changing from 2.6 => 3.2.3 > > I follow advice as long as i can understand whats being said to me. > > So if someone wants to help by asking me to try things please do. > -- > http://mail.python.org/mailman/listinfo/python-list > I think you took an unwise approach to switch from 2.6 to 3.2.3 on a live server. I haven't tried 3.x yet, but I have seen lots of articles and videos about what is involved in moving that way. The unicode stuff seems to be a big change. Another issue is whether third party modules that work for 2.x are available for 3.x. Following along with your questions it appears you just changed interpreters and then watched things break. I suggest that you go back to study what is different about 3.x from 2.x. When you have a good understanding of that, go through your 2.x code and identify all of the areas that seem likely not to work. Then write some small test programs in 3.x to see if you can make the various functions work. You will learn a lot, and when you have problems you will be able to come back here and ask more informed questions, and likely will get more willing help. good luck -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.gr33k at gmail.com Thu Mar 28 10:54:58 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 07:54:58 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> Message-ID: ?? ??????, 28 ??????? 2013 4:42:59 ?.?. UTC+2, ? ??????? Miki Tebeka ??????: > > Fianlly my cgi .py script doesnt produce any more errors, i think i ahve correct them but it present a blank screen > > > Any idea why? > > Please post the code to the script, otherwise we can't help you. who ever dent me an email please sent agian or post here too he sai soemhtign about param style but accidently got deleted please send again or post here! Thank you and i apolgoze. From nikos.gr33k at gmail.com Thu Mar 28 11:56:00 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Thu, 28 Mar 2013 08:56:00 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> References: <96fcb30a-9857-4016-ae6e-7b07eab2d03a@googlegroups.com> Message-ID: <7d6f209f-bbcf-427f-a68e-ecc66d60f032@googlegroups.com> ?? ??????, 28 ??????? 2013 4:42:59 ?.?. UTC+2, ? ??????? Miki Tebeka ??????: > > Fianlly my cgi .py script doesnt produce any more errors, i think i ahve correct them but it present a blank screen > > > Any idea why? > > Please post the code to the script, otherwise we can't help you. Can you do me a big favour please? may i send you my code or perhaps jailed linux access so to understand whats wrong and altyhough i get no erros now i see a blank poage at http://superhost.gr Please man iam struggling 2 days to conever a 2,6 script to 3.2.3 please accept!!! From nagia.retsina at gmail.com Fri Mar 29 15:26:21 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 12:26:21 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: Message-ID: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> ?? ??????, 28 ??????? 2013 4:19:47 ?.?. UTC+2, ? ??????? ????? ???33? ??????: > Fianlly my cgi .py script doesnt produce any more errors, i think i ahve correct them but it present a blank screen > > > > http://superhost.gr > > > > Any idea why? > > What should i check? Thants not the issue, that message uses to be shown in comamnd line even woith python 2.6 somehting else is wrong here and it shwos blank pages. From nagia.retsina at gmail.com Fri Mar 29 15:27:12 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 12:27:12 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> Message-ID: <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> But now iam also receivein this error message as shown here when i switches to 'pymysql' From rosuav at gmail.com Fri Mar 29 15:34:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 06:34:07 +1100 Subject: No errors displayed but i blank scren nstead. In-Reply-To: <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> Message-ID: On Sat, Mar 30, 2013 at 6:27 AM, wrote: > But now iam also receivein this error message as shown here when i switches to 'pymysql' Why the change of email address? Are you trying to dodge killfiles? ChrisA From neilc at norwich.edu Fri Mar 29 16:14:16 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Mar 2013 20:14:16 GMT Subject: No errors displayed but i blank scren nstead. References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> Message-ID: On 2013-03-29, Chris Angelico wrote: > On Sat, Mar 30, 2013 at 6:27 AM, wrote: >> But now iam also receivein this error message as shown here when i switches to 'pymysql' > > Why the change of email address? Are you trying to dodge killfiles? I had that one killfiled already. Must be he/she/it is posting from a different sock puppet. -- Neil Cerutti From walterhurry at lavabit.com Fri Mar 29 17:14:42 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Fri, 29 Mar 2013 21:14:42 +0000 (UTC) Subject: No errors displayed but i blank scren nstead. References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> Message-ID: On Fri, 29 Mar 2013 20:14:16 +0000, Neil Cerutti wrote: > On 2013-03-29, Chris Angelico wrote: >> On Sat, Mar 30, 2013 at 6:27 AM, wrote: >>> But now iam also receivein this error message as shown here when i >>> switches to 'pymysql' >> >> Why the change of email address? Are you trying to dodge killfiles? > > I had that one killfiled already. Must be he/she/it is posting from a > different sock puppet. Ditto. Just another entry for the bozo bin. From nagia.retsina at gmail.com Fri Mar 29 16:34:19 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 13:34:19 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> Message-ID: <23cbfefd-6404-46f9-9aae-e29ac1902e1b@googlegroups.com> ?? ?????????, 29 ??????? 2013 9:34:07 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Mar 30, 2013 at 6:27 AM, wrote: > > > But now iam also receivein this error message as shown here when i switches to 'pymysql' > > > > Why the change of email address? Are you trying to dodge killfiles? > > > > ChrisA No, someone else is using this computer too along with Chrome and Chrome associates his mail address with all google services and i was under the impression i was sposting from my gmail group account. Sorry for that. it happened many tiems alrready as i noticed days ago too. From nagia.retsina at gmail.com Fri Mar 29 16:34:19 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 13:34:19 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: <6c1ce34b-11ba-4457-9caf-a11d1978fad0@googlegroups.com> <26e23d4a-155b-4f19-9d51-ad06c2b2a0e1@googlegroups.com> Message-ID: <23cbfefd-6404-46f9-9aae-e29ac1902e1b@googlegroups.com> ?? ?????????, 29 ??????? 2013 9:34:07 ?.?. UTC+2, ? ??????? Chris Angelico ??????: > On Sat, Mar 30, 2013 at 6:27 AM, wrote: > > > But now iam also receivein this error message as shown here when i switches to 'pymysql' > > > > Why the change of email address? Are you trying to dodge killfiles? > > > > ChrisA No, someone else is using this computer too along with Chrome and Chrome associates his mail address with all google services and i was under the impression i was sposting from my gmail group account. Sorry for that. it happened many tiems alrready as i noticed days ago too. From nagia.retsina at gmail.com Fri Mar 29 15:27:36 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 29 Mar 2013 12:27:36 -0700 (PDT) Subject: No errors displayed but i blank scren nstead. In-Reply-To: References: Message-ID: <03d7a463-c70b-42e7-a86b-7cead5c10fcf@googlegroups.com> But now iam also receiving this error message as shown here when i switches to 'pymysql' From khaosyt at gmail.com Thu Mar 28 10:39:59 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Thu, 28 Mar 2013 07:39:59 -0700 (PDT) Subject: Help printing the integers of a longer number Message-ID: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> I want to print the individual numbers of a large number using division and modulus division. For example: Enter a positive integer: 54321 5 4 3 2 1 From rosuav at gmail.com Thu Mar 28 10:48:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 01:48:25 +1100 Subject: Help printing the integers of a longer number In-Reply-To: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 1:39 AM, wrote: > I want to print the individual numbers of a large number using division and modulus division. > > For example: > > Enter a positive integer: 54321 > 5 > 4 > 3 > 2 > 1 Python has two operators that can help here: // for integer division - returns the quotient without the remainder % for modulus - returns the remainder You'll also want to use a while loop to continue gathering digits so long as there's something left in the number. And if you want the digits to come out in that order, you're probably going to want to gather them into a list and then output them in reverse. But start by ignoring that part and producing something that, for the input 54321, produces 1, 2, 3, 4, and then 5. Finally, when you're asking about homework, please be honest about it. We can tell, you're not putting one over us :) Better still, post your non-working code and explain where you're having trouble; we'll be happy to help you learn, but we won't simply give you the answer. ChrisA From joel.goldstick at gmail.com Thu Mar 28 10:48:16 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 28 Mar 2013 10:48:16 -0400 Subject: Help printing the integers of a longer number In-Reply-To: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: On Thu, Mar 28, 2013 at 10:39 AM, wrote: > I want to print the individual numbers of a large number using division > and modulus division. > > For example: > > Enter a positive integer: 54321 > 5 > 4 > 3 > 2 > 1 > > This looks familiar. Make the integer a string and use a for loop to iterate over each item > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Thu Mar 28 13:03:49 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Mar 2013 19:03:49 +0200 Subject: Help printing the integers of a longer number References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: khaosyt at gmail.com writes: > I want to print the individual numbers of a large number using > division and modulus division. > > For example: > > Enter a positive integer: 54321 > 5 > 4 > 3 > 2 > 1 Those numbers are called the digits of the large number. With divmod(54321, 10) you get both the number that is "left" after removing the last digit, and the last digit: >>> left, last = divmod(54321, 10) >>> left 5432 >>> last 1 Define a function, print_digits(num), that prints the digits of the non-negative integer num. Zero turns out fine so let's allow zero: def print_digits(num): left, last = divmod(num, 10) if left < 0: print the digits of left print(last) How do you print the digits of left? With print_digits. Why does it work? Because you only call print_digits again when left is closer to zero than num. It's called recursion. From jpiitula at ling.helsinki.fi Thu Mar 28 13:11:03 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Mar 2013 19:11:03 +0200 Subject: Help printing the integers of a longer number References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: Jussi Piitulainen writes: > khaosyt at gmail.com writes: > > > I want to print the individual numbers of a large number using > > division and modulus division. > > > > For example: > > > > Enter a positive integer: 54321 > > 5 > > 4 > > 3 > > 2 > > 1 > > Those numbers are called the digits of the large number. > > With divmod(54321, 10) you get both the number that is "left" after > removing the last digit, and the last digit: > > >>> left, last = divmod(54321, 10) > >>> left > 5432 > >>> last > 1 > > Define a function, print_digits(num), that prints the digits of the > non-negative integer num. Zero turns out fine so let's allow zero: > > def print_digits(num): > left, last = divmod(num, 10) > if left < 0: print the digits of left > print(last) Blush. That should be: ... if left > 0: ... ... (Or just "if left" because left will eventually be 0, positive numbers are true values, and 0 is a false value.) Sorry about that. > How do you print the digits of left? With print_digits. Why does it > work? Because you only call print_digits again when left is closer to > zero than num. > > It's called recursion. From rosuav at gmail.com Thu Mar 28 13:19:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 04:19:39 +1100 Subject: Help printing the integers of a longer number In-Reply-To: References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 4:11 AM, Jussi Piitulainen wrote: > Jussi Piitulainen writes: > >> khaosyt at gmail.com writes: >> >> > I want to print the individual numbers of a large number using >> > division and modulus division. >> > >> > For example: >> > >> > Enter a positive integer: 54321 >> > 5 >> > 4 >> > 3 >> > 2 >> > 1 >> >> Those numbers are called the digits of the large number. >> >> With divmod(54321, 10) you get both the number that is "left" after >> removing the last digit, and the last digit: >> >> >>> left, last = divmod(54321, 10) >> >>> left >> 5432 >> >>> last >> 1 >> >> Define a function, print_digits(num), that prints the digits of the >> non-negative integer num. Zero turns out fine so let's allow zero: >> >> def print_digits(num): >> left, last = divmod(num, 10) >> if left < 0: print the digits of left >> print(last) > > Blush. That should be: > > ... > if left > 0: ... > ... > > (Or just "if left" because left will eventually be 0, positive numbers > are true values, and 0 is a false value.) > > Sorry about that. Sorry, I just nitpicked that very thing, hehe :) Note that this doesn't work with negative numbers; it'll infinitely recurse, due to divmod's behaviour. You'd need a special trap in there to handle that: if num<0: print("-") num=-num # and continue. ChrisA From rosuav at gmail.com Thu Mar 28 13:17:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 04:17:19 +1100 Subject: Help printing the integers of a longer number In-Reply-To: References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 4:03 AM, Jussi Piitulainen wrote: > def print_digits(num): > left, last = divmod(num, 10) > if left < 0: print the digits of left > print(last) > > How do you print the digits of left? With print_digits. Why does it > work? Because you only call print_digits again when left is closer to > zero than num. > > It's called recursion. An elegant solution, but buggy, I'm afraid... fortunately it's a trivial problem. The comparison should be left>0. :) ChrisA From inkprs at gmail.com Thu Mar 28 11:23:43 2013 From: inkprs at gmail.com (inkprs at gmail.com) Date: Thu, 28 Mar 2013 08:23:43 -0700 (PDT) Subject: Replacing old data with new data using python Message-ID: <73c4a128-1783-4501-ab4b-c2c5c9017e3e@googlegroups.com> I have 2 tables TBL1 and TBL2. TBL1 has 2 columns id, nSql. TBL2 has 3 columns date, custId, userId. I have 17 rows in TBL1 with id 1 to 17. Each nSql has a SQL query in it. For example nSql for id == 1 is: "select date, pId as custId, tId as userId from TBL3" id == 2 is: "select date, qId as custId, rId as userId from TBL4" ... nSql result is always same 3 columns. Below query runs and puts data into the table TBL2. If there is already data in TBL2 for that day, I want the query to replace the data with new data. If there is not data in TBL2, I want to put data in normal way. Any time I run the query, it will push the data for yesterday into TBL2. For example, if I run the query in the morning and if I want to run it again in evening, I want new data to replace old data for yesterday, since data will be inserted into TBL2 everyday. It is also precaution that if the data already exists (if run by coworker), I do not want duplicate data for that day. I think we can use it in 'if else' statement. something pseudocode like: if there is data in TBL2 for date_sub(curdate(), interval 1 day), remove the database data and insert new data. else insert new data into database. How can I do it? Thank you. (I am new to python, I would appreciate if someone could explain in steps and show in the code) import MySQLdb # Open connection con = MySQLdb.Connection(host="localhost", user="root", passwd="root", db="test") # create a cursor object cur = con.cursor() selectStatement = ("select nSql from TBL1") cur.execute(selectStatement) res = cur.fetchall() for outerrow in res: nSql = outerrow[0] cur.execute(nSql) reslt = cur.fetchall() for row in reslt: date = row[0] custId = row[1] userId = row[2] insertStatement = ("insert into TBL2( date, custId, userId) values ('%s', %d, %d)" % (date, custId, userId)) cur.execute(insertStatement) con.commit() From rosuav at gmail.com Thu Mar 28 12:15:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2013 03:15:04 +1100 Subject: Replacing old data with new data using python In-Reply-To: <73c4a128-1783-4501-ab4b-c2c5c9017e3e@googlegroups.com> References: <73c4a128-1783-4501-ab4b-c2c5c9017e3e@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 2:23 AM, wrote: > I think we can use it in 'if else' statement. something pseudocode like: if there is data in TBL2 for date_sub(curdate(), interval 1 day), remove the database data and insert new data. else insert new data into database. > > How can I do it? Can you simply do a searched DELETE? DELETE from TBL2 WHERE date>date_sub(curdate(), interval 1 day) That will happily do nothing if there are no such records. Be careful of what it'll do, of course. Make sure you won't accidentally delete too much! (BTW, isn't "date" a reserved word? Maybe it isn't in MySQL.) > insertStatement = ("insert into TBL2( date, custId, userId) values ('%s', %d, %d)" % (date, custId, userId)) > cur.execute(insertStatement) > con.commit() I recommend you get used to parameterized queries. Assuming your date field, coming from the other table, is clean, this will be safe; but if there's any chance that date might have an apostrophe in it, this code is very dangerous. But there's a really neat trick you can do. If you have a guarantee that all the SQL statements follow the structure you've given, just prepend a simple string to them, thus: "select date, pId as custId, tId as userId from TBL3" --> "insert into TBL2 (date, custId, userId) select date, pId as custId, tId as userId from TBL3" That'll do the whole transfer in a single statement! Something like this: cur.execute("select nSql from TBL1") for outerrow in cur.fetchall(): cur.execute("insert into TBL2 (date, custId, userId) "+outerrow[0]) con.commit() Note: I've backtabbed the commit() call so that the whole job happens in a single transaction. You may wish to reindent it, to preserve the semantics of your previous version; but I recommend doing the whole job as one transaction, rather than committing each row separately. If this job is interrupted, you'll have to start over anyway, so you may as well have the database be clean. ChrisA From wolfgang.maier at biologie.uni-freiburg.de Thu Mar 28 11:25:14 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 28 Mar 2013 15:25:14 +0000 (UTC) Subject: list comprehension misbehaving Message-ID: Dear all, with a=list(range(1,11)) why (in Python 2.7 and 3.3) is this explicit for loop working: for i in a[:-1]: a.pop() and a giving: [1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5] [1, 2, 3, 4] [1, 2, 3] [1, 2] [1] but the equivalent comprehension failing: [a.pop() and a for i in a[:-1]] giving: [[1], [1], [1], [1], [1], [1], [1], [1], [1]] ??? Especially, since these two things *do* work as expected: [a.pop() and a[:] for i in a[:-1]] [a.pop() and print(a) for i in a[:-1]] # Python 3 only Thanks for your help, Wolfgang From python.list at tim.thechases.com Thu Mar 28 11:44:51 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 28 Mar 2013 10:44:51 -0500 Subject: list comprehension misbehaving In-Reply-To: References: Message-ID: <20130328104451.22bad9af@bigbox.christie.dr> On 2013-03-28 15:25, Wolfgang Maier wrote: > Dear all, with > a=list(range(1,11)) > > why (in Python 2.7 and 3.3) is this explicit for loop working: > for i in a[:-1]: > a.pop() and a As you discover: > Especially, since these two things *do* work as expected: > [a.pop() and a[:] for i in a[:-1]] it's because you're taking a snapshot copy of "a" in the middle of the loop. In your first example, if you change it to results = [] for i in a[:-1]: results.append(a.pop() and a) print results you get the same thing as your list comprehension because each item in "results" refers to the now-(mostly)empty "a". -tkc From wolfgang.maier at biologie.uni-freiburg.de Thu Mar 28 11:52:29 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 28 Mar 2013 15:52:29 +0000 (UTC) Subject: list comprehension misbehaving References: <20130328104451.22bad9af@bigbox.christie.dr> Message-ID: Tim Chase tim.thechases.com> writes: > it's because you're taking a snapshot copy of "a" in the middle of > the loop. In your first example, if you change it to > > results = [] > for i in a[:-1]: > results.append(a.pop() and a) > print results > > you get the same thing as your list comprehension because each item > in "results" refers to the now-(mostly)empty "a". > > -tkc > > Hi Tim, and thanks a lot for helping! I got it: in the comprehension case I'm only getting my results at the end, when my list has been emptied! Thanks, I got stuck with this, but now it's obvious. Best, Wolfgang From __peter__ at web.de Thu Mar 28 11:48:03 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Mar 2013 16:48:03 +0100 Subject: list comprehension misbehaving References: Message-ID: Wolfgang Maier wrote: > Dear all, with > a=list(range(1,11)) > > why (in Python 2.7 and 3.3) is this explicit for loop working: > for i in a[:-1]: > a.pop() and a > > giving: > [1, 2, 3, 4, 5, 6, 7, 8, 9] > [1, 2, 3, 4, 5, 6, 7, 8] > [1, 2, 3, 4, 5, 6, 7] > [1, 2, 3, 4, 5, 6] > [1, 2, 3, 4, 5] > [1, 2, 3, 4] > [1, 2, 3] > [1, 2] > [1] No. Introduce a result list, and you'll see that you append the *same* list to the result nine times: >>> a = range(1, 11) >>> result = [] >>> for i in a[:-1]: ... result.append(a.pop() and a) ... >>> result [[1], [1], [1], [1], [1], [1], [1], [1], [1]] > but the equivalent comprehension failing: > [a.pop() and a for i in a[:-1]] > > giving: > [[1], [1], [1], [1], [1], [1], [1], [1], [1]] > > ??? > Especially, since these two things *do* work as expected: > [a.pop() and a[:] for i in a[:-1]] > [a.pop() and print(a) for i in a[:-1]] # Python 3 only So you already know the solution to your problem... From buzzard at invalid.invalid Thu Mar 28 11:54:23 2013 From: buzzard at invalid.invalid (duncan smith) Date: Thu, 28 Mar 2013 15:54:23 +0000 Subject: list comprehension misbehaving In-Reply-To: References: Message-ID: <515467b1$0$65353$862e30e2@ngroups.net> On 28/03/13 15:25, Wolfgang Maier wrote: > Dear all, with > a=list(range(1,11)) > > why (in Python 2.7 and 3.3) is this explicit for loop working: > for i in a[:-1]: > a.pop() and a > > giving: > [1, 2, 3, 4, 5, 6, 7, 8, 9] > [1, 2, 3, 4, 5, 6, 7, 8] > [1, 2, 3, 4, 5, 6, 7] > [1, 2, 3, 4, 5, 6] > [1, 2, 3, 4, 5] > [1, 2, 3, 4] > [1, 2, 3] > [1, 2] > [1] > > but the equivalent comprehension failing: > [a.pop() and a for i in a[:-1]] > > giving: > [[1], [1], [1], [1], [1], [1], [1], [1], [1]] > > ??? > Especially, since these two things *do* work as expected: > [a.pop() and a[:] for i in a[:-1]] > [a.pop() and print(a) for i in a[:-1]] # Python 3 only > > Thanks for your help, > Wolfgang > With the for loop the list is printed each time you pop an element. With the list comprehension all but one of the elements are popped before the string representation of the resulting list (containing several references to a) is printed. The two list comprehensions that you say "work" behave differently because the first contains copies of a (which are unaffected by subsequent pops), and the second because (I imagine) it does something similar to, [a.pop() and repr(a) for i in a[:-1]] on 2.7 (I haven't migrated to 3 yet). i.e. The list contains a representation of a after each element is popped. Duncan From tavares at fe.up.pt Thu Mar 28 12:00:39 2013 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Thu, 28 Mar 2013 09:00:39 -0700 (PDT) Subject: IV ECCOMAS Thematic Conference VipIMAGE 2013: SUBMISSION REMINDER Message-ID: <9da2b882-4b08-4537-b5a8-f6efa23984f8@googlegroups.com> Dear Colleague, We would like to call your attention that the deadline for abstracts submission for the International Conference VipIMAGE 2013 - IV ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING (www.fe.up.pt/~vipimage) to be held October 14-16, 2013, in Melia Madeira Mare Hotel, Madeira Island, Funchal, Portugal, is approaching (April 15). Once again, we would like to invite you to participate and share your expertise in VipIMAGE 2013. Possible Topics (not limited to) ? Signal and Image Processing ? Computational Vision ? Medical Imaging ? Physics of Medical Imaging ? Tracking and Analysis of Movement ? Simulation and Modeling ? Image Acquisition ? Industrial Applications ? Shape Reconstruction ? Objects Segmentation, Matching, Simulation ? Data Interpolation, Registration, Acquisition and Compression ? 3D Vision ? Virtual Reality ? Visual Inspection ? Software Development for Image Processing and Analysis ? Computer Aided Diagnosis, Surgery, Therapy, and Treatment ? Computational Bioimaging and Visualization ? Telemedicine Systems and their Applications Invited Lecturers ? Daniel Rueckert - Imperial College London, UK ? Dimitris N. Metaxas - Rutgers University, USA ? Durval C. Costa - Champalimaud Foundation, Portugal ? James S Duncan - Yale School of Medicine, USA ? Milan Sonka - The University of Iowa, USA ? Richard Bowden - University of Surrey, UK Thematic Sessions Proposals to organize Thematic Session under the auspicious of VipIMAGE 2013 are welcome. Proposals for Thematic Sessions should be submitted by email to the conference co-chairs (tavares at fe.up.pt, rnatal at fe.up.pt). Confirmed Thematic Sessions ? Imaging of Biological Flows: trends and challenges ? Trabecular Bone Characterization: New trends and challenges ? Computational Vision and Image Processing applied to Dental Medicine Publications ? Proceedings: The proceedings book will be published by the Taylor & Francis Group (www.balkema.nl/instructions.asp) and indexed by Thomson Reuters Conference Proceedings Citation Index, IET Inspect and Elsevier Scopus. ? Springer Book: A book with 20 invited works from the ones presented in the conference will be published by Springer under the book series ?Lecture Notes in Computational Vision and Biomechanics? (www.springer.com/series/8910). ? Journal Publication: A dedicated special issue of the Taylor & Francis International Journal ?Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization? (www.tandfonline.com/tciv) will be published with extended versions of the best works presented in the conference. Important dates ? Deadline for Abstracts: April 15, 2013 ? Authors Notification: May 1, 2013 ? Deadline for Lectures and Papers: July 1, 2013 We are looking forward to see you in Funchal next October. Kind regards, Jo?o Manuel R. S. Tavares Renato Natal Jorge (conference co-chairs) PS. For further details, please, have a look in the conference website at: www.fe.up.pt/~vipimage, or in the conference Facebook page at: www.facebook.com/pages/Vipimage/237980719665456, or join the LinkedIn conference group at: http://www.linkedin.com/groups?gid=4752820&trk=hb_side_g From habibutsu at gmail.com Thu Mar 28 15:37:47 2013 From: habibutsu at gmail.com (Habibutsu) Date: Thu, 28 Mar 2013 22:37:47 +0300 Subject: Lazy evaluated Message-ID: <51549C0B.5020604@gmail.com> For example, we have following code: 01| def foo(): 02| return 1 03| 04| value = foo() 05| 06| if value == 1: 07| print value,"- equal 1" 08| 09| if isinstance(value, int): 10| print value,"- is int" 11| else: 12| print value,"- is not int" Task is to create lazy evaluation for function 'foo'. For decision this task we create special function 'lazy' which turn original function into a lazy evaluated function by means of creating proxy object that evaluated value if needed. We add following code: 01| def lazy(func): 02| 03| class ProxyLazy(object): 04| _result_value = None 05| 06| @property 07| def result_value(self): 08| if self._result_value is not None: 09| return self._result_value 10| self._result_value = self.func(*self.args, **self.kw) 11| return self._result_value 12| 13| def __str__(self): 14| return str(self.result_value) 15| 16| def __cmp__(self, other): 17| return cmp(self.result_value, other) 18| 19| # and other __unicode__, __eq__, __ne__ and so on 20| 21| def wrapper(*args, **kw): 22| proxy = ProxyLazy() 23| proxy.func = func 24| proxy.args = args 25| proxy.kw = kw 26| return proxy 27| 28| return wrapper 29| 30| lazy_foo = lazy(foo) 31| value = lazy_foo() Unfortunately, this method not allow to use 'isinstance' for check type. We can create other variant of function 'lazy' is 'lazy_promise' in which additional parameter will be passed with type of result value. After we can create 'LazyMetaClass' with helping of which will be created 'ProxyLazy' 01| def lazy_promise(func, resultclass): 02| 03| class LazyMetaClass(type): 04| def __new__(cls, name, bases, attrs): 05| return super(LazyMetaClass, cls).__new__(cls, name, (resultclass,), attrs) 06| 07| class ProxyLazy(object): 08| __metaclass__ = LazyMetaClass ... 35| lazy_foo = lazy_promise(foo, int) 36| value = lazy_foo() And everything seems to work, but appear other questions. If original function return different types - what to do in this case? Where i am wrong? What other way to do that. Was no idea to create keyword 'lazy' in Python? Thanks From steve+comp.lang.python at pearwood.info Thu Mar 28 22:40:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 02:40:51 GMT Subject: Lazy evaluated References: Message-ID: <5154ff33$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 22:37:47 +0300, Habibutsu wrote: > For example, we have following code: > > 01| def foo(): > 02| return 1 > 03| > 04| value = foo() > 05| > 06| if value == 1: > 07| print value,"- equal 1" > 08| > 09| if isinstance(value, int): > 10| print value,"- is int" > 11| else: > 12| print value,"- is not int" > > Task is to create lazy evaluation for function 'foo'. For decision this > task we create special function 'lazy' which turn original function into > a lazy evaluated function by means of creating proxy object that > evaluated value if needed. We add following code: > > > 01| def lazy(func): > 02| > 03| class ProxyLazy(object): > 04| _result_value = None > 05| > 06| @property > 07| def result_value(self): [...] It is often useful for the reader to copy and paste code blocks like this into the interactive interpreter. It is more friendly and useful if you paste it in a format that makes that easy (no prompts, no line numbers, no blank lines inside classes or functions). Otherwise the reader has to copy your code, paste it into an editor, strip out the line numbers and blank lines, copy and paste it into the interpreter, and THEN they can finally test your code and see what it does. > 30| lazy_foo = lazy(foo) > 31| value = lazy_foo() > > Unfortunately, this method not allow to use 'isinstance' for check type. Correct. And so it should not, because it value is not an int, it is a ProxyLazy object. You cannot use a ProxyLazy object where an int is expected: py> value + 1 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'ProxyLazy' and 'int' so it is inappropriate to claim that value is an int. I must admit, I don't understand the value of this "lazy proxy" type you have created. You get a proxy like this: value = lazy(foo)() # get a lazy proxy # much later value = value.func() # now safe to use as an int print(value + 1) What benefit does the lazy proxy give? Why not just do this? value = foo() # functions are already a lazy proxy # much later value = value() # now safe to use as an int print(value + 1) [...] > And everything seems to work, but appear other questions. If original > function return different types - what to do in this case? Where i am > wrong? What other way to do that. Was no idea to create keyword 'lazy' > in Python? Why should it be a keyword? Python has very few keywords, and most of them are for programming flow control, like "if", "else", "for", "while", "pass", etc. -- Steven From habibutsu at gmail.com Fri Mar 29 06:37:53 2013 From: habibutsu at gmail.com (Habibutsu) Date: Fri, 29 Mar 2013 13:37:53 +0300 Subject: Lazy evaluated In-Reply-To: <5154ff33$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <5154ff33$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51556F01.1070004@gmail.com> On 03/29/2013 05:40 AM, Steven D'Aprano wrote: > On Thu, 28 Mar 2013 22:37:47 +0300, Habibutsu wrote: > >> For example, we have following code: >> >> 01| def foo(): >> 02| return 1 >> 03| >> 04| value = foo() >> 05| >> 06| if value == 1: >> 07| print value,"- equal 1" >> 08| >> 09| if isinstance(value, int): >> 10| print value,"- is int" >> 11| else: >> 12| print value,"- is not int" >> >> Task is to create lazy evaluation for function 'foo'. For decision this >> task we create special function 'lazy' which turn original function into >> a lazy evaluated function by means of creating proxy object that >> evaluated value if needed. We add following code: >> >> >> 01| def lazy(func): >> 02| >> 03| class ProxyLazy(object): >> 04| _result_value = None >> 05| >> 06| @property >> 07| def result_value(self): > [...] > > > It is often useful for the reader to copy and paste code blocks like this > into the interactive interpreter. It is more friendly and useful if you > paste it in a format that makes that easy (no prompts, no line numbers, > no blank lines inside classes or functions). Otherwise the reader has to > copy your code, paste it into an editor, strip out the line numbers and > blank lines, copy and paste it into the interpreter, and THEN they can > finally test your code and see what it does. > Previously I not to do it, yesterday decide to experiment. It seemed to me more readable if to see in the email-clent. Sorry, I will keep in mind in the future. >> 30| lazy_foo = lazy(foo) >> 31| value = lazy_foo() >> >> Unfortunately, this method not allow to use 'isinstance' for check type. > Correct. And so it should not, because it value is not an int, it is a > ProxyLazy object. You cannot use a ProxyLazy object where an int is > expected: > > py> value + 1 > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'ProxyLazy' and 'int' > Why not? def __add__(self, other): return self._result_value + other and then >>> print value + 1 2 > so it is inappropriate to claim that value is an int. I can overload all arithmetic operators and get almost really int value, but I don't like to write many trivial code. > I must admit, I don't understand the value of this "lazy proxy" type you > have created. You get a proxy like this: > > value = lazy(foo)() # get a lazy proxy > # much later > value = value.func() # now safe to use as an int > print(value + 1) > > What benefit does the lazy proxy give? Why not just do this? Because some people like to use "list comprehensions" and other not, some people like labmda and other not. Advantage is that I can write more expressive code and use different strategies for different cases. "value = value.func()" is looks sad while I just need the value. > > value = foo() # functions are already a lazy proxy > # much later > value = value() # now safe to use as an int > print(value + 1) > > > [...] >> And everything seems to work, but appear other questions. If original >> function return different types - what to do in this case? Where i am >> wrong? What other way to do that. Was no idea to create keyword 'lazy' >> in Python? > Why should it be a keyword? Python has very few keywords, and most of > them are for programming flow control, like "if", "else", "for", "while", > "pass", etc. > Question not in why I can't use exist tools - I can. If i can write code without classes that it does not mean that classes need to delete from language. Question why in language not present this ability? Thanks From victorhooi at gmail.com Fri Mar 29 00:00:44 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Thu, 28 Mar 2013 21:00:44 -0700 (PDT) Subject: Doing both regex match and assignment within a If loop? Message-ID: Hi, I have logline that I need to test against multiple regexes. E.g.: import re expression1 = re.compile(r'....') expression2 = re.compile(r'....') with open('log.txt') as f: for line in f: if expression1.match(line): # Do something - extract fields from line. elif expression2.match(line): # Do something else - extract fields from line. else: # Oh noes! Raise exception. However, in the "Do something" section - I need access to the match object itself, so that I can strip out certain fields from the line. Is it possible to somehow test for a match, as well as do assignment of the re match object to a variable? if expression1.match(line) = results: results.groupsdict()... Obviously the above won't work - however, is there a Pythonic way to tackle this? What I'm trying to avoid is this: if expression1.match(line): results = expression1.match(line) which I assume would call the regex match against the line twice - and when I'm dealing with a huge amount of log lines, slow things down. Cheers, Victor From clp2 at rebertia.com Fri Mar 29 00:29:17 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 28 Mar 2013 21:29:17 -0700 Subject: Doing both regex match and assignment within a If loop? In-Reply-To: References: Message-ID: On Thu, Mar 28, 2013 at 9:00 PM, Victor Hooi wrote: > Hi, > > I have logline that I need to test against multiple regexes. E.g.: > > import re > > expression1 = re.compile(r'....') > expression2 = re.compile(r'....') > > with open('log.txt') as f: > for line in f: > if expression1.match(line): > # Do something - extract fields from line. > elif expression2.match(line): > # Do something else - extract fields from line. > else: > # Oh noes! Raise exception. > > However, in the "Do something" section - I need access to the match object itself, so that I can strip out certain fields from the line. > > Is it possible to somehow test for a match, as well as do assignment of the re match object to a variable? > > if expression1.match(line) = results: > results.groupsdict()... AFAIK, not without hacks and/or being unidiomatic. > Obviously the above won't work - however, is there a Pythonic way to tackle this? > > What I'm trying to avoid is this: > > if expression1.match(line): > results = expression1.match(line) > > which I assume would call the regex match against the line twice - and when I'm dealing with a huge amount of log lines, slow things down. def process(line): match = expr1.match(line) if match: # ...extract fields? return something match = expr2.match(line) if match: # ...extract fields? return something # etc? raise SomeError() # Oh noes! with open('log.txt') as f: for line in f: results = process(line) If you choose to further move the extractor snippets into their own functions, then you can do: # these could be lambdas if they're simple enough def case1(match): # ... def case2(match): # ? # etc... REGEX_EXTRACTOR_PAIRS = [ (re.compile(r'....'), case1), (re.compile(r'....'), case2), # etc... ] def process(line): for regex, extractor in REGEX_EXTRACTOR_PAIRS: match = regex.match(line) if match: return extractor(match) raise SomeError() Although this second option is likely somewhat less performant, but it definitely saves on repetition. Cheers, Chris From steve+comp.lang.python at pearwood.info Fri Mar 29 02:45:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 06:45:37 GMT Subject: Doing both regex match and assignment within a If loop? References: Message-ID: <51553891$0$29974$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Mar 2013 21:00:44 -0700, Victor Hooi wrote: > Is it possible to somehow test for a match, as well as do assignment of > the re match object to a variable? mo = expression.match(line) if mo: ... Many problems become trivial when we stop trying to fit everything into a single line :-) > if expression1.match(line) = results: > results.groupsdict()... > > Obviously the above won't work - however, is there a Pythonic way to > tackle this? Yes. Stop trying to fit everything into a single line :-) I would approach the problem like this: LOOKUP_TABLE = {expression1: do_something, expression2: do_something_else, expression3: function3, expression4: function4, # etc. } with open('log.txt') as f: for line in f: for expr, func in LOOKUP_TABLE.items(): mo = expr.match(line) if mo: func(line, mo) break else: # If we get here, we never reached the break. raise SomeException If you don't like having that many top level functions, you could make them methods of a class. If you only have two or three expressions to test, and the body of each if clause is small, it's probably too much effort to write functions for each one. In that case, I'd stick to the slightly more verbose form: with open('log.txt') as f: for line in f: mo = expression1.match(line) if mo: do_this() do_that() mo = expression2.match(line) if mo: do_something_else() mo = expression3.match(line) if mo: fe() fi() fo() fum() else: raise SomeException > What I'm trying to avoid is this: > > if expression1.match(line): > results = expression1.match(line) > > which I assume would call the regex match against the line twice Correct. -- Steven From __peter__ at web.de Fri Mar 29 04:27:46 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Mar 2013 09:27:46 +0100 Subject: Doing both regex match and assignment within a If loop? References: Message-ID: Victor Hooi wrote: > Hi, > > I have logline that I need to test against multiple regexes. E.g.: > > import re > > expression1 = re.compile(r'....') > expression2 = re.compile(r'....') > > with open('log.txt') as f: > for line in f: > if expression1.match(line): > # Do something - extract fields from line. > elif expression2.match(line): > # Do something else - extract fields from line. > else: > # Oh noes! Raise exception. > > However, in the "Do something" section - I need access to the match object > itself, so that I can strip out certain fields from the line. > > Is it possible to somehow test for a match, as well as do assignment of > the re match object to a variable? > > if expression1.match(line) = results: > results.groupsdict()... > > Obviously the above won't work - however, is there a Pythonic way to > tackle this? > > What I'm trying to avoid is this: > > if expression1.match(line): > results = expression1.match(line) > > which I assume would call the regex match against the line twice - and > when I'm dealing with a huge amount of log lines, slow things down. (1) for line in f: match = expression1.match(line) if match: # ... continue match = expression2.match(line) if match: # ... continue raise NothingMatches (2) import re class Matcher: def __call__(self, expr, line): result = self.match = expr.match(line) return result def __getattr__(self, name): return getattr(self.match, name) match = Matcher() for line in f: if match(expression1, line): print(match.groupdict()) elif match(expression2, line): print(match.group(1)) else: raise NothingMatches From msirenef at lightbird.net Fri Mar 29 09:49:34 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Fri, 29 Mar 2013 09:49:34 -0400 Subject: Doing both regex match and assignment within a If loop? In-Reply-To: References: Message-ID: <51559BEE.6040500@lightbird.net> On 03/29/2013 04:27 AM, Peter Otten wrote: > (2) > import re > > class Matcher: > def __call__(self, expr, line): > result = self.match = expr.match(line) > return result > def __getattr__(self, name): > return getattr(self.match, name) Perhaps it's a little simpler to do this? > self.match = expr.match(line) > return self.match -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Frisbeetarianism is the belief that when you die, your soul goes up on the roof and gets stuck. George Carlin From alain at dpt-info.u-strasbg.fr Fri Mar 29 06:06:30 2013 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 29 Mar 2013 11:06:30 +0100 Subject: Doing both regex match and assignment within a If loop? References: Message-ID: <87txnuv7tl.fsf@dpt-info.u-strasbg.fr> Victor Hooi writes: > expression1 = re.compile(r'....') > expression2 = re.compile(r'....') [...] Just a quick remark: regular expressions are pretty powerful at representing alternatives. You could just stick everything inside a single re, as in '...|...' Then use the returned match to check which alternative was recognized (make sure you have at least one group in each alternative). > Is it possible to somehow test for a match, as well as do assignment > of the re match object to a variable? Yes, use '...(...)...' and MatchObject.group(). See the other messages. -- Alain. From arnodel at gmail.com Fri Mar 29 06:41:26 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 29 Mar 2013 10:41:26 +0000 Subject: Doing both regex match and assignment within a If loop? In-Reply-To: <87txnuv7tl.fsf@dpt-info.u-strasbg.fr> References: <87txnuv7tl.fsf@dpt-info.u-strasbg.fr> Message-ID: On Friday, 29 March 2013, Alain Ketterlin wrote: > Victor Hooi > writes: > > > expression1 = re.compile(r'....') > > expression2 = re.compile(r'....') > [...] > > Just a quick remark: regular expressions are pretty powerful at > representing alternatives. You could just stick everything inside a > single re, as in '...|...' > > Then use the returned match to check which alternative was recognized > (make sure you have at least one group in each alternative). > > Yes, and for extra ease/clarity you can name these alternatives ( '(?Ppattern)'). Then you can do if m.group('case1'): ... elif m.group('case2'): ... -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Fri Mar 29 08:51:17 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Mar 2013 12:51:17 GMT Subject: Doing both regex match and assignment within a If loop? References: <87txnuv7tl.fsf@dpt-info.u-strasbg.fr> Message-ID: On 2013-03-29, Alain Ketterlin wrote: > Victor Hooi writes: > >> expression1 = re.compile(r'....') >> expression2 = re.compile(r'....') > [...] > > Just a quick remark: regular expressions are pretty powerful at > representing alternatives. You could just stick everything > inside a single re, as in '...|...' > > Then use the returned match to check which alternative was > recognized (make sure you have at least one group in each > alternative). Yes, but in a Python program it's more straightforward to program in Python. ;) But this is from a grade A regex avoider, so take it with a small chunk of sodium. >> Is it possible to somehow test for a match, as well as do assignment >> of the re match object to a variable? One way to attack this problem that's not yet been explicitly mentioned is to match using a generator function: def match_each(s, re_seq): for r in re_seq: yield r.match(s) And later something like: for match in match_each(s, (expression1, expression2, expression3)): if match: print(match.groups()) # etc... -- Neil Cerutti From avnesh.nitk at gmail.com Fri Mar 29 08:04:54 2013 From: avnesh.nitk at gmail.com (Avnesh Shakya) Date: Fri, 29 Mar 2013 05:04:54 -0700 (PDT) Subject: trying to open index.py using Indico software...... Message-ID: hi, please help me... I have installed indico software and apache2,when i try to run it using http://indico/index.py,then it's downloading index.py, when i put http://indico, then it's showing all thing properly,but it's not showing index.py but downloading it.... it's not showing any error, even i have tried error.log.. Please help me, I m unable to get this thing.... Thanks From dspublic at freemail.hu Fri Mar 29 08:27:01 2013 From: dspublic at freemail.hu (dspublic at freemail.hu) Date: Fri, 29 Mar 2013 05:27:01 -0700 (PDT) Subject: HTTPConnection.send Message-ID: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> Hi! I have a problem with HTTPConnection object send() method (pyver3.3.1). I want to send data from file-like object with HTTPConnection.send( f ), and I get a "data should be a bytes-like object or an iterable, ..." exception. I have investigated a send method, and discovered a problem: if data has a read attribute, send it , and try send it again with self.sock.sendall(data). My opinion is need an "else" after the "if hasattr(data, "read")" Please, somebody help me. Does it a real BUG or my mistake? http.client.py > if hasattr(data, "read") : if self.debuglevel > 0: print("sendIng a read()able") encode = False try: mode = data.mode except AttributeError: # io.BytesIO and other file-like objects don't have a `mode` # attribute. pass else: if "b" not in mode: encode = True if self.debuglevel > 0: print("encoding file using iso-8859-1") while 1: datablock = data.read(blocksize) if not datablock: break if encode: datablock = datablock.encode("iso-8859-1") self.sock.sendall(datablock) ELSE: #!!!! i guess missing !!!! try: self.sock.sendall(data) except TypeError: if isinstance(data, collections.Iterable): for d in data: self.sock.sendall(d) else: raise TypeError("data should be a bytes-like object " "or an iterable, got %r" % type(data)) From dspublic at freemail.hu Fri Mar 29 09:40:29 2013 From: dspublic at freemail.hu (dspublic at freemail.hu) Date: Fri, 29 Mar 2013 06:40:29 -0700 (PDT) Subject: HTTPConnection.send In-Reply-To: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> References: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> Message-ID: <64ec269f-be78-45bb-a916-bbbbbfcac289@googlegroups.com> Problematical python versions: 3.2+ (2.x, 3.0, 3.1 ok) From __peter__ at web.de Fri Mar 29 10:49:05 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Mar 2013 15:49:05 +0100 Subject: HTTPConnection.send References: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> Message-ID: dspublic at freemail.hu wrote: > I have a problem with HTTPConnection object send() method (pyver3.3.1). I > want to send data from file-like object with HTTPConnection.send( f ), and > I get a "data should be a bytes-like object or an iterable, ..." > exception. I have investigated a send method, and discovered a problem: if > data has a read attribute, send it , and try send it again with > self.sock.sendall(data). My opinion is need an "else" after the "if > hasattr(data, "read")" > > Please, somebody help me. Does it a real BUG or my mistake? I think your analysis is correct. Please file a bug report on . > http.client.py > > > if hasattr(data, "read") : > if self.debuglevel > 0: > print("sendIng a read()able") > encode = False > try: > mode = data.mode > except AttributeError: > # io.BytesIO and other file-like objects don't have a > # `mode` attribute. > pass > else: > if "b" not in mode: > encode = True > if self.debuglevel > 0: > print("encoding file using iso-8859-1") > while 1: > datablock = data.read(blocksize) > if not datablock: > break > if encode: > datablock = datablock.encode("iso-8859-1") > self.sock.sendall(datablock) > ELSE: #!!!! i guess missing !!!! > try: > self.sock.sendall(data) > except TypeError: > if isinstance(data, collections.Iterable): > for d in data: > self.sock.sendall(d) > else: > raise TypeError("data should be a bytes-like object " > "or an iterable, got %r" % type(data)) From rosuav at gmail.com Fri Mar 29 10:58:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 01:58:28 +1100 Subject: HTTPConnection.send In-Reply-To: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> References: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 11:27 PM, wrote: > I have a problem with HTTPConnection object send() method (pyver3.3.1). I want to send data from file-like object with HTTPConnection.send( f ), and I get a "data should be a bytes-like object or an iterable, ..." exception. I have investigated a send method, and discovered a problem: if data has a read attribute, send it , and try send it again with self.sock.sendall(data). My opinion is need an "else" after the "if hasattr(data, "read")" > > Please, somebody help me. Does it a real BUG or my mistake? Yeah, I think you may be right on that. Changeset 67046 added the try block, and removed the else. I'd raise this on the tracker; I'd say the removal of else was purely accidental. ChrisA From dspublic at freemail.hu Fri Mar 29 12:32:48 2013 From: dspublic at freemail.hu (dspublic at freemail.hu) Date: Fri, 29 Mar 2013 09:32:48 -0700 (PDT) Subject: HTTPConnection.send In-Reply-To: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> References: <64ae9389-ef1b-4852-94a9-7cc5c228238c@googlegroups.com> Message-ID: <856134d5-1808-4e94-bcd4-592b6acc09af@googlegroups.com> Thanx for confirmations... I have reported http://bugs.python.org/issue17575 From roy at panix.com Fri Mar 29 10:48:28 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 10:48:28 -0400 Subject: How to find bad row with db api executemany()? Message-ID: I'm inserting a gazillion rows into a MySQL database using MySQLdb and cursor.executemany() for efficiency. Every once in a while, I get a row which violates some kind of database constraint and raises Error. I can catch the exception, but don't see any way to tell which row caused the problem. Is this information obtainable, short of retrying each row one by one? --- Roy Smith roy at panix.com From davea at davea.name Fri Mar 29 14:53:30 2013 From: davea at davea.name (Dave Angel) Date: Fri, 29 Mar 2013 14:53:30 -0400 Subject: How to find bad row with db api executemany()? In-Reply-To: References: Message-ID: <5155E32A.1000403@davea.name> On 03/29/2013 10:48 AM, Roy Smith wrote: > I'm inserting a gazillion rows into a MySQL database using MySQLdb and cursor.executemany() for efficiency. Every once in a while, I get a row which violates some kind of database constraint and raises Error. > > I can catch the exception, but don't see any way to tell which row caused the problem. Is this information obtainable, short of retrying each row one by one? > I don't know the direct answer, or even if there is one (way to get MySQL to tell you which one failed), but ... Assuming that executeMany is much cheaper than a million calls to executeOne (or whatever). -- single bad rows -- If you have a million items, and you know exactly one is different, you can narrow it down more quickly than just sequencing through them. You can do half of them at a time, carefully choosing which subset of the total you use each time. After 20 such calls, you can then calculate exactly which one is different. Standard CS algorithm. -- sparse set of rows -- If you know that it's at least one, but still less than a dozen or so, it's a little trickier, but you should still converge on a final list pretty quickly. Each time you do half, you also do the complementary half. If either of them has no 'differences" you can then eliminate half the cases. If you don't get a specific answer where MySQL can tell you the bad row, and if you don't know what I'm talking about, ask and I'll try to elaborate on one of the two above cases. -- DaveA From roy at panix.com Fri Mar 29 20:41:03 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 20:41:03 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Dennis Lee Bieber wrote: > If using MySQLdb, there isn't all that much difference... MySQLdb is > still compatible with MySQL v4 (and maybe even v3), and since those > versions don't have "prepared statements", .executemany() essentially > turns into something that creates a newline delimited "list" of > "identical" (but for argument substitution) statements and submits that > to MySQL. Shockingly, that does appear to be the case. I had thought during my initial testing that I was seeing far greater throughput, but as I got more into the project and started doing some side-by-side comparisons, it the differences went away. We're sucking in a pretty huge amount of data. The source document is a 7 GB gzipped XML file. I'm not sure how big it is uncompressed (we use gzip.GzipFile to uncompress on the fly) but I'm guessing something like a 30x compression ratio so 200 GB? The last time we imported the whole set, it ran for 21 days! It turns out, the problems we were seeing were all inserts into a new table we added. Apparently, the default charset is latin-1 and we didn't notice that when we altered the schema! Once I noticed that all the other tables were utf-8 and changed this one to be that, the problems went away. Sadly, I ended up resorting to a truly ugly hack to diagnose the problem. I catch the exception and parse the text message. Yuck. try: self.executemany(self.sql_statement, self.sql_params) except MySQLdb.Error as ex: code, message = ex.args m = re.search(r".* at row (\d+)$", message) if m: i = int(m.group(1)) - 1 # Python is 0-index, SQL, 1-index The other truly horrible part of the project was when I decided it was bad for my import script to have too much schema knowledge hard-wired in. So, I decided to use SQLAlchemy to introspect the database and discover the column names, types, and defaults. It turns out, if an integer column has a default (say, 0), the introspected data comes back with the default as the string, '0'. WTF??? Does Postgress's Python adapter handle executemany() in a sane way? We're not wedded to MySQL in any way. We use it for exactly this one process. We get these XML dumps from a supplier's SQL-Server database. We stage the data in MySQL, then export what we need into MongoDB. We could easily swap out the MySQL staging for Postgress if that worked better. Hmmm, we do take advantage of REPLACE INTO, which I think is a non-standard MySQL addition. Not sure if Postgress supports that. From rosuav at gmail.com Fri Mar 29 20:57:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 11:57:03 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 11:41 AM, Roy Smith wrote: > In article , > Dennis Lee Bieber wrote: > >> If using MySQLdb, there isn't all that much difference... MySQLdb is >> still compatible with MySQL v4 (and maybe even v3), and since those >> versions don't have "prepared statements", .executemany() essentially >> turns into something that creates a newline delimited "list" of >> "identical" (but for argument substitution) statements and submits that >> to MySQL. > > Shockingly, that does appear to be the case. I had thought during my > initial testing that I was seeing far greater throughput, but as I got > more into the project and started doing some side-by-side comparisons, > it the differences went away. How much are you doing per transaction? The two extremes (everything in one transaction, or each line in its own transaction) are probably the worst for performance. See what happens if you pepper the code with 'begin' and 'commit' statements (maybe every thousand or ten thousand rows) to see if performance improves. ChrisA From roy at panix.com Fri Mar 29 21:19:22 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 21:19:22 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Chris Angelico wrote: > On Sat, Mar 30, 2013 at 11:41 AM, Roy Smith wrote: > > In article , > > Dennis Lee Bieber wrote: > > > >> If using MySQLdb, there isn't all that much difference... MySQLdb is > >> still compatible with MySQL v4 (and maybe even v3), and since those > >> versions don't have "prepared statements", .executemany() essentially > >> turns into something that creates a newline delimited "list" of > >> "identical" (but for argument substitution) statements and submits that > >> to MySQL. > > > > Shockingly, that does appear to be the case. I had thought during my > > initial testing that I was seeing far greater throughput, but as I got > > more into the project and started doing some side-by-side comparisons, > > it the differences went away. > > How much are you doing per transaction? The two extremes (everything > in one transaction, or each line in its own transaction) are probably > the worst for performance. See what happens if you pepper the code > with 'begin' and 'commit' statements (maybe every thousand or ten > thousand rows) to see if performance improves. > > ChrisA We're doing it all in one transaction, on purpose. We start with an initial dump, then get updates about once a day. We want to make sure that the updates either complete without errors, or back out cleanly. If we ever had a partial daily update, the result would be a mess. Hmmm, on the other hand, I could probably try doing the initial dump the way you describe. If it fails, we can just delete the whole thing and start again. From rosuav at gmail.com Fri Mar 29 22:05:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 13:05:08 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 12:19 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sat, Mar 30, 2013 at 11:41 AM, Roy Smith wrote: >> > In article , >> > Dennis Lee Bieber wrote: >> > >> >> If using MySQLdb, there isn't all that much difference... MySQLdb is >> >> still compatible with MySQL v4 (and maybe even v3), and since those >> >> versions don't have "prepared statements", .executemany() essentially >> >> turns into something that creates a newline delimited "list" of >> >> "identical" (but for argument substitution) statements and submits that >> >> to MySQL. >> > >> > Shockingly, that does appear to be the case. I had thought during my >> > initial testing that I was seeing far greater throughput, but as I got >> > more into the project and started doing some side-by-side comparisons, >> > it the differences went away. >> >> How much are you doing per transaction? The two extremes (everything >> in one transaction, or each line in its own transaction) are probably >> the worst for performance. See what happens if you pepper the code >> with 'begin' and 'commit' statements (maybe every thousand or ten >> thousand rows) to see if performance improves. >> >> ChrisA > > We're doing it all in one transaction, on purpose. We start with an > initial dump, then get updates about once a day. We want to make sure > that the updates either complete without errors, or back out cleanly. > If we ever had a partial daily update, the result would be a mess. > > Hmmm, on the other hand, I could probably try doing the initial dump the > way you describe. If it fails, we can just delete the whole thing and > start again. One transaction for the lot isn't nearly as bad as one transaction per row, but it can consume a lot of memory on the server - or at least, that's what I found last time I worked with MySQL. (PostgreSQL works completely differently, and I'd strongly recommend doing it all as one transaction if you switch.) It's not guaranteed to help, but if it won't hurt to try, there's a chance you'll gain some performance. ChrisA From python.list at tim.thechases.com Fri Mar 29 23:17:50 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 29 Mar 2013 22:17:50 -0500 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: <20130329221750.4b00728d@bigbox.christie.dr> On 2013-03-29 21:19, Roy Smith wrote: > We're doing it all in one transaction, on purpose. We start with > an initial dump, then get updates about once a day. We want to > make sure that the updates either complete without errors, or back > out cleanly. If we ever had a partial daily update, the result > would be a mess. Having had to do some similarly-sized bulk data loads (in my case, MSSqlServer at $JOB) couple other ideas occur to me: 1) I believe MySQL has a side-loading function (I'd have to go digging for it; a quick google suggests a "LOAD DATA INFILE" statement[1]) that allows you to load data from an external file such as an XML or CSV file 2) Load into a temp table in testable batches, then do some sort of batch insert into your main table. Again, a quick google suggest the "INSERT ... SELECT" syntax[2] -tkc [1] http://dev.mysql.com/doc/refman/5.1/en/load-data.html [2] http://dev.mysql.com/doc/refman/5.0/en/insert-select.html From python.list at tim.thechases.com Fri Mar 29 23:38:08 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 29 Mar 2013 22:38:08 -0500 Subject: How to find bad row with db api executemany()? (PS) In-Reply-To: <20130329221750.4b00728d@bigbox.christie.dr> References: <5155E32A.1000403@davea.name> <20130329221750.4b00728d@bigbox.christie.dr> Message-ID: <20130329223808.2728d349@bigbox.christie.dr> On 2013-03-29 22:17, Tim Chase wrote: > 2) Load into a temp table in testable batches, then do some sort of > batch insert into your main table. Again, a quick google suggest > the "INSERT ... SELECT" syntax[2] It looks like there's a corresponding "REPLACE INTO ... SELECT" syntax[1], as you mention doing a REPLACE INTO rather than a straight INSERT -tkc [1] http://dev.mysql.com/doc/refman/5.0/en/replace.html From roy at panix.com Fri Mar 29 22:44:53 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 22:44:53 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Roy Smith wrote: > In article , > Dennis Lee Bieber wrote: > > > If using MySQLdb, there isn't all that much difference... MySQLdb is > > still compatible with MySQL v4 (and maybe even v3), and since those > > versions don't have "prepared statements", .executemany() essentially > > turns into something that creates a newline delimited "list" of > > "identical" (but for argument substitution) statements and submits that > > to MySQL. > > Shockingly, that does appear to be the case. I had thought during my > initial testing that I was seeing far greater throughput, but as I got > more into the project and started doing some side-by-side comparisons, > it the differences went away. OMG, this is amazing. http://stackoverflow.com/questions/3945642/ It turns out, the MySQLdb executemany() runs a regex over your SQL and picks one of two algorithms depending on whether it matches or not. restr = (r"\svalues\s*" r"(\(((? References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 1:44 PM, Roy Smith wrote: > The slow way (i.e. "VALUES"), I'm inserting 1000 rows about every 2.4 > seconds. When I switch to "values", I'm getting more like 1000 rows in > 100 ms! > > A truly breathtaking bug. *facepalm* Doubly facepalm because a regex could easily have tested for mixed case. Especially facepalm because there's some way to do this that's faster than straight INSERT statements, and it's not clearly documented as "hey, guys, if you want to dump loads of data in, use COPY instead" (it might be that, I don't know, but usually COPY isn't directly transliterable with INSERT). I agree. Breathtaking. ChrisA From rosuav at gmail.com Sat Mar 30 00:24:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 15:24:52 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: <2mocl85ru7r58tluf05e47qicjecpht68c@invalid.netcom.com> References: <5155E32A.1000403@davea.name> <2mocl85ru7r58tluf05e47qicjecpht68c@invalid.netcom.com> Message-ID: On Sat, Mar 30, 2013 at 3:19 PM, Dennis Lee Bieber wrote: > I think MySQL is the only common DBMS with an extension on INSERT of > allowing multiple records (I've not checked my Access 2010 docs, and my > MSDE/SQL-Server books are in storage -- but SQLite3, Firebird, and > PostgreSQL all seem to be "one INSERT = one record"). I don't know about performance, but syntactically at least, an INSERT is certainly allowed to do multiple records. I do this all the time for database dump/recreation, something like: INSERT INTO table (field,field,field) VALUES (value,value,value),(value,value,value); I've done this in PostgreSQL, and I'm pretty sure also in MySQL. That might be identical in performance to two separate statements, but at least it's clearer. ChrisA From python.list at tim.thechases.com Sat Mar 30 07:38:58 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 30 Mar 2013 06:38:58 -0500 Subject: How to find bad row with db api executemany()? In-Reply-To: <2mocl85ru7r58tluf05e47qicjecpht68c@invalid.netcom.com> References: <5155E32A.1000403@davea.name> <2mocl85ru7r58tluf05e47qicjecpht68c@invalid.netcom.com> Message-ID: <20130330063858.62d42655@bigbox.christie.dr> On 2013-03-30 00:19, Dennis Lee Bieber wrote: > I think MySQL is the only common DBMS with an extension on > INSERT of allowing multiple records (I've not checked my Access > 2010 docs, and my MSDE/SQL-Server books are in storage -- but > SQLite3, Firebird, and PostgreSQL all seem to be "one INSERT = one > record"). MS SQL Server supports the "INSERT INTO ... SELECT" syntax as well. Strangely, it *also* supports "SELECT ... INTO tblNew" but that creates the tblNew, rather than inserting into an existing one. I've seen Chris's suggestion about "INSERT INTO (f1,f2,f3) VALUES (v1,v2,v3),(v4,v5,v6);" syntax, but that hasn't worked cross-RDBMS for me, so I always have to resurrect the syntax. -tkc From roy at panix.com Fri Mar 29 23:09:37 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 23:09:37 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Chris Angelico wrote: > Especially facepalm because there's some way to do this that's faster > than straight INSERT statements, and it's not clearly documented as > "hey, guys, if you want to dump loads of data in, use COPY instead" > (it might be that, I don't know, but usually COPY isn't directly > transliterable with INSERT). We're actually using REPLACE INTO. For the initial data load, we could just as well do INSERT, but we need the REPLACE functionality as we roll in the daily incremental updates. This also explains why, even after provisioning our RDS instance for 2000 IOPS (that's AWS-speak for "we paid extra to get more disk bandwidth"), we didn't see any performance improvement! From rosuav at gmail.com Fri Mar 29 23:14:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 14:14:38 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 2:09 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Especially facepalm because there's some way to do this that's faster >> than straight INSERT statements, and it's not clearly documented as >> "hey, guys, if you want to dump loads of data in, use COPY instead" >> (it might be that, I don't know, but usually COPY isn't directly >> transliterable with INSERT). > > We're actually using REPLACE INTO. For the initial data load, we could > just as well do INSERT, but we need the REPLACE functionality as we roll > in the daily incremental updates. > > This also explains why, even after provisioning our RDS instance for > 2000 IOPS (that's AWS-speak for "we paid extra to get more disk > bandwidth"), we didn't see any performance improvement! Hmm. I heard around the forums that Amazon weren't that great at disk bandwidth anyway, and that provisioning IO was often a waste of money. But we never did all that much much research on Amazon I/O performance; shortly after doing some basic benchmarking, we decided that the cloud was a poor fit for our system model, and went looking at dedicated servers with their own RAID storage right there on the bus. ChrisA From roy at panix.com Fri Mar 29 23:36:54 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 23:36:54 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Chris Angelico wrote: > Hmm. I heard around the forums that Amazon weren't that great at disk > bandwidth anyway, and that provisioning IO was often a waste of money. Au, contraire. I guess it all depends on what you're doing. If you're CPU bound, increasing your I/O bandwidth won't help. But, at least on our database (MongoDB) servers, we saw a huge performance boost when we started going for provisioned IO. > But we never did all that much much research on Amazon I/O > performance; shortly after doing some basic benchmarking, we decided > that the cloud was a poor fit for our system model, and went looking > at dedicated servers with their own RAID storage right there on the > bus. As far as I can tell, from a raw price/performance basis, they're pretty expensive. But, from a convenience standpoint, it's hard to beat. Case in point: We've been thinking about SSD as our next performance step-up. One day, we just spun up some big honking machine, configured it with 2 TB of SSD, and played around for a while. Wicked fast. Then we shut it down. That experiment probably cost us $10 or so, and we were able to run it on the spur of the moment. Another example was last summer when we had a huge traffic spike because of a new product release. Caught us by surprise how much new traffic it would generate. Our site was in total meltdown. We were able to spin up 10 new servers in an afternoon. If we had to go out and buy hardware, have it shipped to us, figure out where we had rack space, power, network capacity, cooling, etc, we'd have been out of business before we got back on the air. Yet another example. We just (as in, while I've been typing this) had one of our servers go down. Looks like the underlying hardware the VM was running on croaked, because when the instance came back up, it had a new IP address. The whole event was over in a couple of minutes, with only minor disruption to the service. And, presumably, there's some piece of hardware somewhere in Virginia that needs repairing, but that's not our problem. The really big boys (Google, Facebook) run their own data centers. But, some surprisingly large operations run out of AWS. Netflix, for example. The convenience and flexibility is worth a lot. From rosuav at gmail.com Fri Mar 29 23:57:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 14:57:56 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 2:36 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Hmm. I heard around the forums that Amazon weren't that great at disk >> bandwidth anyway, and that provisioning IO was often a waste of money. > > Au, contraire. I guess it all depends on what you're doing. If you're > CPU bound, increasing your I/O bandwidth won't help. But, at least on > our database (MongoDB) servers, we saw a huge performance boost when we > started going for provisioned IO. > > As far as I can tell, from a raw price/performance basis, they're pretty > expensive. But, from a convenience standpoint, it's hard to beat. Yeah, I'm not saying you won't see performance go up - just that it's going to be expensive compared to what you could do with a dedicated server. The flexibility costs. > Case in point: We've been thinking about SSD as our next performance > step-up. One day, we just spun up some big honking machine, configured > it with 2 TB of SSD, and played around for a while. Wicked fast. Then > we shut it down. That experiment probably cost us $10 or so, and we > were able to run it on the spur of the moment. That is one thing the cloud is *awesome* for. "Hmm, I wonder......" *half an hour later* "Now I know." *bill comes in* "That was cheap." > Another example was last summer when we had a huge traffic spike because > of a new product release. Caught us by surprise how much new traffic it > would generate. Our site was in total meltdown. We were able to spin > up 10 new servers in an afternoon. If we had to go out and buy > hardware, have it shipped to us, figure out where we had rack space, > power, network capacity, cooling, etc, we'd have been out of business > before we got back on the air. Yep. We're looking rather at server rental, from big honking data centers (by the way, I never managed to figure this out - at what size do things begin to honk? Larger than a bread box?), where hopefully they would be able to deploy us more servers within a matter of hours. Not as good as cloud (where you can have more servers in minutes), but you described "in an afternoon" as your success story, so I'm guessing most of the delay was an administrative one - the decision to actually go ahead and spin those servers up. Unless you're automating the whole thing (which is possible with the Amazon cloud, but not every client will do it), that's always going to cost you. > Yet another example. We just (as in, while I've been typing this) had > one of our servers go down. Looks like the underlying hardware the VM > was running on croaked, because when the instance came back up, it had a > new IP address. The whole event was over in a couple of minutes, with > only minor disruption to the service. And, presumably, there's some > piece of hardware somewhere in Virginia that needs repairing, but that's > not our problem. Yeah, that's also a concern. And that works beautifully as long as you're okay with that. It'll also happen more often with AWS than with dedicated hardware, because there are more components to fail. That's part of what wouldn't have fitted our server layout; we have a layer on top of all that to manage monitoring (and, incidentally, we set up a dozen home-grade laptops as a "server cluster" to test all those systems, and knew within minutes of one of the laptops deciding that it had crunched its last bits), and we really want stable IP addresses for DNS and such. Cloud isn't bad, it was just a bad fit for us. Side point: You mentioned SSDs. Are you aware of the fundamental risks associated with them? Only a handful of SSD models are actually trustworthy for databasing. Sure, they're fast, but can you afford data corruption in the event of a power outage? Most SSDs will cheerfully lie about fsync() and thus violate transactional integrity (ACID compliance etc). ChrisA From roy at panix.com Sat Mar 30 00:10:09 2013 From: roy at panix.com (Roy Smith) Date: Sat, 30 Mar 2013 00:10:09 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Chris Angelico wrote: > Side point: You mentioned SSDs. Are you aware of the fundamental risks > associated with them? Only a handful of SSD models are actually > trustworthy for databasing. We haven't decided if we're going that route yet, but if we do, we will probably use do RAID SSD for added reliability. We also have all our database servers in failover clusters, so we get added reliability that way too. But, we have some runway left with more conventional technologies, so we don't need to decide for a while. Ultimately, however, as reliability goes up and cost comes down, it's hard to imagine the SSD isn't going to be a big part of our lives at some point. From rosuav at gmail.com Sat Mar 30 00:21:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 15:21:31 +1100 Subject: How to find bad row with db api executemany()? In-Reply-To: References: <5155E32A.1000403@davea.name> Message-ID: On Sat, Mar 30, 2013 at 3:10 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Side point: You mentioned SSDs. Are you aware of the fundamental risks >> associated with them? Only a handful of SSD models are actually >> trustworthy for databasing. > > We haven't decided if we're going that route yet, but if we do, we will > probably use do RAID SSD for added reliability. We also have all our > database servers in failover clusters, so we get added reliability that > way too. But will you know if you have corruption? Normally, transactional integrity means: 1) If a transaction, from begin to commit, is not completely applied, then it is completely not-applied; and 2) If a transaction that was affected by this one has been applied, then so has this one. SSDs that lie about fsync (and some hard disks lie too, as do some operating systems and some file system drivers, but - under Linux at least - it's possible to guarantee the OS and FS parts) can violate both halves. Anything might have been written, anything might have been missed. I did some tests with PostgreSQL on an SSD, and the results were seriously scary. > But, we have some runway left with more conventional technologies, so we > don't need to decide for a while. Ultimately, however, as reliability > goes up and cost comes down, it's hard to imagine the SSD isn't going to > be a big part of our lives at some point. Yes. I hope that by then, the manufacturers will realize that TPS isn't the only thing that matters. I'm sure SSDs will mature to the point where we can trust all brands equally (or at least, most brands - maybe it'll be like "server SSDs" and "desktop SSDs"?), but until then, there aren't many options. ChrisA From roy at panix.com Sat Mar 30 10:19:24 2013 From: roy at panix.com (Roy Smith) Date: Sat, 30 Mar 2013 10:19:24 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , Chris Angelico wrote: > SSDs that lie about fsync (and some hard disks lie too, as do some > operating systems and some file system drivers, but - under Linux at > least - it's possible to guarantee the OS and FS parts) can violate > both halves. Anything might have been written, anything might have > been missed. I did some tests with PostgreSQL on an SSD, and the > results were seriously scary. What you say is true, but then again, it's true of other things too. We're running in a completely virtual environment. Our "real" disk storage is EBS. Somewhere out on the network there's something which pretends to be a disk. Does "written" really mean "the bits have been committed to a piece of physical spinning iron oxide"? I have no clue. But, this conversation is getting very far away from Python. From rustompmody at gmail.com Fri Mar 29 23:13:48 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 20:13:48 -0700 (PDT) Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: On Mar 30, 7:49?am, Chris Angelico wrote: > On Sat, Mar 30, 2013 at 1:44 PM, Roy Smith wrote: > > The slow way (i.e. "VALUES"), I'm inserting 1000 rows about every 2.4 > > seconds. ?When I switch to "values", I'm getting more like 1000 rows in > > 100 ms! > > > A truly breathtaking bug. > > *facepalm* > > Doubly facepalm because a regex could easily have tested for mixed case. > > Especially facepalm because there's some way to do this that's faster > than straight INSERT statements, and it's not clearly documented as > "hey, guys, if you want to dump loads of data in, use COPY instead" > (it might be that, I don't know, but usually COPY isn't directly > transliterable with INSERT). > > I agree. Breathtaking. > > ChrisA I recently heard this: A phone company needed to send out bulk-smses to its customers. It was of the order of millions. A (noob?) python programmer was assigned the task and used django with whatever is the django orm. It took of the order of weeks to send out the smses. A python expert was called in. He threw out the python and redid it in SQL. It was done in minutes. From rustompmody at gmail.com Fri Mar 29 23:15:44 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 20:15:44 -0700 (PDT) Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: <1568eb91-0f1f-44f8-b3ea-17747026694a@u5g2000pbs.googlegroups.com> On Mar 30, 8:13?am, rusi wrote: > It took of the order of weeks to send out the smses. 'Week' I think is more accurate. From roy at panix.com Fri Mar 29 23:40:36 2013 From: roy at panix.com (Roy Smith) Date: Fri, 29 Mar 2013 23:40:36 -0400 Subject: How to find bad row with db api executemany()? References: <5155E32A.1000403@davea.name> Message-ID: In article , rusi wrote: > I recently heard this: > A phone company needed to send out bulk-smses to its customers. It was > of the order of millions. > A (noob?) python programmer was assigned the task and used django with > whatever is the django orm. > It took of the order of weeks to send out the smses. > A python expert was called in. He threw out the python and redid it > in SQL. > It was done in minutes. I'm not surprised. It almost certainly wasn't the python that was the problem. More than likely, he was doing some horribly inefficient database operations. Certainly, in our case, performance is all about the database. We mostly can't even measure the time we spend running Python code. From miki.tebeka at gmail.com Sat Mar 30 12:24:31 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 30 Mar 2013 09:24:31 -0700 (PDT) Subject: How to find bad row with db api executemany()? In-Reply-To: References: Message-ID: <6b085f98-0d19-4572-be92-4fb1764a221b@googlegroups.com> > I can catch the exception, but don't see any way to tell which row caused the problem. Is this information obtainable, short of retrying each row one by one? One way to debug this is to wrap the iterable passed to executemany with one that remembers the last line. Something like: class LastIterator(object): def __init__(self, coll): self.it = iter(coll) self.last = None def __iter__(self): return self def next(self): self.last = next(self.it) return self.last ... li = ListIterator(items) try: cursor.executemany(sql, li) except SQLError, e: print('Error: {}, row was {}'.format(e, li.last)) From roy at panix.com Sat Mar 30 12:44:55 2013 From: roy at panix.com (Roy Smith) Date: Sat, 30 Mar 2013 12:44:55 -0400 Subject: How to find bad row with db api executemany()? References: <6b085f98-0d19-4572-be92-4fb1764a221b@googlegroups.com> Message-ID: In article <6b085f98-0d19-4572-be92-4fb1764a221b at googlegroups.com>, Miki Tebeka wrote: > > I can catch the exception, but don't see any way to tell which row caused > > the problem. Is this information obtainable, short of retrying each row > > one by one? > One way to debug this is to wrap the iterable passed to executemany with one > that remembers the last line. Something like: > > class LastIterator(object): > def __init__(self, coll): > self.it = iter(coll) > self.last = None > > def __iter__(self): > return self > > def next(self): > self.last = next(self.it) > return self.last > > ... > li = ListIterator(items) > try: > cursor.executemany(sql, li) > except SQLError, e: > print('Error: {}, row was {}'.format(e, li.last)) This assumes that the exception is raised synchronously with iterating over the input. The whole idea of executemany() is to batch up rows and send them to the database as a single unit, so this would almost certainly not be a good assumption. From hesoyam16 at gmail.com Fri Mar 29 10:52:49 2013 From: hesoyam16 at gmail.com (hesoyam16 at gmail.com) Date: Fri, 29 Mar 2013 07:52:49 -0700 (PDT) Subject: Interlacing of images Message-ID: <55801b9d-94ce-4b75-8798-86bdc899a605@googlegroups.com> Hi, I am new to python , and working on some basic stuff. I have separated the even and odd rows of a image into two separate images, now i want to combine them back, is there a simple way to do that using numpy or opencv commands or do I have to use a for loop. Thanks, Eric From breamoreboy at yahoo.co.uk Fri Mar 29 11:34:11 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 29 Mar 2013 15:34:11 +0000 Subject: Interlacing of images In-Reply-To: <55801b9d-94ce-4b75-8798-86bdc899a605@googlegroups.com> References: <55801b9d-94ce-4b75-8798-86bdc899a605@googlegroups.com> Message-ID: On 29/03/2013 14:52, hesoyam16 at gmail.com wrote: > Hi, > I am new to python , and working on some basic stuff. I have separated the even and odd rows of a image into two separate images, now i want to combine them back, is there a simple way to do that using numpy or opencv commands or do I have to use a for loop. > > Thanks, > Eric > Use the builtin zip function? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From anadionisio257 at gmail.com Fri Mar 29 13:33:26 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 29 Mar 2013 10:33:26 -0700 (PDT) Subject: Export data from python to a txt file Message-ID: Hello!!! I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to a txt file and I can't use csv. And I want the next format: a 1 3 5 6 10 b a t q r s I already have this code: "f = open("test.txt", 'w') f.write("a") f.write("\n") f.write("b") f.write("\n") for i in xrange(len(a)): LDFile.write("\t") LDFile.write(str(a[i])) LDFile.write("\t") LDFile.write(str(b[i])) f.close()" But it doesn't have the format I want. Can you help? Thanks! From jason.swails at gmail.com Fri Mar 29 13:52:12 2013 From: jason.swails at gmail.com (Jason Swails) Date: Fri, 29 Mar 2013 13:52:12 -0400 Subject: Export data from python to a txt file In-Reply-To: References: Message-ID: On Fri, Mar 29, 2013 at 1:33 PM, Ana Dion?sio wrote: > Hello!!! > > I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to > a txt file and I can't use csv. > It would help if you showed exactly what you had in your program or in the Python interpreter. For instance a = [1, 3, 5, 6, 10] b = [a, t, q, r, s] won't work, since it interprets the letters in the b-list as variables rather than strings. It would need to be b = ['a', 't', 'q', 'r', 's'] or something equivalent. Assuming you had that part correct: > And I want the next format: > > a 1 3 5 6 10 > b a t q r s > > I already have this code: > > "f = open("test.txt", 'w') > f.write("a") > f.write("\n") > f.write("b") > f.write("\n") > > for i in xrange(len(a)): > LDFile.write("\t") > LDFile.write(str(a[i])) > LDFile.write("\t") > LDFile.write(str(b[i])) > > f.close()" > > But it doesn't have the format I want. Can you help? > Walk through exactly what the computer is doing here. First it prints a, then a newline, then b, then a newline: --begin-- a b --end-- Then your for loop executes (notice LDFile and f are different file objects, so they won't write to the same location). This will print a tab, followed by the i'th element of a, followed by another tab, followed by the i'th element of b. So this: a 1 3 5 6 10 b a t q r s --begin-- [tab] 1 [tab] a [tab] 3 [tab] t [tab] 5 [tab] q [tab] 6 [tab] r [tab] 10 [tab] s [tab]--end-- So the final file will look something like this: a b 1 a 3 t 5 q 6 r 10 s which is obviously not what you want. The following code will do what you want (although there are ways of doing this in less code, this is the most straightforward): f.write('a\t') for element in a: f.write(str(element) + '\t') f.write('\n') f.write('b\t') for element in b: f.write(str(element) + '\t') f.write('\n') HTH, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Mar 29 13:58:34 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 29 Mar 2013 17:58:34 +0000 Subject: Export data from python to a txt file In-Reply-To: References: Message-ID: On 29/03/2013 17:33, Ana Dion?sio wrote: > Hello!!! > > I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to a txt file and I can't use csv. > > And I want the next format: > > a 1 3 5 6 10 > b a t q r s > > I already have this code: > > "f = open("test.txt", 'w') > f.write("a") You'll have to write your data here. > f.write("\n") And here. > f.write("b") > f.write("\n") > > for i in xrange(len(a)): > LDFile.write("\t") > LDFile.write(str(a[i])) > LDFile.write("\t") > LDFile.write(str(b[i])) You rarely need a loop like this in Python. for x in a: doSomething is the usual way of writing this. But you don't need this anyway. Just use the string join method as you can't use csv, which tells me it's homework, so I'll leave you to it :) > > f.close()" > > But it doesn't have the format I want. Can you help? > > Thanks! > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rustompmody at gmail.com Fri Mar 29 13:55:59 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 10:55:59 -0700 (PDT) Subject: Export data from python to a txt file References: Message-ID: <96cd4596-7aaf-45d3-81e9-27b378980200@w2g2000pbw.googlegroups.com> On Mar 29, 10:33?pm, Ana Dion?sio wrote: > Hello!!! > > I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to a txt file and I can't use csv. > > And I want the next format: > > a 1 3 5 6 10 > b a t q r s > > I already have this code: > > "f = open("test.txt", 'w') > ?f.write("a") > ?f.write("\n") > ?f.write("b") > ?f.write("\n") > > ?for i in xrange(len(a)): > ? ? LDFile.write("\t") > ? ? LDFile.write(str(a[i])) > ? ? LDFile.write("\t") > ? ? LDFile.write(str(b[i])) > > ?f.close()" > > But it doesn't have the format I want. Can you help? > > Thanks! Dunno about LDFile. [Neither does google] You can try: >>> a=[1,3,7,10,100] >>> "a " + " ".join(map(str,a)) 'a 1 3 7 10 100' From vincent.vandevyvre at swing.be Fri Mar 29 14:00:58 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 29 Mar 2013 19:00:58 +0100 Subject: Export data from python to a txt file In-Reply-To: References: Message-ID: <5155D6DA.8050803@swing.be> Le 29/03/13 18:33, Ana Dion?sio a ?crit : > Hello!!! > > I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to a txt file and I can't use csv. > > And I want the next format: > > a 1 3 5 6 10 > b a t q r s > > I already have this code: > > "f = open("test.txt", 'w') > f.write("a") > f.write("\n") > f.write("b") > f.write("\n") > > for i in xrange(len(a)): > LDFile.write("\t") > LDFile.write(str(a[i])) > LDFile.write("\t") > LDFile.write(str(b[i])) > > f.close()" > > But it doesn't have the format I want. Can you help? > > Thanks! > > Something like that: Python 2.6.5 (r265:79063, Oct 1 2012, 22:07:21) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a=[1,3,5,6,10] >>> b=['a', 't', 'q', 'r', 's'] >>> sta = " ".join([str(i) for i in a]) >>> stb = " ".join(b) >>> txt = "a " + sta + '\nb ' + stb >>> f = open('test.txt', 'w') >>> f.write(txt) >>> f.close() >>> f = open('test.txt', 'r') >>> for line in f: ... print line ... a 1 3 5 6 10 b a t q r s >>> -- Vincent V.V. Oqapy . Qarte . PaQager From __peter__ at web.de Fri Mar 29 14:11:01 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Mar 2013 19:11:01 +0100 Subject: Export data from python to a txt file References: Message-ID: Ana Dion?sio wrote: > I have this lists a=[1,3,5,6,10], b=[a,t,q,r,s] and I need to export it to > a txt file and I can't use csv. What do you mean by "can't use csv"? - You cannot get it to work with the csv module - You are not allowed to use csv by your instructor - Something else. > And I want the next format: > > a 1 3 5 6 10 > b a t q r s > > I already have this code: > > "f = open("test.txt", 'w') > f.write("a") > f.write("\n") > f.write("b") > f.write("\n") > > for i in xrange(len(a)): > LDFile.write("\t") > LDFile.write(str(a[i])) > LDFile.write("\t") > LDFile.write(str(b[i])) > > f.close()" > > But it doesn't have the format I want. Can you help? > > Thanks! From kruno.saho at gmail.com Fri Mar 29 14:27:19 2013 From: kruno.saho at gmail.com (Kruno Saho) Date: Fri, 29 Mar 2013 11:27:19 -0700 (PDT) Subject: Generator hack to avoid an exception Message-ID: <0e54e343-1386-47e6-a492-a00099b7edd6@googlegroups.com> I understand that 'with ignore(...)' will be coming out in Python 3.4 next year, but in the mean time I have added a yield at the end of a particular coroutine. Here is the 'fixed' version: http://pastebin.com/c8kbqc4w Here is the original version, which I believe is more pythonic: http://pastebin.com/38Fb7N0Y The reason being is to have my code outside the generator clean and flat(er). I feel that this little hack, while irritating, is more pythonic than a try/except, which only breaks out of an infinite loop, which was not there to begin with. I could replace the infinite loop with an iteration over a range, but that in itself is doing more work unnecessarily, and is just as hackish. I would not do this if the coroutine controlled any resources, as they would need to be cleaned up. I have not seen this issue addressed in PEP8. What is the consensus on this issue being more/less pythonic, and how acceptable is this practice? Thanks. From annaraven at gmail.com Fri Mar 29 14:33:10 2013 From: annaraven at gmail.com (Anna Ravenscroft) Date: Fri, 29 Mar 2013 11:33:10 -0700 Subject: Extended Call for Proposals for Presentations and Tutorials at PyCon SG 2013 In-Reply-To: References: Message-ID: Just a followup - Alex Martelli and I attended PyCon SG 2012 and it was a wonderful experience. I highly encourage folks to consider submitting a proposal to this conference. It's a worthwhile conference and a chance to visit a fascinating place. cordially, Anna On Fri, Mar 29, 2013 at 5:55 AM, George Goh wrote: > Hi, > > On behalf of the organizing committee of PyCon SG 2013, we are > announcing our Extended Call for Proposals for Presentations and > Tutorials for the 2013 PyCon Singapore Conference, to be held in > Singapore from June 13 to 15, 2013. > > We are pleased to announce that our keynote speaker is Wes McKinney, > main developer of pandas (http://pandas.pydata.org/) and author of the > new book "Python for Data Analysis". > > To submit your proposal(s) for presentations and/or tutorials, please > refer to the details found at https://pycon.sg/proposals/ > > The submission deadlines for both have been extended to April 30, 2013 > > For enquiries, pls direct them to conference at > pycon.sg > > We look forward to receiving your proposals! And to a great conference > this year. > > Best regards, > George Goh > On behalf of the PyCon SG 2013 Organizing Committee > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ -- cordially, Anna From ngnedin at gmail.com Fri Mar 29 17:04:24 2013 From: ngnedin at gmail.com (Nick Gnedin) Date: Fri, 29 Mar 2013 16:04:24 -0500 Subject: dir() vs print(dir()) in the embedded mode Message-ID: <515601D8.2000005@gmail.com> Folks, I have a newbie question: I am trying to embed Python into my application. While playing around, I noticed that the behavior of the interpreter in the embedded mode differs from the standalone one. Namely, in the standalone mode if I type dir(), I get a list of build-in symbols. In the embedded mode only print(dir()) does that, while just dir() returns silently. Is there a way to intercept the output of dir() (and all other commands) and display them to the user? Here is an example code that illustrates the behavior (the first call to PyRun_SimpleString() returns silently). Many thanks for your future hints, Nick #include int main() { Py_Initialize(); PyRun_SimpleString("dir()"); printf("-----\n"); PyRun_SimpleString("print(dir())"); Py_Finalize(); return 0; } From python at mrabarnett.plus.com Fri Mar 29 17:24:33 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Mar 2013 21:24:33 +0000 Subject: dir() vs print(dir()) in the embedded mode In-Reply-To: <515601D8.2000005@gmail.com> References: <515601D8.2000005@gmail.com> Message-ID: <51560691.90308@mrabarnett.plus.com> On 29/03/2013 21:04, Nick Gnedin wrote: > > Folks, > > I have a newbie question: I am trying to embed Python into my > application. While playing around, I noticed that the behavior of the > interpreter in the embedded mode differs from the standalone one. > > Namely, in the standalone mode if I type dir(), I get a list of build-in > symbols. In the embedded mode only print(dir()) does that, while just > dir() returns silently. > > Is there a way to intercept the output of dir() (and all other commands) > and display them to the user? > > Here is an example code that illustrates the behavior (the first call to > PyRun_SimpleString() returns silently). > > Many thanks for your future hints, > dir() doesn't print anything, it just returns a list. It's the interactive interpreter that's printing the result, unless it's None. From steve+comp.lang.python at pearwood.info Fri Mar 29 18:16:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 22:16:20 GMT Subject: dir() vs print(dir()) in the embedded mode References: Message-ID: <515612b4$0$29974$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Mar 2013 16:04:24 -0500, Nick Gnedin wrote: > Folks, > > I have a newbie question: I am trying to embed Python into my > application. While playing around, I noticed that the behavior of the > interpreter in the embedded mode differs from the standalone one. > > Namely, in the standalone mode if I type dir(), I get a list of build-in > symbols. In the embedded mode only print(dir()) does that, while just > dir() returns silently. What do you mean by "standalone mode"? If you are talking about the interactive interpreter, that is expected behaviour. The interactive interpreter automatically prints the output of every line. When running non-interactively as a script (whether embedded or not), if you want to print the output of a line, you will have to call print on that output. > Is there a way to intercept the output of dir() (and all other commands) > and display them to the user? Automatically? I don't believe so. I think it is hard-coded behaviour of the interactive interpreter, and cannot by enabled for scripts. -- Steven From rustompmody at gmail.com Sat Mar 30 01:52:28 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 22:52:28 -0700 (PDT) Subject: dir() vs print(dir()) in the embedded mode References: Message-ID: <8479da74-58aa-4521-b096-ee748dbb21d6@5g2000pbs.googlegroups.com> On Mar 30, 2:04?am, Nick Gnedin wrote: > Folks, > > I have a newbie question: I am trying to embed Python into my > application. While playing around, I noticed that the behavior of the > interpreter in the embedded mode differs from the standalone one. > > Namely, in the standalone mode if I type dir(), I get a list of build-in > symbols. In the embedded mode only print(dir()) does that, while just > dir() returns silently. This: http://docs.python.org/2/library/custominterp.html is (or can be conceptualized as providing) the interactive interpreter behavior. IOW the interactive interpreter (aka REPL) is a packaging of that. > > Is there a way to intercept the output of dir() (and all other commands) > and display them to the user? You are looking at it upside down (as MRAB hinted). You dont want to intercept (aka monkeypatch or subtract) from a functional ie value-returning dir etc Instead you want to add (your own custom) REPL behavior. > > Here is an example code that illustrates the behavior (the first call to > PyRun_SimpleString() returns silently). > > Many thanks for your future hints, > > Nick > > #include > > int main() > { > ? ?Py_Initialize(); > ? ?PyRun_SimpleString("dir()"); > ? ?printf("-----\n"); > ? ?PyRun_SimpleString("print(dir())"); > ? ?Py_Finalize(); > > ? ?return 0; > > > > > > > > } From sambez_14 at hotmail.co.uk Fri Mar 29 17:12:01 2013 From: sambez_14 at hotmail.co.uk (Sam Berry) Date: Fri, 29 Mar 2013 14:12:01 -0700 (PDT) Subject: Python class and variable issue(newby question!) Message-ID: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> Hey, Im new to object orientated programming and have an issue with using classes. Im using the kivy module, a GUI creator , so posting the actual code may confuse. But an example of what im trying to achieve is below class test() s = 1 def test1() global s s = 2 def test2() global s s = 3 def test3() global s s = 4 class test4() def printing() print test().s After been in the test()class a choice of buttons allows the user to run either of the functions within it and sends us into the test4() class. Then another button runs printing(). However printing() always prints 1, even if the variable has been changed. Im guessing because print test().s redefines the variable. May be a very simple to solve problem, but i cant figure it out. Any insights of how to get this working, or example code would be very helpful! Thanks, Sam From rosuav at gmail.com Fri Mar 29 17:24:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 08:24:00 +1100 Subject: Python class and variable issue(newby question!) In-Reply-To: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> Message-ID: On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry wrote: > class test() > s = 1 > > def test1() > global s > s = 2 > > def test2() > global s > s = 3 > > def test3() > global s > s = 4 That's not a global, that's a class variable. But to give any more specific help, it'd be helpful to have some actual working code - twiddle your code until it's a nice simple example: http://sscce.org/ Most likely, what you want is to make these functions into either static methods or instance methods. Beyond that, hard to say exactly. ChrisA From benjamin.kaplan at case.edu Fri Mar 29 17:23:13 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 29 Mar 2013 14:23:13 -0700 Subject: Python class and variable issue(newby question!) In-Reply-To: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> Message-ID: On Fri, Mar 29, 2013 at 2:12 PM, Sam Berry wrote: > Hey, > > Im new to object orientated programming and have an issue with using classes. Im using the kivy module, a GUI creator , so posting the actual code may confuse. But an example of what im trying to achieve is below > > class test() > s = 1 > > def test1() > global s > s = 2 > > def test2() > global s > s = 3 > > def test3() > global s > s = 4 > > > class test4() > > def printing() > print test().s > > After been in the test()class a choice of buttons allows the user to run either of the functions within it and sends us into the test4() class. Then another button runs printing(). > > However printing() always prints 1, even if the variable has been changed. Im guessing because print test().s redefines the variable. May be a very simple to solve problem, but i cant figure it out. > > Any insights of how to get this working, or example code would be very helpful! > > Thanks, Sam > -- There are three different namespaces here: global, class, and local. You're assigning to the global s, which exists outside the class. Do "print s" instead of "print test().s" and you'll see your changed value of s. If you want to change the value of s inside the class, it's called "test.s" (notice that there's no parenthesis- that's because s here is an attribute of the test class, not each instance of test. The same value will be shared by all instances of that class). From sambez_14 at hotmail.co.uk Fri Mar 29 18:17:45 2013 From: sambez_14 at hotmail.co.uk (Sam Berry) Date: Fri, 29 Mar 2013 15:17:45 -0700 (PDT) Subject: Python class and variable issue(newby question!) In-Reply-To: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> Message-ID: <6deb6120-e93d-429f-821f-437d25f0a761@googlegroups.com> Thanks for the responses! My issue was sorted with Benjamins post, just printing s worked. Cheers for the info though Chris, if i have any further issues il post them with some working code. Sam From rosuav at gmail.com Fri Mar 29 18:45:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 09:45:46 +1100 Subject: Python class and variable issue(newby question!) In-Reply-To: <6deb6120-e93d-429f-821f-437d25f0a761@googlegroups.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> <6deb6120-e93d-429f-821f-437d25f0a761@googlegroups.com> Message-ID: On Sat, Mar 30, 2013 at 9:17 AM, Sam Berry wrote: > Thanks for the responses! My issue was sorted with Benjamins post, just printing s worked. > > Cheers for the info though Chris, if i have any further issues il post them with some working code. Awesome! Always happy to help out. ChrisA From davea at davea.name Fri Mar 29 18:56:07 2013 From: davea at davea.name (Dave Angel) Date: Fri, 29 Mar 2013 18:56:07 -0400 Subject: Python class and variable issue(newby question!) In-Reply-To: <6deb6120-e93d-429f-821f-437d25f0a761@googlegroups.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> <6deb6120-e93d-429f-821f-437d25f0a761@googlegroups.com> Message-ID: <51561C07.7090400@davea.name> On 03/29/2013 06:17 PM, Sam Berry wrote: > Thanks for the responses! My issue was sorted with Benjamins post, just printing s worked. > > Cheers for the info though Chris, if i have any further issues il post them with some working code. > In that case, you probably should add a line like: s = None at the beginning of the code, along with a description of what s is supposed to represent (especially since the name doesn't reveal much). And you should remove the class variable s. It'll just confuse things. I guess this isn't the place to rail about non-const globals. -- DaveA From steve+comp.lang.python at pearwood.info Fri Mar 29 18:51:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2013 22:51:15 GMT Subject: Python class and variable issue(newby question!) References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> Message-ID: <51561ae3$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Mar 2013 08:24:00 +1100, Chris Angelico wrote: > On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry > wrote: >> class test() >> s = 1 >> >> def test1() >> global s >> s = 2 > That's not a global, that's a class variable. /me thwacks Chris with a halibut. Not only is "class variable" ambiguous, but Python uses different scoping rules for "variables" (name bindings) and attributes. I don't know what language first decided to conflate object attributes and variables -- I suspect Java -- but it is actively harmful terminology (in Python at least, if not in general) and whoever invented it is bad and should feel bad. -- Steven From rosuav at gmail.com Fri Mar 29 18:59:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2013 09:59:22 +1100 Subject: Python class and variable issue(newby question!) In-Reply-To: <51561ae3$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> <51561ae3$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 30, 2013 at 9:51 AM, Steven D'Aprano wrote: > On Sat, 30 Mar 2013 08:24:00 +1100, Chris Angelico wrote: > >> On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry >> wrote: >>> class test() >>> s = 1 >>> >>> def test1() >>> global s >>> s = 2 > >> That's not a global, that's a class variable. > > > /me thwacks Chris with a halibut. Ow ow ow, I give in... I am suitably and appropriately thwacked. > Not only is "class variable" ambiguous, but Python uses different scoping > rules for "variables" (name bindings) and attributes. Yes, I should have said class ATTRIBUTE. Sorry all! (Can I blame the whole 8AM and still up thing? No? Mea culpa, anyhow.) > I don't know what language first decided to conflate object attributes > and variables -- I suspect Java -- but it is actively harmful terminology > (in Python at least, if not in general) and whoever invented it is bad > and should feel bad. Agreed. Unfortunately it permeates a lot of programmer's vocabularies, mine included. ChrisA From yijianxiang100 at gmail.com Fri Mar 29 23:07:50 2013 From: yijianxiang100 at gmail.com (jianxiang.yi) Date: Fri, 29 Mar 2013 20:07:50 -0700 (PDT) Subject: take elance python test Message-ID: Hi, Did any one take elance python test? It is come from here "http://www.expertrating.com/certifications/Python-2-x-Test.asp". I want to know who have thoese subject, or demo, or souce code. Sorry about my poor english. reagrds yi From sagittarus999 at gmail.com Sat Mar 30 01:09:06 2013 From: sagittarus999 at gmail.com (TheDigitalroot) Date: Fri, 29 Mar 2013 22:09:06 -0700 (PDT) Subject: I wanna make wordlist cutter Message-ID: I imagine to make a wordlist cutter program with python pgrogramming . but I don't know too much with it . I think , first , I will make a user input as a wordlist with command eg , C:\john\Desktop\wordlist.txt and than I will use a string to count eg , Enter your count: at that time , my program assume count of numbers like notepad ++ which inlcude in wordlist.txt that i input with command . How can i code for that , please guide me and help me . From rustompmody at gmail.com Sat Mar 30 01:25:38 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 22:25:38 -0700 (PDT) Subject: I wanna make wordlist cutter References: Message-ID: <3c24695e-e28a-48d8-b4bb-43247f73aee8@j1g2000pbq.googlegroups.com> On Mar 30, 10:09?am, TheDigitalroot wrote: > I imagine to make a wordlist cutter program with python pgrogramming . but I don't know too much with it . > > I think , first , I will make a user input as a wordlist with command > > eg , C:\john\Desktop\wordlist.txt > > and than I will use a string to count > > eg , Enter your count: > > at that time , my program assume count of numbers like notepad ++ which inlcude in wordlist.txt that i input with command . > > How can i code for that , please guide me and help me . No idea what is 'wordlist cutter.' Are you assuming that folks here should be upto speed with notepad++ vocabulary? From sagittarus999 at gmail.com Sat Mar 30 01:28:42 2013 From: sagittarus999 at gmail.com (TheDigitalroot) Date: Fri, 29 Mar 2013 22:28:42 -0700 (PDT) Subject: I wanna make wordlist cutter In-Reply-To: References: Message-ID: <06e315c2-3284-4271-89d6-ad2a030b07cc@googlegroups.com> nope , my bro i mean count number . In notepad ++ , when we insert words like the follwoing , book cook meet beat we know 4 words because Notepad ++ show me 4 counts of words . I mean that , bro thanks From rustompmody at gmail.com Sat Mar 30 01:38:36 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Mar 2013 22:38:36 -0700 (PDT) Subject: I wanna make wordlist cutter References: <06e315c2-3284-4271-89d6-ad2a030b07cc@googlegroups.com> Message-ID: On Mar 30, 10:28?am, TheDigitalroot wrote: > nope , my bro i mean count number . > > In notepad ++ , when we insert words like the follwoing , > book > cook > meet > beat > > we know 4 words because Notepad ++ show me 4 counts of words . > > I mean that , bro > thanks Still cant make out what you want. Anyways heres a suggestion. To start with forget about files; work with (triple quoted?) strings And before that maybe a simple string representing a single line. And before that maybe a list containing strings, where each string is a word as you want. Now do what you want with that list (Or tell us what you want done) Then reverse-engineer back to files (Or if stuck tell us where) From sagittarus999 at gmail.com Sat Mar 30 01:30:17 2013 From: sagittarus999 at gmail.com (TheDigitalroot) Date: Fri, 29 Mar 2013 22:30:17 -0700 (PDT) Subject: I wanna make wordlist cutter In-Reply-To: References: Message-ID: <5546fb63-50f3-4305-94a9-37433605153d@googlegroups.com> I mean , I wanna detect counts of words that i insert with command line . From sagittarus999 at gmail.com Sat Mar 30 02:06:55 2013 From: sagittarus999 at gmail.com (TheDigitalroot) Date: Fri, 29 Mar 2013 23:06:55 -0700 (PDT) Subject: I wanna make wordlist cutter In-Reply-To: References: Message-ID: <9e1f3f43-b204-463e-9944-913f09e9708b@googlegroups.com> On Saturday, March 30, 2013 9:09:06 AM UTC+4, TheDigitalroot wrote: > I imagine to make a wordlist cutter program with python pgrogramming . but I don't know too much with it . > > > > I think , first , I will make a user input as a wordlist with command > > > > eg , C:\john\Desktop\wordlist.txt > > > > and than I will use a string to count > > > > eg , Enter your count: > > > > at that time , my program assume count of numbers like notepad ++ which inlcude in wordlist.txt that i input with command . > > > > How can i code for that , please guide me and help me . thanks bro , all of the others can give me a dvice or sample codes From xxy-php at qq.com Sat Mar 30 01:08:10 2013 From: xxy-php at qq.com (=?gb18030?B?0KHRp9SwUEhQ?=) Date: Sat, 30 Mar 2013 13:08:10 +0800 Subject: Curl and python httplib? Message-ID: Guys, I take a project that need send request to Hadoop by curl. But now, the curl and pycurl can't satisfy my project. So i need use the powerful httplib. But failed. my curl request: curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" my return: HTTP/1.1 307 TEMPORARY_REDIRECT Content-Type: application/octet-stream Location: http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false Content-Length: 0 Server: Jetty(6.1.26) Now, i change the curl request to httplib: import httplib import urllib params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) headers={"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn=httplib.HTTPConnection("localhost:50070") conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) response=conn.getresponse() print response.status, response.reason data=response.read() print data conn.close() But it failed: #print response.status, response.reason 500 Internal Server Error #print data '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' Who knows why? It's OK when i use curl, so where is the problem in httplib method? Or some other reasons? Who can help me change the curl request to httplib edition? TIA Levi -------------- next part -------------- An HTML attachment was scrubbed... URL: From amachu at amachu.me Sat Mar 30 03:52:59 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Sat, 30 Mar 2013 13:22:59 +0530 Subject: round off to two decimal & return float Message-ID: <515699DB.8060104@amachu.me> Consider the scenario, >> a = 10 >> "{0:.2f}".format(a) '10.00' This returns a string 10.00. But what is the preferred method to retain 10.0 (float) as 10.00 (float)? I am trying to assign the value to a cell of a spreadsheet, using python-xlwt. I would like to have 10.00 as the value that is right aligned. With text it is left aligned. -- Sri Ramadoss M From roland.em0001 at googlemail.com Sat Mar 30 05:28:41 2013 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sat, 30 Mar 2013 11:28:41 +0200 Subject: round off to two decimal & return float In-Reply-To: <515699DB.8060104@amachu.me> References: <515699DB.8060104@amachu.me> Message-ID: Hello, 2013/3/30 ??????? > Consider the scenario, > > >> a = 10 > >> "{0:.2f}".format(a) > '10.00' > > This returns a string 10.00. But what is the preferred method to retain > 10.0 (float) as 10.00 (float)? > > I assume you have a numeric value a and want to have a float with 2 decimals. This can be achieved with the function round(): >>> a = 10 >>> type(a) >>> a = round(10,2) >>> type (a) >>> a 10.0 BR, Roland > I am trying to assign the value to a cell of a spreadsheet, using > python-xlwt. I would like to have 10.00 as the value that is right > aligned. With text it is left aligned. > > -- > > Sri Ramadoss M > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From amachu at amachu.me Sat Mar 30 05:32:34 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Sat, 30 Mar 2013 15:02:34 +0530 Subject: round off to two decimal & return float In-Reply-To: References: <515699DB.8060104@amachu.me> Message-ID: <5156B132.2040801@amachu.me> On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: > > > > I assume you have a numeric value a and want to have a float with 2 > decimals. This can be achieved with the function round(): But I need 10.00 and not 10.0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From roland.em0001 at googlemail.com Sat Mar 30 05:43:46 2013 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sat, 30 Mar 2013 11:43:46 +0200 Subject: round off to two decimal & return float In-Reply-To: References: <515699DB.8060104@amachu.me> Message-ID: 2013/3/30 Roland Mueller > Hello, > > 2013/3/30 ??????? > >> Consider the scenario, >> >> >> a = 10 >> >> "{0:.2f}".format(a) >> '10.00' >> >> This returns a string 10.00. But what is the preferred method to retain >> 10.0 (float) as 10.00 (float)? >> >> I assume you have a numeric value a and want to have a float with 2 > decimals. This can be achieved with the function round(): > > Of course the representation of the float having a given number of decimals printed out is always a string. The float format does not imply any formatting and Python's default formatting when a float is printed out is to print as decimals as needed. Thus, using round() fives you a float with maximal two decimals. >>> a = 9.2022222 >>> a = round(a,2) >>> a 9.2 >>> a = 9.2222222 >>> a = round(a,2) >>> a 9.22 >>> a = 10 > > > >>> type(a) > > > >>> a = round(10,2) > > > > >>> type (a) > > > > > > >>> a > > > 10.0 > > BR, > Roland > > >> I am trying to assign the value to a cell of a spreadsheet, using >> python-xlwt. I would like to have 10.00 as the value that is right >> aligned. With text it is left aligned. >> >> -- >> >> Sri Ramadoss M >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Sat Mar 30 09:36:53 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 30 Mar 2013 13:36:53 +0000 (UTC) Subject: round off to two decimal & return float References: <515699DB.8060104@amachu.me> Message-ID: On 2013-03-30, ????????????????????? wrote: > On Saturday 30 March 2013 02:58 PM, Roland Mueller wrote: >> >> >> >> I assume you have a numeric value a and want to have a float with 2 >> decimals. This can be achieved with the function round(): > > But I need 10.00 and not 10.0 They're the same number. Are you asking how to format floating point numbers when they're displayed? -- Grant From julius.welby at gmail.com Sat Mar 30 05:30:08 2013 From: julius.welby at gmail.com (pyplexed) Date: Sat, 30 Mar 2013 02:30:08 -0700 (PDT) Subject: round off to two decimal & return float In-Reply-To: References: Message-ID: Hi Sri. I'm not familiar with the xlwt module, but I think you are confusing two different things here. Generally spreadsheets separate out how they handle the value in a cell (the value) and how that value is displayed (the format). This means that the you leave the cell value unchanged when you tell Excel separately that the number should be displayed as, for example, a percentage, a date, in scientific notation, or as a float with a specified number of decimal places etc. Try converting the integer to a floating point number using float(a), and see what the default format for floats looks like when you open the output in Excel. It may be OK for you. If not, take a look at the python-xlwt/examples folder. num_formats.py shows how to apply Excel number formats to cells. By the way, if you are doing this kind of thing frequently or at any kind of scale, you may find it easier to use something like the pandas module to do your data manipulation and then you can use pandas' DataFrame.to_excel method which allows you to define a format for floats in the output, and also provides many other options. HTH From julius.welby at gmail.com Sat Mar 30 05:30:08 2013 From: julius.welby at gmail.com (pyplexed) Date: Sat, 30 Mar 2013 02:30:08 -0700 (PDT) Subject: round off to two decimal & return float In-Reply-To: References: Message-ID: Hi Sri. I'm not familiar with the xlwt module, but I think you are confusing two different things here. Generally spreadsheets separate out how they handle the value in a cell (the value) and how that value is displayed (the format). This means that the you leave the cell value unchanged when you tell Excel separately that the number should be displayed as, for example, a percentage, a date, in scientific notation, or as a float with a specified number of decimal places etc. Try converting the integer to a floating point number using float(a), and see what the default format for floats looks like when you open the output in Excel. It may be OK for you. If not, take a look at the python-xlwt/examples folder. num_formats.py shows how to apply Excel number formats to cells. By the way, if you are doing this kind of thing frequently or at any kind of scale, you may find it easier to use something like the pandas module to do your data manipulation and then you can use pandas' DataFrame.to_excel method which allows you to define a format for floats in the output, and also provides many other options. HTH From __peter__ at web.de Sat Mar 30 05:44:04 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 30 Mar 2013 10:44:04 +0100 Subject: round off to two decimal & return float References: <515699DB.8060104@amachu.me> Message-ID: ??????? wrote: > Consider the scenario, > >>> a = 10 >>> "{0:.2f}".format(a) > '10.00' > > This returns a string 10.00. But what is the preferred method to retain > 10.0 (float) as 10.00 (float)? You can use round() to convert 1.226 to 1.23 >>> round(1.225, 2) 1.23 for example, but 10.0 and 10.00 are the same float value -- there's no way to keep track of the number of digits you want to see. > I am trying to assign the value to a cell of a spreadsheet, using > python-xlwt. I would like to have 10.00 as the value that is right > aligned. With text it is left aligned. You can pass 10.0 as the cell value and apply a format to the cell: # adapted from #https://secure.simplistix.co.uk/svn/xlwt/trunk/xlwt/examples/num_formats.py import xlwt workbook = xlwt.Workbook() worksheet = workbook.add_sheet('Example') numbers = [10, 1.0/6] headers = ["raw", "rounded", "formatted", "rounded and formatted"] style = xlwt.XFStyle() style.num_format_str = "0.00" for column, header in enumerate(headers): worksheet.write(0, column, header) for row, value in enumerate(numbers, 1): worksheet.write(row, 0, value) worksheet.write(row, 1, round(value, 2)) worksheet.write(row, 2, value, style) worksheet.write(row, 3, round(value, 2), style) workbook.save('tmp.xls') Move over the cells with the cursor in Excel to compare what is displayed with the actual value. From amachu at amachu.me Sat Mar 30 14:18:12 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Sat, 30 Mar 2013 23:48:12 +0530 Subject: round off to two decimal & return float In-Reply-To: References: <515699DB.8060104@amachu.me> Message-ID: <51572C64.4080804@amachu.me> On Saturday 30 March 2013 03:14 PM, Peter Otten wrote: > style = xlwt.XFStyle() > style.num_format_str = "0.00" Yes. That was really helpful & what I expected. Thank you. From rurpy at yahoo.com Sat Mar 30 13:32:32 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 30 Mar 2013 10:32:32 -0700 (PDT) Subject: round off to two decimal & return float In-Reply-To: References: <515699DB.8060104@amachu.me> Message-ID: <0c19c474-ee09-41e1-945e-291cc8325fe9@googlegroups.com> On 03/30/2013 10:41 AM, Dennis Lee Bieber wrote: > On Sat, 30 Mar 2013 13:22:59 +0530, ??????? declaimed > the following in gmane.comp.python.general: > >> Consider the scenario, >> >> >> a = 10 >> >> "{0:.2f}".format(a) >> '10.00' >> >> This returns a string 10.00. But what is the preferred method to retain >> 10.0 (float) as 10.00 (float)? >> >> I am trying to assign the value to a cell of a spreadsheet, using >> python-xlwt. I would like to have 10.00 as the value that is right >> aligned. With text it is left aligned. > > That is a matter of the spreadsheet formatting the floating point to > some number of decimal places... Internally it is just saving 1.0E1 > (well, actually, it is saving the binary equivalent). > > I don't believe xlwt gives access to the formatting controls, does > it? [...] It does. Here is a short example of how to set the numeric formatting of cells. There are more example in the xlwt documentation at https://github.com/python-excel/xlwt/tree/master/xlwt/examples -------- #!/usr/bin/env python2 import xlwt def main(): w = xlwt.Workbook() ws = w.add_sheet('Sheet1') style_money = xlwt.XFStyle() style_money.num_format_str = '[$$-409]#,##0.00;[RED]-[$$-409]#,##0.00' for row in range(6): ws.write(row, 1, 'Test') ws.write(row, 2, 3.123456 - row) ws.write(row, 3, 3.123456 - row, style_money) w.save('test.xls') if __name__ == '__main__': main() -------- > You may have to use the win32 extensions an open an instance of > Excel, then use Excel's library of functions to select the cell and > change formatting. From roy at panix.com Sat Mar 30 12:19:39 2013 From: roy at panix.com (Roy Smith) Date: Sat, 30 Mar 2013 12:19:39 -0400 Subject: MySQLdb not playing nice with unicode Message-ID: 5.1.63-log MySQL Community Server (GPL) Python 2.7.3 MySQL-python==1.2.3 I've got a table: CREATE TABLE `songza_temp` ( `s` varchar(1000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; When I run this code: -------------------------------------------- db = MySQLdb.connect(host=db_host, db=db_db, user=db_user, passwd=db_passwd, charset='utf8', sql_mode='TRADITIONAL') cursor = db.cursor() baloon = u'\U0001f388' print "baloon=%s, repr=%r, length=%d" % (baloon, baloon, len(baloon)) cursor.execute("insert into songza_temp (s) values (%s)", [baloon]) -------------------------------------------- I get: baloon= cursor.execute("insert into songza_temp (s) values (%s)", [baloon]) File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.OperationalError: (1366, "Incorrect string value: '\\xF0\\x9F\\x8E\\x88' for column 's' at row 1") My unicode-fu is a bit weak. Are we looking at a Python problem, a MySQLdb problem, or a problem with the underlying MySQL server? We've certainly inserted utf-8 data before without any problems. It's possible this is the first time we've tried to handle a character outside the BMP. From roy at panix.com Sat Mar 30 12:41:19 2013 From: roy at panix.com (Roy Smith) Date: Sat, 30 Mar 2013 12:41:19 -0400 Subject: MySQLdb not playing nice with unicode References: Message-ID: In article , Roy Smith wrote: > My unicode-fu is a bit weak. Are we looking at a Python problem, a > MySQLdb problem, or a problem with the underlying MySQL server? We've > certainly inserted utf-8 data before without any problems. It's > possible this is the first time we've tried to handle a character > outside the BMP. Sigh. As is so often the case, I found the answer shortly after posting this. http://stackoverflow.com/questions/1890693/ It turns out MySQL (at least the version we're running) can't handle characters outside the BMP! OK, that leads to the next question. Is there anyway I can (in Python 2.7) detect when a string is not entirely in the BMP? If I could find all the non-BMP characters, I could replace them with U+FFFD (REPLACEMENT CHARACTER) and life would be good (enough). Apparently, newer versions of MySQL have utf8mb4 which can handle this. On possibility is upgrading to a new MySQL, but if we could just catch and replace the non-BMP characters during ingestion, that would be a lot simpler. From hossamalagmy at gmail.com Sat Mar 30 12:47:55 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sat, 30 Mar 2013 09:47:55 -0700 (PDT) Subject: HTC ChaCha review Message-ID: HTC ChaCha review http://natigtas7ab.blogspot.com/2012/10/htc-chacha-review.html From naccttemha at gmail.com Sat Mar 30 16:39:47 2013 From: naccttemha at gmail.com (Nac Temha) Date: Sat, 30 Mar 2013 22:39:47 +0200 Subject: How to set or get enviroment variable Message-ID: Hi, I want to get and set enviroment variable of linux system. Actually I can do this issue using os module but How can I do without using os module? Is there another way? Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 30 16:45:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Mar 2013 07:45:07 +1100 Subject: How to set or get enviroment variable In-Reply-To: References: Message-ID: On Sun, Mar 31, 2013 at 7:39 AM, Nac Temha wrote: > Hi, I want to get and set enviroment variable of linux system. Actually I > can do this issue using os module but How can I do without using os module? > Is there another way? Why would you want to do it without the os module? That IS the way to do it. Why would there be another way? ChrisA From rosuav at gmail.com Sat Mar 30 16:52:54 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Mar 2013 07:52:54 +1100 Subject: How to set or get enviroment variable In-Reply-To: References: Message-ID: On Sun, Mar 31, 2013 at 7:52 AM, Nac Temha wrote: > Just wondering. most ideal approach is use os module, is true? Yes, it most definitely is. ChrisA From naccttemha at gmail.com Sat Mar 30 16:53:05 2013 From: naccttemha at gmail.com (Nac Temha) Date: Sat, 30 Mar 2013 22:53:05 +0200 Subject: How to set or get enviroment variable In-Reply-To: References: Message-ID: Just wondering. most ideal approach is use os module, is true? On Sat, Mar 30, 2013 at 10:45 PM, Chris Angelico wrote: > On Sun, Mar 31, 2013 at 7:39 AM, Nac Temha wrote: > > Hi, I want to get and set enviroment variable of linux system. Actually I > > can do this issue using os module but How can I do without using os > module? > > Is there another way? > > Why would you want to do it without the os module? That IS the way to > do it. Why would there be another way? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sat Mar 30 17:07:41 2013 From: davea at davea.name (Dave Angel) Date: Sat, 30 Mar 2013 17:07:41 -0400 Subject: How to set or get enviroment variable In-Reply-To: References: Message-ID: <5157541D.7070904@davea.name> On 03/30/2013 04:39 PM, Nac Temha wrote: > Hi, I want to get and set enviroment variable of linux system. Actually I > can do this issue using os module but How can I do without using os module? > Is there another way? > > As Chris has said, the os module is the way to get and modify the environment of your Python program, whether on Linux or elsewhere. However, the wording of your question was ambiguous enough that I thought I'd better clarify. Changing the environment within one application does not in general affect any other. So if you had thoughts of setting an environment variable from your python script, and exiting, and having the next thing you ran from the shell affected, better think again. That sort of thing needs to be done from the shell, rather than from a script. And while there are tricks to do, they're Linux-- (or Windows, or whatever) tricks, not Python ones. -- DaveA From bv8bv8bv8 at gmail.com Sat Mar 30 16:45:03 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 30 Mar 2013 13:45:03 -0700 (PDT) Subject: The Quran...A Book You Can Believe In Message-ID: The Quran...A Book You Can Believe In We invite you to take a few minutes to learn something about a book that is the foundation of the worldwide & culture of almost one-fourth of the people on this planet. The Quran A book you can believe in The Quran is the most often-read book in the world. Revealed by God to the Prophet Muhammad (peace be upon him) in the 7th century, and revered by Muslims being God's final Scripture and Testament; its words have been lovingly recited, memorized, and implemented by Muslims Of every nationality ever since. The faithful are inspired, consoled often moved to tears by its eloquence and poetic imagery, especially when recited aloud. And yet, the Qur'an is unique in being the only Scripture that is free of scientific inaccuracies, whose historical authenticity can be verified, and whose text has been so carefully preserved that just one authorized version (in Arabic) exists. Approximately the length of the New Testament, the Qur'an is also the only holy book that can be memorized in its entirety by people of all ages and intellectual abilities including non Arabic speakers, which Muslims consider to be one of its miracles. We invite you to take a few minutes to learn something about a book that is the foundation of the worldview and culture of almost one-fourth of the people on this planet. A Scientific Scripture for a scientific age One of the most remarkable things about the Qur'an is that it contains many verses which accurately describe natural phenomena in various fields such as embryology, astronomy, geology and oceanography. Scientists have found its descriptions to be inexplicably valid for a book dating from the 6th century, in fact, many of the processes and functions mentioned in the Qur'an have been discovered only recently. This fact alone has been the cause of a number of distinguished scientists embracing Islam. It never arose in Islam; the Qur'an repeatedly encourages people to reflect and use their intelligence, and most Muslim scientists and inventors have also been pious believers. Some of the Qur'an's 'scientific' verses include an accurate description of embryonic development during the first forty days of life; an explanation that the roots of mountains are like pegs which help to anchor and stabilize the earth's crust, that a natural barrier exists wherever two seas meet (each maintains its own salinity, temperature and density); that waves occur in layers in the depths of the ocean; that the heavens and earth were first joined together before being split apart; and that the heavens emerged from "smoke', i, e, the gases and dust that characterize nebulas as stars are forming. The Qur'an was never meant to be a 'science textbook'; whether highlighting the wonders of nature or the lessons of history, its verses direct us to reflect on the glory of God, However, no other ancient book or Scripture is accurate in this way, Muslims believe that this is one of the Qur'an's proofs; one of the things that makes it a credible, ' living revelation' for a modern age, and allows it to reveal itself afresh with passing time. The Qur'an and the development of knowledge The word 'Qur'an' means 'recitation'. And the first verse; of the! Qur'an to be revealed by the Angel Gabriel to the prophet Muhammad was a command to {Read! In the name of your Lord...} {??????? ??????? ???????...} Transliteration: Iqra biismi rabbika This directive to a man who, like most people of the time, could neither read nor write; marked the beginning of a new age in human communication, learning, and development. Whereas earlier Scriptures had been written and passed down by elite circles of priests and scribes usually long after the death of the religion's founder the preservation of the Qur'an was a community effort from the beginning, and it was completed during the Prophet Muhammad's own lifetime. The Prophet's early followers eagerly memorized and recorded each new revelation as it was revealed: by the time he passed away, thousands had memorized the entire Qur'an by heart. Within two years after the Prophet's death, the first caliph Abu Bakr requested the Prophet's secretary Zayd to collect all existing copies and fragments of the Qur'an in one place, in order to compile a standard edition. This manuscript became the basis for the authorized editions that were distributed to each Muslim province during the rule of 'Uthman (the third caliph): remarkably, a few of those early manuscripts have been preserved and can still be viewed in museums today. Following the example of the beloved Prophet, who encouraged all Muslims, male and female, to seek beneficial knowledge, mosques became centers of learning as well as prayer. The concept of universal, free basic education originated in Islam; children learned to read, write, memorize the Qur'an and do basic maths at village mosque schools; bright students were sent to cities to pursue higher education. The world's first universities, hospitals and postal services were established by Muslims. Early caliphs set up institutions like the 'House of Wisdom' in Baghdad, where scholars were paid to translate scientific, literary and religious works from every known language into Arabic. It was this open-mindedness that inspired Jews and Christians under Muslim rule in Spain to translate classical Roman and Greek texts from Arabic into European languages, sparking the European Renaissance. A Book with a Message & a Purpose Like all books, the Qur'an is a means to convey a message in this case, a very special message from the Creator to all humanity. The Qur'an is an 'owner's manual for the human being': whoever wonders about the purpose of life and their own existence will find to be guide par excellence. Building on prior revelations, this Final Testament confirms the age- old truths of previous Scriptures, but clarifies points of faith where error or confusion have crept into them over the centuries. Those who have read the Bible will find much that is familiar: descriptions of God's handiwork, stories of the Prophets. Satan, angels and the Day of Judgment, moral and ethical guidelines, and spiritual practices like prayer and fasting. Yet the Qur'an is not just a re-hashing of old stones, its perspective is unique and fresh, and its worldview eminently suited to people of today. To give one example, according to the Qur'an, God held Adam and Eve jointly responsible for tasting the forbidden fruit; no special curse was laid on Eve for leading Adam astray. And no 'original sin' came into being, to be inherited for all time by innocent children. Adam and Eve simply sought His forgiveness and were forgiven, and Adam (peace be upon him) is respected in Islam as the first Prophet. There are other important distinctions between the Qur'an and the Bible; the Qur'an asserts that much of the original books of the Bible and other Scriptures have been lost or corrupted over time (whether through war fare, political intrigue, religious schisms or other reasons). One only has to consider the number of different versions of the Bible in use today, the lack of "first" originals, and the late discovery of long-lost scriptures like the Dead Sea Scrolls to realize that this viewpoint is an objective one. The Qur'an rejects the concept of salvation or special privilege based on ethnicity: God does not discriminate on the basis of race or colour. It also denies the need for the sacrifice of innocent life, animal or human in order for people to attain salvation. It states that Jesus (peace be upon him) was not crucified as claimed, but that God saved him from his enemies, as one would expect of God's honoured and beloved Messenger; his life was meant to be an inspiring example. Spiritual salvation is to be achieved solely through humble repentance, coupled by an attempt to make amends for one's sins, and a sincere intention not to repeat one's mistakes in the future. There is no official priesthood in Islam, and the Imam is no more than a knowledgeable prayer-leader and brother in faith; one's sins need only be confessed directly to the Creator. The Qur'an's main message is to call people to turn to the Source of all being and the Giver of life, and to serve Him with a pure heart free of idolatry or superstition. In Islam, "One God" means just that there is no concept of trinity, or anything else to complicate one's understanding Like the single nucleus of a cell or an atom. He alone is the control centre' behind it all: anything else would lead to chaos and confusion. God is Unique and without partner; He was not born and did not give birth; he is All-Compassionate and Merciful, Almighty and Just, and the only One we need turn to for guidance and help. Anything that we allow to come between ourselves and our Creator even our own egos is an idol. Wealth, fame, physical attraction and all the pleasures of this world will someday fade, and we will not be able to take them with us when we die. Only our faith and good deeds will remain, to light our graves and be a beacon for us on the Day of Judgment. Although no translation of the Qur'an can faithfully capture its Arabic meaning (and all Muslims are encouraged to learn Arabic), the following excerpt illustrates these points beautifully: { And recite to them the story of Ibrahim (Abraham). (69) When he said to his father and his people: "What do you worship?" (70) They said: "We worship idols, and to them we are ever devoted." (71) He said: "Do they hear you, when you call (on them)? (72) "Or do they benefit you or do they harm (you)?" (73) They said: "Nay, but we found our fathers doing so." (74) He said: "Do you observe that which you have been worshipping, (75) "You and your ancient fathers? (76) "Verily! They are enemies to me, save the Lord of the 'Alamin (mankind, jinns and all that exists); (77) "Who has created me, and it is He Who guides me; (78) "And it is He Who feeds me and gives me to drink. (79) "And when I am ill, it is He who cures me. (80) "And Who will cause me to die, and then will bring me to life (again); (81) "And Who, I hope will forgive me my faults on the Day of Recompense, (the Day of Resurrection)," (82) My Lord! Bestow Hukman (religious knowledge, right judgement of the affairs and Prophethood) on me, and join me with the righteous; (83) And grant me an honourable mention in later generations; (84) And make me one of the inheritors of the Paradise of Delight; (85) And forgive my father, verily he is of the erring; (86) And disgrace me not on the Day when (all the creatures) will be resurrected; (87) The Day whereon neither wealth nor sons will avail, (88) Except him who brings to Allah a clean heart [clean from Shirk (polytheism) and Nifaq (hypocrisy)].} [Ash-Shu?raa? 26:69-89] {??????? ?????????? ?????? ???????????? ???? ???? ????? ????????? ?????????? ??? ??????????? ???? ??????? ???????? ?????????? ????????? ????? ?????????? ???? ????? ???? ??????????????? ???? ????????? ? ??? ???? ?????????????? ???? ?????????? ???? ??????? ???? ????????? ????????? ????????? ??????????? ???? ????? ????????????? ???? ??????? ??????????? ???? ??????? ???????????? ?????????????? ???? ??????????? ??????? ???? ?????? ????? ????????????? ???? ??????? ????????? ?????? ????????? ???? ????????? ???? ??????????? ??????????? ???? ??????? ???????? ?????? ????????? ???? ????????? ?????????? ????? ????????? ? ??? ????????? ???????? ??? ???????? ??? ?????????? ?????? ???????? ? ??? ????? ???? ??? ??????? ????????????? ??????????????? ???? ???????? ???? ??????? ?????? ??? ??????????? ???? ???????????? ??? ???????? ??????? ?????????? ???? ????????? ??????? ??????? ????? ???? ???????????? ???? ????? ????????? ?????? ??????????? ???? ?????? ??? ??????? ????? ????? ??????? ???? ?????? ???? ????? ???????? ???????? ???????} ???????: 69-89 Transliteration: Waotlu AAalayhim nabaa ibraheema (69) Ith qala liabeehi waqawmihi ma taAAbudoona (70) Qaloo naAAbudu asnaman fanathallu laha AAakifeena (71) Qala hal yasmaAAoonakum ith tadAAoona (72) Aw yanfaAAoonakum aw yadurroona (73) Qaloo bal wajadnaabaana kathalika yafAAaloona (74) Qala afaraaytum makuntum taAAbudoona (75) Antum waabaokumu alaqdamoona (76) Fainnahum AAaduwwun lee illa rabba alAAalameena (77) Allathee khalaqanee fahuwa yahdeeni(78) Waallathee huwa yutAAimunee wayasqeeni (79)Waitha maridtu fahuwa yashfeeni (80) Waallathee yumeetunee thumma yuhyeeni (81) Waallathee atmaAAu an yaghfira lee khateeatee yawma alddeeni (82) Rabbi hab lee hukman waalhiqnee bialssaliheena (83)WaijAAal lee lisana sidqin fee alakhireena (84)WaijAAalnee min warathati jannati alnnaAAeemi (85)Waighfir liabee innahu kana mina alddalleena (86) Walatukhzinee yawma yubAAathoona (87) Yawma layanfaAAu malun wala banoona (88) Illa man ata Allaha biqalbin saleemin http://en.islamway.net/article/12393 thank you From morphex at gmail.com Sun Mar 31 02:56:46 2013 From: morphex at gmail.com (morphex) Date: Sat, 30 Mar 2013 23:56:46 -0700 (PDT) Subject: Why does 1**2**3**4**5 raise a MemoryError? Message-ID: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Hi. I was just doodling around with the python interpreter today, and here is the dump from the terminal: morphex at laptop:~$ python Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1**2 1 >>> 1**2**3 1 >>> 1**2**3**4 1L >>> 1**2**3**4**5 Traceback (most recent call last): File "", line 1, in MemoryError >>> Does anyone know why this raises a MemoryError? Doesn't make sense to me. Happy Easter! -Morten From davea at davea.name Sun Mar 31 03:34:31 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 03:34:31 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: <5157E707.2060302@davea.name> On 03/31/2013 02:56 AM, morphex wrote: > Hi. > > I was just doodling around with the python interpreter today, and here is the dump from the terminal: > > morphex at laptop:~$ python > Python 2.7.3 (default, Sep 26 2012, 21:53:58) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 1**2 > 1 >>>> 1**2**3 > 1 >>>> 1**2**3**4 > 1L >>>> 1**2**3**4**5 > Traceback (most recent call last): > File "", line 1, in > MemoryError >>>> > > Does anyone know why this raises a MemoryError? Doesn't make sense to me. > > Perhaps you didn't realize that the expression will be done from right to left. So first it calculates 4**5 which is 1024 Then it calculates 3**1024, which has 488 digits. then it calculates 2 to that power, which is a number large enough to boggle the mind. That number's storage needs makes a few gigabytes seem like a molecule in the ocean. Anyway, it never gets around to doing the 1** part. On the other hand, perhaps you wanted to do a different calculation: >>> ((((1**2)**3)**4)**5) 1 -- DaveA From steve+comp.lang.python at pearwood.info Sun Mar 31 03:33:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Mar 2013 07:33:32 GMT Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote: > Hi. > > I was just doodling around with the python interpreter today, and here > is the dump from the terminal: > > morphex at laptop:~$ python > Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 1**2 > 1 >>>> 1**2**3 > 1 >>>> 1**2**3**4 > 1L >>>> 1**2**3**4**5 > Traceback (most recent call last): > File "", line 1, in > MemoryError >>>> >>>> > Does anyone know why this raises a MemoryError? Doesn't make sense to > me. Because exponentiation is right-associative, not left. 1**2**3**4**5 is calculated like this: 1**2**3**4**5 => 1**2**3**1024 => 1**2**373...481 # 489-digit number => 1**(something absolutely humongous) => 1 except of course you get a MemoryError in calculating the intermediate values. In other words, unlike you or me, Python is not smart enough to realise that 1**(...) is automatically 1, it tries to calculate the humongous intermediate result, and that's what fails. For what it's worth, that last intermediate result (two to the power of the 489-digit number) has approximately a billion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion trillion digits. (American billion and trillion, 10**9 and 10**12 respectively.) -- Steven From davea at davea.name Sun Mar 31 03:48:02 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 03:48:02 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5157EA32.6010607@davea.name> On 03/31/2013 03:33 AM, Steven D'Aprano wrote: > On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote: > >> Hi. >> >> I was just doodling around with the python interpreter today, and here >> is the dump from the terminal: >> >> morphex at laptop:~$ python >> Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> 1**2 >> 1 >>>>> 1**2**3 >> 1 >>>>> 1**2**3**4 >> 1L >>>>> 1**2**3**4**5 >> Traceback (most recent call last): >> File "", line 1, in >> MemoryError >>>>> >>>>> >> Does anyone know why this raises a MemoryError? Doesn't make sense to >> me. > > Because exponentiation is right-associative, not left. > > 1**2**3**4**5 is calculated like this: > > 1**2**3**4**5 > => 1**2**3**1024 > => 1**2**373...481 # 489-digit number Oops, you're right, it's 489. I figured 488 but was wrong. -- DaveA From morphex at gmail.com Sun Mar 31 08:07:08 2013 From: morphex at gmail.com (morphex) Date: Sun, 31 Mar 2013 05:07:08 -0700 (PDT) Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Aha, OK. Thought I found a bug but yeah that makes sense ;) While we're on the subject, wouldn't it be nice to have some cap there so that it isn't possible to more or less block the system with large exponentiation? On Sunday, March 31, 2013 9:33:32 AM UTC+2, Steven D'Aprano wrote: > On Sat, 30 Mar 2013 23:56:46 -0700, morphex wrote: > > > > > Hi. > > > > > > I was just doodling around with the python interpreter today, and here > > > is the dump from the terminal: > > > > > > morphex at laptop:~$ python > > > Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> 1**2 > > > 1 > > >>>> 1**2**3 > > > 1 > > >>>> 1**2**3**4 > > > 1L > > >>>> 1**2**3**4**5 > > > Traceback (most recent call last): > > > File "", line 1, in > > > MemoryError > > >>>> > > >>>> > > > Does anyone know why this raises a MemoryError? Doesn't make sense to > > > me. > > > > Because exponentiation is right-associative, not left. > > > > 1**2**3**4**5 is calculated like this: > > > > 1**2**3**4**5 > > => 1**2**3**1024 > > => 1**2**373...481 # 489-digit number > > => 1**(something absolutely humongous) > > => 1 > > > > except of course you get a MemoryError in calculating the intermediate > > values. > > > > In other words, unlike you or me, Python is not smart enough to realise > > that 1**(...) is automatically 1, it tries to calculate the humongous > > intermediate result, and that's what fails. > > > > For what it's worth, that last intermediate result (two to the power of > > the 489-digit number) has approximately a billion trillion trillion > > trillion trillion trillion trillion trillion trillion trillion trillion > > trillion trillion trillion trillion trillion trillion trillion trillion > > trillion trillion trillion trillion trillion trillion trillion trillion > > trillion trillion trillion trillion trillion trillion trillion trillion > > trillion trillion trillion trillion trillion trillion digits. > > > > (American billion and trillion, 10**9 and 10**12 respectively.) > > > > > > > > -- > > Steven From d at davea.name Sun Mar 31 08:43:10 2013 From: d at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 08:43:10 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: <51582F5E.6060103@davea.name> On 03/31/2013 08:07 AM, morphex wrote: > Aha, OK. Thought I found a bug but yeah that makes sense ;) > > While we're on the subject, wouldn't it be nice to have some cap there so that it isn't possible to more or less block the system with large exponentiation? > There's an assumption there. The Operating System should defend itself against starvation by any single process. Besides, there are many ways for a process to run out of memory, and exponentiation is probably the least likely of them. In general, an application cannot tell whether a particular memory allocation will succeed or not without actually trying the allocation. If it fails, you get the exception. I'm typing this while a terminal is open doing the particular operation, and the system doesn't seem in the least sluggish. Currently the memory used is at 10gig, and while there are some pauses in my typing, the system has not died. This is on Linux Ubuntu 12.04. At 15gig, there are some blockages, of maybe 5 secs each. -- DaveA From roy at panix.com Sun Mar 31 09:04:44 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 09:04:44 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: In article <8276eff6-9e5c-4060-b9e8-94fab606206f at googlegroups.com>, morphex wrote: > Aha, OK. Thought I found a bug but yeah that makes sense ;) > > While we're on the subject, wouldn't it be nice to have some cap there so > that it isn't possible to more or less block the system with large > exponentiation? Every time we think we know a good upper bound to something (i.e. "nobody will ever need more than 64k of memory"), it turns out that limit is wrong. There's great value in writing code which continues to work until it runs out of some external resource (i.e. memory, disk space, whatever). Eventually, somebody will want to do some calculation which you previously thought was absurd but turns out to be useful. I don't use Python bugnums very often, but when I do, I'm really happy they're there. From roy at panix.com Sun Mar 31 09:15:06 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 09:15:06 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: In article , Dave Angel wrote: > I'm typing this while a terminal is open doing the particular operation, > and the system doesn't seem in the least sluggish. > > Currently the memory used is at 10gig, and while there are some pauses > in my typing, the system has not died. This is on Linux Ubuntu 12.04. > > At 15gig, there are some blockages, of maybe 5 secs each. 15 gig? Feh. > $ prtstat 29937 > Process: mongod State: S (sleeping) > [...] > Memory > Vsize: 1998285 MB > RSS: 5428 MB > RSS Limit: 18446744073709 MB If I counted the digits right, that 1.9 TB. I love the RSS Limit. I'll be really impressed when somebody builds a machine with enough RAM to reach that :-) From jason.swails at gmail.com Sun Mar 31 10:03:12 2013 From: jason.swails at gmail.com (Jason Swails) Date: Sun, 31 Mar 2013 10:03:12 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: On Sun, Mar 31, 2013 at 9:15 AM, Roy Smith wrote: > > > $ prtstat 29937 > > Process: mongod State: S (sleeping) > > [...] > > Memory > > Vsize: 1998285 MB > > RSS: 5428 MB > > RSS Limit: 18446744073709 MB > > If I counted the digits right, that 1.9 TB. I love the RSS Limit. I'll > be really impressed when somebody builds a machine with enough RAM to > reach that :-) > http://www.ncsa.illinois.edu/UserInfo/Resources/Hardware/SGIAltix/TechSummary/ Look at co-compute2. The indicated memory is available as shared memory across all 512 cores. And that's nothing---it can be configured with up to 64 TB of global shared memory: http://www.sgi.com/products/servers/uv/configs.html Impressed? :) All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sun Mar 31 08:59:06 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 08:59:06 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5157e6cc$0$29974$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > For what it's worth, that last intermediate result (two to the power of > the 489-digit number) has approximately a billion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion trillion trillion > trillion trillion trillion trillion trillion trillion digits. > > (American billion and trillion, 10**9 and 10**12 respectively.) What's that in crore? From foo at email.invalid Sun Mar 31 18:06:49 2013 From: foo at email.invalid (Alex) Date: Sun, 31 Mar 2013 22:06:49 +0000 (UTC) Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: Dave Angel wrote: > On 03/31/2013 02:56 AM, morphex wrote: > > > > > 1**2 > > 1 > > > > > 1**2**3 > > 1 > > > > > 1**2**3**4 > > 1L > > > > > 1**2**3**4**5 > > Traceback (most recent call last): > > File "", line 1, in > > MemoryError > > > > > > > > > Does anyone know why this raises a MemoryError? Doesn't make sense > > to me. > > Perhaps you didn't realize that the expression will be done from > right to left. Really? The Python 3 documentation (http://docs.python.org/3/reference/expressions.html) says in section 6.14 (Evaluation order) that "Python evaluates expressions from left to right" (an exception being when evaluating assignments, in which case the RHS of the assignment is calculated first, in left-to-right order). Section 6.4 discusses the power operator specifically and does not contradict 6.14 except that the power operator uses right-to-left evaluation in the presence of unparenthesized unary operators. Neither of these two exception cases appear to apply here, so I think the OP is reasonable in expecting Python to do the operation left-to-right. Am I missing something written somewhere else in the docs? Are the docs I quoted wrong? Please help me understand the discrepancy I am perceiving here. Alex From rosuav at gmail.com Sun Mar 31 18:28:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 09:28:17 +1100 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 9:06 AM, Alex wrote: > Dave Angel wrote: > >> On 03/31/2013 02:56 AM, morphex wrote: >> > > > > 1**2 >> > 1 >> > > > > 1**2**3 >> > 1 >> > > > > 1**2**3**4 >> > 1L >> > > > > 1**2**3**4**5 >> > Traceback (most recent call last): >> > File "", line 1, in >> > MemoryError >> > > > > >> > >> > Does anyone know why this raises a MemoryError? Doesn't make sense >> > to me. >> >> Perhaps you didn't realize that the expression will be done from >> right to left. > > Really? > > The Python 3 documentation > (http://docs.python.org/3/reference/expressions.html) says in section > 6.14 (Evaluation order) that "Python evaluates expressions from left to > right" (an exception being when evaluating assignments, in which case > the RHS of the assignment is calculated first, in left-to-right order). > > Section 6.4 discusses the power operator specifically and does not > contradict 6.14 except that the power operator uses right-to-left > evaluation in the presence of unparenthesized unary operators. http://docs.python.org/3/reference/expressions.html#operator-precedence Opening paragraph, "... exponentiation, which groups from right to left". It follows the obvious expectation from mathematics. (The OP is using Python 2, but the same applies.) ChrisA From rosuav at gmail.com Sun Mar 31 18:32:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 09:32:04 +1100 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 9:28 AM, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 9:06 AM, Alex wrote: >> Really? >> >> The Python 3 documentation >> (http://docs.python.org/3/reference/expressions.html) says in section >> 6.14 (Evaluation order) that "Python evaluates expressions from left to >> right" (an exception being when evaluating assignments, in which case >> the RHS of the assignment is calculated first, in left-to-right order). >> >> Section 6.4 discusses the power operator specifically and does not >> contradict 6.14 except that the power operator uses right-to-left >> evaluation in the presence of unparenthesized unary operators. > > http://docs.python.org/3/reference/expressions.html#operator-precedence > > Opening paragraph, "... exponentiation, which groups from right to > left". It follows the obvious expectation from mathematics. (The OP is > using Python 2, but the same applies.) Though your point about 6.14 is still true. It states the order that the integers will be evaluated in. Note one of the examples given: expr1 + expr2 * (expr3 - expr4) The evaluation of the expression starts with 3 and 4, then picks up 2, then 1, but the operands themselves are evaluated left to right. ChrisA From davea at davea.name Sun Mar 31 18:34:05 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 18:34:05 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: <5158B9DD.4010506@davea.name> On 03/31/2013 06:06 PM, Alex wrote: > Dave Angel wrote: > >> On 03/31/2013 02:56 AM, morphex wrote: >>>>>> 1**2 >>> 1 >>>>>> 1**2**3 >>> 1 >>>>>> 1**2**3**4 >>> 1L >>>>>> 1**2**3**4**5 >>> Traceback (most recent call last): >>> File "", line 1, in >>> MemoryError >>>>>> >>> >>> Does anyone know why this raises a MemoryError? Doesn't make sense >>> to me. >> >> Perhaps you didn't realize that the expression will be done from >> right to left. > > Really? > > The Python 3 documentation > (http://docs.python.org/3/reference/expressions.html) says in section > 6.14 (Evaluation order) that "Python evaluates expressions from left to > right" (an exception being when evaluating assignments, in which case > the RHS of the assignment is calculated first, in left-to-right order). > > Section 6.4 discusses the power operator specifically and does not > contradict 6.14 except that the power operator uses right-to-left > evaluation in the presence of unparenthesized unary operators. > > Neither of these two exception cases appear to apply here, so I think > the OP is reasonable in expecting Python to do the operation > left-to-right. > > Am I missing something written somewhere else in the docs? Are the docs > I quoted wrong? Please help me understand the discrepancy I am > perceiving here. > > Alex > On the page you reference, in section 6.14, see the 4th entry: expr1 + expr2 * (expr3 - expr4) expr1 is evaluated before expr2, but the multiply happens before the add. Now see the following paragraph (6.15): """ The following table summarizes the operator precedences in Python, from lowest precedence (least binding) to highest precedence (most binding). Operators in the same box have the same precedence. Unless the syntax is explicitly given, operators are binary. Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right ? see section Comparisons ? and exponentiation, which groups from right to left). """ What this paragraph refers to as "grouping" is commonly called associativity in other languages. There are three different concepts here that apply whenever an expression has more than one term: 1) evaluation order is important for terms lie function calls which have side effects 2) precedence, lie where multiply will happen before add 3) associativity, where the order of operations for operators with the same precedence are done either left to right (usually), or right to left (like exponentiation) -- DaveA From foo at email.invalid Sun Mar 31 20:39:56 2013 From: foo at email.invalid (Alex) Date: Mon, 1 Apr 2013 00:39:56 +0000 (UTC) Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: Chris Angelico wrote: > > Opening paragraph, "... exponentiation, which groups from right to > left". It follows the obvious expectation from mathematics. (The OP is > using Python 2, but the same applies.) Thanks. I did miss that parenthetical comment in para 6.15, and that would have been the correct place to look, since it appears that operators are not parts of expressions, but rather separate them. Is that the "obvious expectation from mathematics," though? Given that 3 5 4 (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit more consistency with the other operators. I guess that is one of the foolish consistencies that comprise the hobgoblins of my little mind, though. From rosuav at gmail.com Sun Mar 31 20:58:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 11:58:18 +1100 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 11:39 AM, Alex wrote: > Given that > > 3 > 5 > 4 > > (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit > more consistency with the other operators. I guess that is one of the > foolish consistencies that comprise the hobgoblins of my little mind, > though. Not sure what you mean by transitive here. Certainly (4**5)**3 and 4**(5**3) are not the same value. ChrisA From nikos.gr33k at gmail.com Sun Mar 31 10:03:05 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 31 Mar 2013 07:03:05 -0700 (PDT) Subject: Python 3.2.3 and my blank page Message-ID: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> Hello all, i need some help i recently changes pythoon 2.6 code => python 3.2.3 but my script although not producing any errors now doesnt display anything else but a blank page at htp://superhost.gr can you help? I tried MySQLdb, pymysql, oursql, but nothing happens. i still get a blank page. I dont know what else to try since i see no error. can anyone suggest anything? I can even provide host:port user & pass for someone willing to take a look from the inside. From feedthetroll at gmx.de Sun Mar 31 11:47:57 2013 From: feedthetroll at gmx.de (feedthetroll at gmx.de) Date: Sun, 31 Mar 2013 08:47:57 -0700 (PDT) Subject: Python 3.2.3 and my blank page References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> Message-ID: I like to feed trolls :-) On 31 Mrz., 16:03, ????? ???33? wrote: > Hello all, Hello Ferrous Cranus [3]! > ... > I tried MySQLdb, pymysql, oursql, but nothing happens. > i still get a blank page. I dont know what else to try since i see no error. Well, the output of your cgi is: --> --> This is not valid html. Therefore the browser does not render anything. > > can anyone suggest anything? Learn html [1] and python [2], read your code. Find out, why most of your html-output does not get into the response. Solve the reasons. Done. > > I can even provide host:port user & pass for someone willing to take a look from the inside. I'm sure it depends what you are willing to pay. [Sorry, I forgot. You are looking for someone, who does your work (which you are payed for because aou are a hoster) for free.] [1] https://www.google.at/search?q=learn+html+online [2] https://www.google.at/search?q=learn+python+online [3] http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm From rurpy at yahoo.com Sun Mar 31 14:14:43 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 31 Mar 2013 11:14:43 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> Message-ID: <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> On 03/31/2013 08:03 AM, ????? ???33? wrote: > Hello all, > > i need some help > i recently changes pythoon 2.6 code => python 3.2.3 but my script although not producing any errors now doesnt display anything else but a blank page at htp://superhost.gr > can you help? > > I tried MySQLdb, pymysql, oursql, but nothing happens. > i still get a blank page. I dont know what else to try since i see no error. When I look at your page and do a "show source" in my browser it shows me the following: --> --> One obvious error is that you are writing html text before the "Content-Type: text/html" line. And whatever code is supposed to create the content is not getting run. > can anyone suggest anything? It is hard to help you because there is no code to look at. Also, I looked at your web site a couple days ago after you said you were getting a blank page, but I got a traceback page. I realize your are working on the problem and changing things but nobody wants to spend time looking for a problem, only to find out you've changed the code and their time was wasted. Also, your requests for help are spread out over multiple threads making it hard for anyone to figure out what you've already tried and what the current state of your code and problems are. I haven't used MySql so I can't offer any specific help regarding that, but I can say how I would try to attack your problem if it were my problem. First, Python 2 and Python 3 are two different languages. Code written for Python 2 will not run under Python 3 (in general) unless it is changed. So first, are you sure that the database connector (dbi module) runs under Python 3? Are you sure it is installed properly? To answer this question definitively you can write a simple Python program to import the dbi module, open a connection to your database and execute a simple query. Once you are sure you can access the database with Python 3 code, next is your cgi script code. Try running your cgi script interactively. But when you do this, remember that the environment that your script sees is different when you run it interactively than when Apache runs your script. When Apache runs your script it might be using a different userid (which can affect what files your script can open), there different environment variables (like REMOTE_HOST which will be missing when you run interactively). You can see the environment that exists when Apache is running your script by creating a cgi script like: ------------ #!/bin/env python3 import cgi, os, sys print("Content-type: text/html\n") print("""\ Python CGI Environment

    Python CGI Environment

    """) print("Python %s
    " % sys.version) print("Current directory: %s

    " % os.getcwd()) print("Environment Variables:
    ") for k in sorted(os.environ.keys()): print(" %s: %s
    " % (k, cgi.escape(os.environ[k]))) print("") ------------ Open that cgi script in your browser. You can also run it interactively and you'll see many differences with what you see in your browser. When you run your failing cgi script interactively, you can give it an argument that is the url of the cgi script. For example, if you do: cd ~me/public_html/cgi_bin/ python3 myscript.py 'http://superhost.gr/myscript.cgi' the cgi module will parse the url argument and setup the right values for the QUERY_STRING environment value that Apache would normally set up. There may be other problems resulting from the different interactive environment. If I recall, at one point you were having an error because REMOTE_ADDR was not present in the interactive environment. Perhaps the best way to deal with that is to modify your code. Foe example replace host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] with try: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] except KeyError: host = 'not available' Then your script will be able to run interactively and you can continue debugging the real problems in it. Of course there may be other issue you have to fix as well but find and fix them one at a time. Add print statements to your code to find out where things are going wrong. Don't trust your own thinking about the code! If you think a variable should be 3 at some point in the code, print it out and verify it! After you get the program to generate html that looks ok, comment out your debugging print statements (so that only html is printed), redirect the html output into a file, them open the file in your browser and see if it looks ok. If not, modify the code until it does. After you've got the script producing good output interactively see if works from Apache as cgi script. If not, it should be much easier now to find the problem since most of the other problems have been fixed. > I can even provide host:port user & pass for someone willing to take a look from the inside. Sorry, but I don't use MySql so I probably wouldn't be much help. You might consider posting (and updating when you change it!!) your code to some public place on the internet like http://pastebin.com so that anyone who wants to try helping you has some code to look at. Be sure to remove any userids and passwords in your code before posting it publicly. And please don't post it to this list because it is too big. From nikos.gr33k at gmail.com Sun Mar 31 15:12:03 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 31 Mar 2013 12:12:03 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> Message-ID: ?? ???????, 31 ??????? 2013 9:14:43 ?.?. UTC+3, ? ??????? ru... at yahoo.com ??????: > On 03/31/2013 08:03 AM, ????? ???33? wrote: > > > Hello all, > > > > > > i need some help > > > i recently changes pythoon 2.6 code => python 3.2.3 but my script although not producing any errors now doesnt display anything else but a blank page at htp://superhost.gr > > > can you help? > > > > > > I tried MySQLdb, pymysql, oursql, but nothing happens. > > > i still get a blank page. I dont know what else to try since i see no error. > > > > When I look at your page and do a "show source" in my browser > > it shows me the following: > > > > > > --> --> > > > > > > > > One obvious error is that you are writing html text before the > > "Content-Type: text/html" line. And whatever code is supposed > > to create the content is not getting run. > > > > > can anyone suggest anything? > > > > It is hard to help you because there is no code to look at. > > Also, I looked at your web site a couple days ago after you > > said you were getting a blank page, but I got a traceback > > page. I realize your are working on the problem and changing > > things but nobody wants to spend time looking for a problem, > > only to find out you've changed the code and their time was > > wasted. > > > > Also, your requests for help are spread out over multiple > > threads making it hard for anyone to figure out what you've > > already tried and what the current state of your code and > > problems are. > > > > I haven't used MySql so I can't offer any specific help regarding > > that, but I can say how I would try to attack your problem if it > > were my problem. > > > > First, Python 2 and Python 3 are two different languages. Code > > written for Python 2 will not run under Python 3 (in general) > > unless it is changed. So first, are you sure that the database > > connector (dbi module) runs under Python 3? Are you sure it is > > installed properly? > > > > To answer this question definitively you can write a simple > > Python program to import the dbi module, open a connection to > > your database and execute a simple query. > > > > Once you are sure you can access the database with Python 3 > > code, next is your cgi script code. > > > > Try running your cgi script interactively. > > > > But when you do this, remember that the environment that your > > script sees is different when you run it interactively than > > when Apache runs your script. When Apache runs your script > > it might be using a different userid (which can affect what > > files your script can open), there different environment variables > > (like REMOTE_HOST which will be missing when you run interactively). > > > > You can see the environment that exists when Apache is running > > your script by creating a cgi script like: > > > > ------------ > > #!/bin/env python3 > > import cgi, os, sys > > > > print("Content-type: text/html\n") > > print("""\ > > > PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > > > > > Python CGI Environment > > > > > > > >

    Python CGI Environment

    > > """) > > print("Python %s
    " % sys.version) > > print("Current directory: %s

    " % os.getcwd()) > > print("Environment Variables:
    ") > > for k in sorted(os.environ.keys()): > > print(" %s: %s
    " % (k, cgi.escape(os.environ[k]))) > > > > print("") > > ------------ > > > > Open that cgi script in your browser. You can also run it > > interactively and you'll see many differences with what > > you see in your browser. > > > > When you run your failing cgi script interactively, you can > > give it an argument that is the url of the cgi script. For > > example, if you do: > > > > cd ~me/public_html/cgi_bin/ > > python3 myscript.py 'http://superhost.gr/myscript.cgi' > > > > the cgi module will parse the url argument and setup the right > > values for the QUERY_STRING environment value that Apache would > > normally set up. > > > > There may be other problems resulting from the different interactive > > environment. If I recall, at one point you were having an error > > because REMOTE_ADDR was not present in the interactive environment. > > > > Perhaps the best way to deal with that is to modify your code. > > Foe example replace > > > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > > > with > > try: > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > except KeyError: > > host = 'not available' > > > > Then your script will be able to run interactively and you can > > continue debugging the real problems in it. Of course there > > may be other issue you have to fix as well but find and fix > > them one at a time. > > > > Add print statements to your code to find out where things are > > going wrong. Don't trust your own thinking about the code! > > If you think a variable should be 3 at some point in the code, > > print it out and verify it! > > > > After you get the program to generate html that looks ok, comment > > out your debugging print statements (so that only html is printed), > > redirect the html output into a file, them open the file in your > > browser and see if it looks ok. If not, modify the code until > > it does. > > > > After you've got the script producing good output interactively > > see if works from Apache as cgi script. If not, it should be > > much easier now to find the problem since most of the other > > problems have been fixed. > > > > > > > I can even provide host:port user & pass for someone willing to take a look from the inside. > > > > Sorry, but I don't use MySql so I probably wouldn't be much help. > > > > You might consider posting (and updating when you change it!!) your > > code to some public place on the internet like http://pastebin.com > > so that anyone who wants to try helping you has some code to look > > at. Be sure to remove any userids and passwords in your code > > before posting it publicly. And please don't post it to this > > list because it is too big. Firsly, thank you for your willing to help me. i wrote, uploaded an chmoded test.py and you can see the cgi enviromental table here: http://superhost.gr/cgi-bin/test.py All values seem okey, so it really isnt somehting wrong with the cgi enviroment. Also i chnagen the host line to what you suggestes so interactive prompts will not give errors. Please take a look the values to see if something not look ok and i 'am about to create another trest script to check if i can pefrom a simple mysql query with python 3.2.3 just to make sure the MySQLdb connector work ok with 3.x From rurpy at yahoo.com Sun Mar 31 15:46:57 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 31 Mar 2013 12:46:57 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> Message-ID: <31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com> On 03/31/2013 01:12 PM, ????? ???33? wrote: > Firsly, thank you for your willing to help me. i wrote, uploaded an > chmoded test.py and you can see the cgi enviromental table here: > http://superhost.gr/cgi-bin/test.py All values seem okey, so it > really isnt somehting wrong with the cgi enviroment. Also i chnagen > the host line to what you suggestes so interactive prompts will not > give errors. Please take a look the values to see if something not > look ok and i 'am about to create another trest script to check if i > can pefrom a simple mysql query with python 3.2.3 just to make sure > the MySQLdb connector work ok with 3.x I didn't mean that there was anything *wrong* with your cgi environment, only that it is *different* than your interactive environment. It is easier to debug code in an interactive environment than a cgi one so you want to do as much debugging interactively as possible,. But because the environments are different your code will behave differently. Knowing what is different between the two environments will help you know if an error is due to a real problem in your code, or is just due to the different environment. And it will help you setup your interactive environment to be as close as possible to the cgi one. From nikos.gr33k at gmail.com Sun Mar 31 16:08:59 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 31 Mar 2013 13:08:59 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> <31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com> Message-ID: <3efac1a0-ea1f-4d64-886a-9609be9babef@googlegroups.com> ?? ???????, 31 ??????? 2013 10:46:57 ?.?. UTC+3, ? ??????? ru... at yahoo.com ??????: > On 03/31/2013 01:12 PM, ????? ???33? wrote: > > > Firsly, thank you for your willing to help me. i wrote, uploaded an > > > chmoded test.py and you can see the cgi enviromental table here: > > > http://superhost.gr/cgi-bin/test.py All values seem okey, so it > > > really isnt somehting wrong with the cgi enviroment. Also i chnagen > > > the host line to what you suggestes so interactive prompts will not > > > give errors. Please take a look the values to see if something not > > > look ok and i 'am about to create another trest script to check if i > > > can pefrom a simple mysql query with python 3.2.3 just to make sure > > > the MySQLdb connector work ok with 3.x > > > > I didn't mean that there was anything *wrong* with your cgi > > environment, only that it is *different* than your interactive > > environment. > > > > It is easier to debug code in an interactive environment than a > > cgi one so you want to do as much debugging interactively as possible,. > > But because the environments are different your code will behave > > differently. Knowing what is different between the two environments > > will help you know if an error is due to a real problem in your > > code, or is just due to the different environment. And it will > > help you setup your interactive environment to be as close as > > possible to the cgi one. But i look the code and run python via interactive prompt and it says it has no error. So i don't have a clue on what i still need to try since i get no error via cmd or via browser(blank page) From rurpy at yahoo.com Sun Mar 31 16:21:21 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 31 Mar 2013 13:21:21 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <3efac1a0-ea1f-4d64-886a-9609be9babef@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> <31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com> <3efac1a0-ea1f-4d64-886a-9609be9babef@googlegroups.com> Message-ID: <3035b123-3bd3-4046-b6f0-a0e598f50cbc@googlegroups.com> On 03/31/2013 02:08 PM, ????? ???33? wrote: > But i look the code and run python via interactive prompt and it says > it has no error. Does it produce any output? Is that output the right html? That is, if you save the html to a file and open that file in a browser, does it look right? > So i don't have a clue on what i still need to try since i get no > error via cmd or via browser(blank page) I have no clue either because I don't know what output you are getting when you run the script interactively, nor do I know what the code is that you are running. From nikos.gr33k at gmail.com Sun Mar 31 16:34:51 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 31 Mar 2013 13:34:51 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <3035b123-3bd3-4046-b6f0-a0e598f50cbc@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> <31bc2bdf-ede1-4782-80e2-597f6a8ca4fc@googlegroups.com> <3efac1a0-ea1f-4d64-886a-9609be9babef@googlegroups.com> <3035b123-3bd3-4046-b6f0-a0e598f50cbc@googlegroups.com> Message-ID: <0b9712c6-6788-4a3c-9e1f-a8bccf1c76b8@googlegroups.com> ?? ???????, 31 ??????? 2013 11:21:21 ?.?. UTC+3, ? ??????? ru... at yahoo.com ??????: > On 03/31/2013 02:08 PM, ????? ???33? wrote: > > > > > But i look the code and run python via interactive prompt and it says > > > it has no error. > > > > Does it produce any output? Is that output the right html? That is, if > > you save the html to a file and open that file in a browser, does it look > > right? > > > > > So i don't have a clue on what i still need to try since i get no > > > error via cmd or via browser(blank page) > > > > I have no clue either because I don't know what output you are getting > > when you run the script interactively, nor do I know what the code is > > that you are running. I think i have mase some progress and it seems that the reason *perhaps* is encoding issues. look at http://superhost.gr now and biew its source too..... From nikos.gr33k at gmail.com Sun Mar 31 15:19:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Sun, 31 Mar 2013 12:19:57 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> Message-ID: I just tried the testmysql.py script: #!/usr/bin/python3 # coding=utf-8 import cgitb; cgitb.enable() import cgi, re, os, sys, socket, datetime, MySQLdb, locale, random, subprocess # connect to database con = MySQLdb.connect( db = 'nikos_metrites', host = 'localhost', user = 'nikos_nikos', passwd = 'tiabhp2r#', init_command='SET NAMES UTF8' ) cur = con.cursor() print ( "Content-type: text/html; charset=utf-8\n" ) # ================================================================================================================= # if extra string is attached to the URL is 'log' then show explicit page log and exit # ================================================================================================================= cur.execute('''SELECT hits FROM counters''') data = cur.fetchall() #URL is unique, so should only be one for item in data: print( item ) =================== it works, as you can see at: http://superhost.gr/cgi-bin/testmysql.py so MySQLdb mpodule does work for Python3 !!!!! so mysql connector is not the problem. but hwta is it then i get no errors!! From rurpy at yahoo.com Sun Mar 31 16:10:26 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 31 Mar 2013 13:10:26 -0700 (PDT) Subject: Python 3.2.3 and my blank page In-Reply-To: References: <18a3faa7-8571-44e3-a5b3-3651493549ed@googlegroups.com> <1093d5f3-4fac-4a2f-9f16-87df97498afe@googlegroups.com> Message-ID: <6ab68a12-d164-45e0-8ac9-2ba2c60d0463@googlegroups.com> On 03/31/2013 01:19 PM, ????? ???33? wrote: > I just tried the testmysql.py script: >[...snip code...] I hope no one who reads this list also has access to your database and that you don't use that username/password anyplace else. > it works, as you can see at: > http://superhost.gr/cgi-bin/testmysql.py > so MySQLdb mpodule does work for Python3 !!!!! > so mysql connector is not the problem. > but hwta is it then i get no errors!! Get no errors from what? The original script you were having trouble with? Are you running it by using your browser or from interactively in a terminal window? I probably should have asked this before, but can do you have shell access to the script? Can you run it interactively in a terminal window? From maccten2000 at hotmail.com Sun Mar 31 10:53:14 2013 From: maccten2000 at hotmail.com (Steve B) Date: Sun, 31 Mar 2013 16:53:14 +0200 Subject: Convert Latitude, Longitude To TimeZone Message-ID: Hi All I'm new to python (4 days J) and was wondering if anyone out there can help me I am trying to get the time zones for latitude and longitude coordinates but am having a few problems The mistakes are probably very basic I have a table in a database with around 600 rows. Each row contains a lat long coordinate for somewhere in the world I want to feed these co-ordinates into a function and then retrieve the time zone. The aim being to convert events which have a local time stamp within each of these 600 places into UTC time I found a piece of code [http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html ] which uses the function [https://gist.github.com/pamelafox/2288222] When I try to run the code, I get the error geonames is not defined (This is the function previously linked to) I have applied for an account with geonames, I think I have just saved the function file in the wrong directory or something simple. Can anyone help #--------------------------------------------------------------------------- ---- # Converts latitude longitude into a time zone # REF: https://gist.github.com/pamelafox/2288222 # REF: http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html #--------------------------------------------------------------------------- ---- geonames_client = geonames.GeonamesClient('Username_alpha') geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng': 2.77928}) user.timezone = geonames_result['timezoneId'] Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sun Mar 31 11:09:14 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 11:09:14 -0400 Subject: Convert Latitude, Longitude To TimeZone References: Message-ID: In article , Steve B wrote: > I found a piece of code > [http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html > ] which uses the function [https://gist.github.com/pamelafox/2288222] > > When I try to run the code, I get the error geonames is not defined (This is > the function previously linked to) The best thing to do when asking questions like this is to copy-paste the exact error message you got. It was probably something like: Traceback (most recent call last): File "", line 1, in NameError: name 'geonames' is not defined In this example, it's easy enough to figure out what went wrong from your description, but in general, giving the exact error helps in the diagnosis. > geonames_client = geonames.GeonamesClient('Username_alpha') > > geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng': > 2.77928}) > > user.timezone = geonames_result['timezoneId'] You simply never imported the geonames module. Somewhere before your first line of code, you want to add: import geonames This assumes that you've saved the module in a file named "geonames.py". From love_ram2010 at yahoo.com Sun Mar 31 11:45:56 2013 From: love_ram2010 at yahoo.com (saddd) Date: Sun, 31 Mar 2013 08:45:56 -0700 (PDT) Subject: A Healthy Alternative to Takeaway Regret Message-ID: <176fa0a3-976a-42c7-a7c1-76e27746ee89@fn10g2000vbb.googlegroups.com> A Healthy Alternative to Takeaway Regret http://natigtas7ab.blogspot.com/2013/03/a-healthy-alternative-to-takeaway-regret.html From swilks06 at gmail.com Sun Mar 31 11:52:50 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 08:52:50 -0700 (PDT) Subject: Creating a dictionary from a .txt file Message-ID: Hello, I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: 1958 MGA Twin Cam 1958 Zunndapp Janus 1961 Amphicar 1961 Corvair 1966 Peel Trident 1970 AMC Gremlin 1970 Triumph Stag 1971 Chrysler Imperial LeBaron Two-Door Hardtop The car manufacturer should be the key and a tuple containing the year and the model should be the key's value. I tried the following to just get the contents of the file into a list, but only the very last line in the txt file is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I print temp. d={} car_file = open('worstcars.txt', 'r') for line in car_file: temp = line.split() print (temp) car_file.close() After playing around with the code, I came up with the following code to get everything into a list: d=[] car_file = open('worstcars.txt', 'r') for line in car_file: d.append(line.strip('\n')) print (d) car_file.close() Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Here is a sample of what list d looks like: ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', '2003 Hummer H2', '2004 Chevy SSR'] Any help would be appreciated! From rosuav at gmail.com Sun Mar 31 12:06:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 03:06:18 +1100 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Mon, Apr 1, 2013 at 2:52 AM, C.T. wrote: > After playing around with the code, I came up with the following code to get everything into a list: > > d=[] > car_file = open('worstcars.txt', 'r') > for line in car_file: > d.append(line.strip('\n')) > print (d) > car_file.close() > > Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Ah, a nice straight-forward text parsing problem! The question is how to recognize the manufacturer. Is it guaranteed to be the second blank-delimited word, with the year being the first? If so, you were almost there with .split(). car_file = open('worstcars.txt', 'r') # You may want to consider the 'with' statement here - no need to close() for line in car_file: temp = line.split(None, 2) if len(temp)==3: year, mfg, model = temp # Now do something with these three values print("Manufacturer: %s Year: %s Model: %s"%(mfg,year,model)) That's sorted out the parsing side of things. Do you know how to build up the dictionary from there? What happens if there are multiple entries in the file for the same manufacturer? Do you need to handle that? ChrisA From dreamingforward at gmail.com Sun Mar 31 12:20:25 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 31 Mar 2013 09:20:25 -0700 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: > > Every line is now an element in list d. The question I have now is how can > I make a dictionary out of the list d with the car manufacturer as the key > and a tuple containing the year and the model should be the key's value. > Here is a sample of what list d looks like: > > ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', > '2003 Hummer H2', '2004 Chevy SSR'] > > Any help would be appreciated! > > As long as your data is consistently ordered, just use list indexing. d[2] is your key, and (d[1],d[3]) the key's value. Mark Tacoma, Washington -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Sun Mar 31 12:38:56 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 12:38:56 -0400 Subject: Creating a dictionary from a .txt file References: Message-ID: In article , "C.T." wrote: > Hello, > > I'm currently working on a homework problem that requires me to create a > dictionary from a .txt file that contains some of the worst cars ever made. > The file looks something like this: > > 1958 MGA Twin Cam > 1958 Zunndapp Janus > 1961 Amphicar > 1961 Corvair > 1966 Peel Trident > 1970 AMC Gremlin > 1970 Triumph Stag > 1971 Chrysler Imperial LeBaron Two-Door Hardtop > > The car manufacturer should be the key and a tuple containing the year and > the model should be the key's value. I tried the following to just get the > contents of the file into a list, but only the very last line in the txt file > is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I > print temp. > > d={} > car_file = open('worstcars.txt', 'r') > for line in car_file: > temp = line.split() > print (temp) > car_file.close() Yup. Because you run through the whole file, putting each line into temp, overwriting the previous temp value. > d=[] > car_file = open('worstcars.txt', 'r') > for line in car_file: > d.append(line.strip('\n')) > print (d) > car_file.close() You could do most of that with just: car_file = open('worstcars.txt', 'r') d = car_file.readlines() but there's no real reason to read the whole file into a list. What you probably want to do is something like: d = {} car_file = open('worstcars.txt', 'r') for line in car_file: year, manufacturer, model = parse_line(line) d[manufacturer] = (year, model) One comment about the above; it assumes that there's only a single entry for a given manufacturer in the file. If that's not true, the above code will only keep the last one. But let's assume it's true for the moment. Now, we're just down to writing parse_line(). This takes a string and breaks it up into 3 strings. I'm going to leave this as an exercise for you to work out. The complicated part is going to be figuring out some logic to deal with anything from multi-word model names ("Imperial LeBaron Two-Door Hardtop"), to lines like the Corvair where there is no manufacturer (or maybe there's no model?). From swilks06 at gmail.com Sun Mar 31 13:28:40 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 10:28:40 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Sunday, March 31, 2013 12:38:56 PM UTC-4, Roy Smith wrote: > In article , > > "C.T." wrote: > > > > > Hello, > > > > > > I'm currently working on a homework problem that requires me to create a > > > dictionary from a .txt file that contains some of the worst cars ever made. > > > The file looks something like this: > > > > > > 1958 MGA Twin Cam > > > 1958 Zunndapp Janus > > > 1961 Amphicar > > > 1961 Corvair > > > 1966 Peel Trident > > > 1970 AMC Gremlin > > > 1970 Triumph Stag > > > 1971 Chrysler Imperial LeBaron Two-Door Hardtop > > > > > > The car manufacturer should be the key and a tuple containing the year and > > > the model should be the key's value. I tried the following to just get the > > > contents of the file into a list, but only the very last line in the txt file > > > is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I > > > print temp. > > > > > > d={} > > > car_file = open('worstcars.txt', 'r') > > > for line in car_file: > > > temp = line.split() > > > print (temp) > > > car_file.close() > > > > Yup. Because you run through the whole file, putting each line into > > temp, overwriting the previous temp value. > > > > > d=[] > > > car_file = open('worstcars.txt', 'r') > > > for line in car_file: > > > d.append(line.strip('\n')) > > > print (d) > > > car_file.close() > > > > You could do most of that with just: > > > > car_file = open('worstcars.txt', 'r') > > d = car_file.readlines() > > > > but there's no real reason to read the whole file into a list. What you > > probably want to do is something like: > > > > d = {} > > car_file = open('worstcars.txt', 'r') > > for line in car_file: > > year, manufacturer, model = parse_line(line) > > d[manufacturer] = (year, model) > > > > One comment about the above; it assumes that there's only a single entry > > for a given manufacturer in the file. If that's not true, the above > > code will only keep the last one. But let's assume it's true for the > > moment. > > > > Now, we're just down to writing parse_line(). This takes a string and > > breaks it up into 3 strings. I'm going to leave this as an exercise for > > you to work out. The complicated part is going to be figuring out some > > logic to deal with anything from multi-word model names ("Imperial > > LeBaron Two-Door Hardtop"), to lines like the Corvair where there is no > > manufacturer (or maybe there's no model?). Roy, thank you so much! I'll do some more research to see how I can achieve this. Thank you! From swilks06 at gmail.com Sun Mar 31 12:52:50 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 09:52:50 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: > Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Here is a sample of what list d looks like: > > > > > ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', '2003 Hummer H2', '2004 Chevy SSR'] > > > > Any help would be appreciated! > > > > > As long as your data is consistently ordered, just use list indexing. ?d[2] is your key, and (d[1],d[3]) the key's value. > > > > Mark > Tacoma, Washington Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year into a tuple, but because a car manufacturer could have two names (ie, Aston Martin) or a car model could have two names(ie, Iron Duke), its harder to use slicing and indexing for those two. I've added the following, but the output is still not what I need it to be. t={} for i in d : t[d[d.index(i)][5:]]= tuple(d[d.index(i)][:4]) print (t) The output looks something like this: {'Ford Model T': ('1', '9', '0', '9'), 'Mosler Consulier GTP': ('1', '9', '8', '5'), 'Scripps-Booth Bi-Autogo': ('1', '9', '1', '3'), 'Morgan Plus 8 Propane': ('1', '9', '7', '5'), 'Fiat Multipla': ('1', '9', '9', '8'), 'Ford Pinto': ('1', '9', '7', '1'), 'Triumph Stag': ('1', '9', '7', '0'), 'BMW 7-series': ('2', '0', '0', '2')} Here the key is the car manufacturer and car model and the value is a tuple containing the year separated by a comma.( Not sure why that is ?) From swilks06 at gmail.com Sun Mar 31 12:52:50 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 09:52:50 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: > Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. Here is a sample of what list d looks like: > > > > > ['1899 Horsey Horseless', '1909 Ford Model T', '1911 Overland OctoAuto', '2003 Hummer H2', '2004 Chevy SSR'] > > > > Any help would be appreciated! > > > > > As long as your data is consistently ordered, just use list indexing. ?d[2] is your key, and (d[1],d[3]) the key's value. > > > > Mark > Tacoma, Washington Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year into a tuple, but because a car manufacturer could have two names (ie, Aston Martin) or a car model could have two names(ie, Iron Duke), its harder to use slicing and indexing for those two. I've added the following, but the output is still not what I need it to be. t={} for i in d : t[d[d.index(i)][5:]]= tuple(d[d.index(i)][:4]) print (t) The output looks something like this: {'Ford Model T': ('1', '9', '0', '9'), 'Mosler Consulier GTP': ('1', '9', '8', '5'), 'Scripps-Booth Bi-Autogo': ('1', '9', '1', '3'), 'Morgan Plus 8 Propane': ('1', '9', '7', '5'), 'Fiat Multipla': ('1', '9', '9', '8'), 'Ford Pinto': ('1', '9', '7', '1'), 'Triumph Stag': ('1', '9', '7', '0'), 'BMW 7-series': ('2', '0', '0', '2')} Here the key is the car manufacturer and car model and the value is a tuple containing the year separated by a comma.( Not sure why that is ?) From davea at davea.name Sun Mar 31 13:31:36 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 13:31:36 -0400 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: <515872F8.3040804@davea.name> On 03/31/2013 12:52 PM, C.T. wrote: > On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: >> >> > > Thank you, Mark! My problem is the data isn't consistently ordered. I can use slicing and indexing to put the year into a tuple, but because a car manufacturer could have two names (ie, Aston Martin) or a car model could have two names(ie, Iron Duke), its harder to use slicing and indexing for those two. I've added the following, but the output is still not what I need it to be. > > So the correct answer is "it cannot be done," and an explanation. Many times I've been given impossible conditions for a problem. And invariably the correct solution is to press bac on the supplier of the constraints. Unless there are some invisible characters in that file, lie tabs in between the fields, it loocs liec you're out of luc. Or you could manually edit the file before running the program. [The character after 'j' is broccen on this cceyboard.] -- DaveA From roy at panix.com Sun Mar 31 14:41:41 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 14:41:41 -0400 Subject: Creating a dictionary from a .txt file References: Message-ID: In article , Dave Angel wrote: > On 03/31/2013 12:52 PM, C.T. wrote: > > On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: > >> > >> > > > > Thank you, Mark! My problem is the data isn't consistently ordered. I can > > use slicing and indexing to put the year into a tuple, but because a car > > manufacturer could have two names (ie, Aston Martin) or a car model could > > have two names(ie, Iron Duke), its harder to use slicing and indexing for > > those two. I've added the following, but the output is still not what I > > need it to be. > > So the correct answer is "it cannot be done," and an explanation. > > Many times I've been given impossible conditions for a problem. And > invariably the correct solution is to press [back] on the supplier of the > constraints. In real life, you often have to deal with crappy input data (and bogus project requirements). Sometimes you just need to be creative. There's only a small set of car manufacturers. A good start would be mining wikipedia's [[List of automobile manufacturers]]. Once you've got that list, you could try matching portions of the input against the list. Depending on how much effort you wanted to put into this, you could explore all sorts of fuzzy matching (ie "delorean" vs "delorean motor company"), but even a simple search is better than giving up. And, this is a good excuse to explore some of the interesting third-party modules. For example, mwclient ("pip install mwclient") gives you a neat Python interface to wikipedia. And there's a whole landscape of string matching packages to explore. We deal with this every day at Songza. Are Kesha and Ke$ha the same artist? Pushing back on the record labels to clean up their catalogs isn't going to get us very far. From davea at davea.name Sun Mar 31 17:37:33 2013 From: davea at davea.name (Dave Angel) Date: Sun, 31 Mar 2013 17:37:33 -0400 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: <5158AC9D.7040407@davea.name> On 03/31/2013 02:41 PM, Roy Smith wrote: > In article , > Dave Angel wrote: > >> On 03/31/2013 12:52 PM, C.T. wrote: >>> On Sunday, March 31, 2013 12:20:25 PM UTC-4, zipher wrote: >>>> >>>> >>> >>> Thank you, Mark! My problem is the data isn't consistently ordered. I can >>> use slicing and indexing to put the year into a tuple, but because a car >>> manufacturer could have two names (ie, Aston Martin) or a car model could >>> have two names(ie, Iron Duke), its harder to use slicing and indexing for >>> those two. I've added the following, but the output is still not what I >>> need it to be. >> >> So the correct answer is "it cannot be done," and an explanation. >> >> Many times I've been given impossible conditions for a problem. And >> invariably the correct solution is to press [back] on the supplier of the >> constraints. > > In real life, you often have to deal with crappy input data (and bogus > project requirements). Sometimes you just need to be creative. > > There's only a small set of car manufacturers. A good start would be > mining wikipedia's [[List of automobile manufacturers]]. Once you've > got that list, you could try matching portions of the input against the > list. > > Depending on how much effort you wanted to put into this, you could > explore all sorts of fuzzy matching (ie "delorean" vs "delorean motor > company"), but even a simple search is better than giving up. > > And, this is a good excuse to explore some of the interesting > third-party modules. For example, mwclient ("pip install mwclient") > gives you a neat Python interface to wikipedia. And there's a whole > landscape of string matching packages to explore. > > We deal with this every day at Songza. Are Kesha and Ke$ha the same > artist? Pushing back on the record labels to clean up their catalogs > isn't going to get us very far. > I agree with everything you've said, although in your case, presumably the record labels are not your client/boss, so that's not who you push back against. The client should know when the data is being fudged, and have a say in how it's to be done. But this is a homework assignment. I think the OP is learning Python, not how to second-guess a client. -- DaveA From swilks06 at gmail.com Sun Mar 31 13:19:57 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 10:19:57 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Sunday, March 31, 2013 12:06:18 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 2:52 AM, C.T. > > > After playing around with the code, I came up with the following code to get everything into a list: > > > > > > d=[] > > > car_file = open('worstcars.txt', 'r') > > > for line in car_file: > > > d.append(line.strip('\n')) > > > print (d) > > > car_file.close() > > > > > > Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. > > > > Ah, a nice straight-forward text parsing problem! > > > > The question is how to recognize the manufacturer. Is it guaranteed to > > be the second blank-delimited word, with the year being the first? If > > so, you were almost there with .split(). > > > > car_file = open('worstcars.txt', 'r') > > # You may want to consider the 'with' statement here - no need to close() > > for line in car_file: > > temp = line.split(None, 2) > > if len(temp)==3: > > year, mfg, model = temp > > # Now do something with these three values > > print("Manufacturer: %s Year: %s Model: %s"%(mfg,year,model)) > > > > That's sorted out the parsing side of things. Do you know how to build > > up the dictionary from there? > > > > What happens if there are multiple entries in the file for the same > > manufacturer? Do you need to handle that? > > > > ChrisA Thank you, Chris! I could use slicing and indexing to build the dictionary but the problem is with the car manufacturer an the car model. Either or both could be multiple names. From swilks06 at gmail.com Sun Mar 31 13:19:57 2013 From: swilks06 at gmail.com (C.T.) Date: Sun, 31 Mar 2013 10:19:57 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Sunday, March 31, 2013 12:06:18 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 2:52 AM, C.T. > > > After playing around with the code, I came up with the following code to get everything into a list: > > > > > > d=[] > > > car_file = open('worstcars.txt', 'r') > > > for line in car_file: > > > d.append(line.strip('\n')) > > > print (d) > > > car_file.close() > > > > > > Every line is now an element in list d. The question I have now is how can I make a dictionary out of the list d with the car manufacturer as the key and a tuple containing the year and the model should be the key's value. > > > > Ah, a nice straight-forward text parsing problem! > > > > The question is how to recognize the manufacturer. Is it guaranteed to > > be the second blank-delimited word, with the year being the first? If > > so, you were almost there with .split(). > > > > car_file = open('worstcars.txt', 'r') > > # You may want to consider the 'with' statement here - no need to close() > > for line in car_file: > > temp = line.split(None, 2) > > if len(temp)==3: > > year, mfg, model = temp > > # Now do something with these three values > > print("Manufacturer: %s Year: %s Model: %s"%(mfg,year,model)) > > > > That's sorted out the parsing side of things. Do you know how to build > > up the dictionary from there? > > > > What happens if there are multiple entries in the file for the same > > manufacturer? Do you need to handle that? > > > > ChrisA Thank you, Chris! I could use slicing and indexing to build the dictionary but the problem is with the car manufacturer an the car model. Either or both could be multiple names. From rosuav at gmail.com Sun Mar 31 13:22:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 04:22:44 +1100 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On Mon, Apr 1, 2013 at 4:19 AM, C.T. wrote: > Thank you, Chris! I could use slicing and indexing to build the dictionary but the problem is with the car manufacturer an the car model. Either or both could be multiple names. Then you're going to need some other form of magic to recognize where the manufacturer ends and the model starts. Do you have, say, tabs between the fields and spaces within? ChrisA From tjreedy at udel.edu Sun Mar 31 15:04:54 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sun, 31 Mar 2013 15:04:54 -0400 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: On 3/31/2013 11:52 AM, C.T. wrote: > Hello, > > I'm currently working on a homework problem that requires me to create a dictionary from a .txt file that contains some of the worst cars ever made. The file looks something like this: > > 1958 MGA Twin Cam > 1958 Zunndapp Janus > 1961 Amphicar > 1961 Corvair > 1966 Peel Trident > 1970 AMC Gremlin > 1970 Triumph Stag > 1971 Chrysler Imperial LeBaron Two-Door Hardtop > > The car manufacturer should be the key and a tuple containing the year and the model should be the key's value. I tried the following to just get the contents of the file into a list, but only the very last line in the txt file is shown as a list with three elements (ie, ['2004', 'Chevy', 'SSR']) when I print temp. > > d={} > car_file = open('worstcars.txt', 'r') > for line in car_file: > temp = line.split() If all makers are one word (Austen-Martin would be ok, and if the file is otherwise consistently year maker model words, then adding 'maxsplit=3' to the split call would be all the parsing you need. From bjruth at gmail.com Sun Mar 31 13:57:08 2013 From: bjruth at gmail.com (Byron Ruth) Date: Sun, 31 Mar 2013 10:57:08 -0700 (PDT) Subject: collections.Iterator __subclasshook__ does not check if next() is callable Message-ID: I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. Consider: ```python class A(object): def __init__(self): self.r = iter(range(5)) def __iter__(self): return self @property def next(self): return next(self.r) ``` The `next` method is a property, however: ```python from collections import Iterator a = A() isinstance(a, Iterator) # True next(a) # TypeError: 'int' object is not callable ``` I am using `collections.Iterator` as the means to check if the object is an iterator, however I am not sure if that is _root_ problem here. My understanding of the iterator protocol is that is assumes the __iter__ and next *methods* are implemented. In the example, `A.next` is defined as a property, but is still identified as an iterator. To me, this is incorrect behavior since it's not conforming to the iterator protocol requirements (i.e. a `next` method, not a property). Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." I think I understand _why_ this is the case.. but I downstream libraries use `collections.Iterator` to determine if an object _is one_: see https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 Who's job is it to check if `next` (and technically `__iter__`) are methods? From bjruth at gmail.com Sun Mar 31 15:44:09 2013 From: bjruth at gmail.com (Byron Ruth) Date: Sun, 31 Mar 2013 12:44:09 -0700 (PDT) Subject: collections.Iterator __subclasshook__ does not check if next() is callable In-Reply-To: References: Message-ID: <7c0fe05a-e28f-4e43-bb3b-5a3903c9cb6f@googlegroups.com> Raymond's replied to my follow-up and made me realize that the `next` property could return a callable and it would be transparent to the caller. On Sunday, March 31, 2013 1:57:08 PM UTC-4, Byron Ruth wrote: > I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. > > > > Consider: > > > > ```python > > class A(object): > > def __init__(self): > > self.r = iter(range(5)) > > def __iter__(self): > > return self > > @property > > def next(self): > > return next(self.r) > > ``` > > > > The `next` method is a property, however: > > > > ```python > > from collections import Iterator > > a = A() > > isinstance(a, Iterator) # True > > next(a) # TypeError: 'int' object is not callable > > ``` > > > > I am using `collections.Iterator` as the means to check if the object is an iterator, however I am not sure if that is _root_ problem here. My understanding of the iterator protocol is that is assumes the __iter__ and next *methods* are implemented. In the example, `A.next` is defined as a property, but is still identified as an iterator. To me, this is incorrect behavior since it's not conforming to the iterator protocol requirements (i.e. a `next` method, not a property). > > > > Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." I think I understand _why_ this is the case.. but I downstream libraries use `collections.Iterator` to determine if an object _is one_: see https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 > > > > Who's job is it to check if `next` (and technically `__iter__`) are methods? From tjreedy at udel.edu Sun Mar 31 15:47:07 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sun, 31 Mar 2013 15:47:07 -0400 Subject: collections.Iterator __subclasshook__ does not check if next() is callable In-Reply-To: References: Message-ID: On 3/31/2013 1:57 PM, Byron Ruth wrote: > I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. > > Consider: > > ```python > class A(object): > def __init__(self): > self.r = iter(range(5)) > def __iter__(self): > return self > @property > def next(self): > return next(self.r) > ``` > > The `next` method is a property, however: A competent Python programmer should not do that. In Py3, the method is properly renamed '__next__', which should make doing that accidentally even less likely. > > ```python > from collections import Iterator > a = A() > isinstance(a, Iterator) # True > next(a) # TypeError: 'int' object is not callable > ``` > > I am using `collections.Iterator` as the means to check if the object is an iterator, Being an Iterator only means that it *might* be an iterator. > however I am not sure if that is _root_ problem here. My understanding of the iterator protocol is that is assumes the __iter__ and next *methods* are implemented. In the example, `A.next` is defined as a property, but is still identified as an iterator. To me, this is incorrect behavior since it's not conforming to the iterator protocol requirements (i.e. a `next` method, not a property). There is more to any protocol than can be statically checked. > Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." Having the required attributes is currently the definition of being an instance of an ABC. Adding 'not a property' would be possible. but hardly worthwhile. Checking signatures would be worthwhile, but signatures are not yet available to Python for C-coded methods, let alone other implementations. I think I understand _why_ this is the case.. but I downstream libraries use `collections.Iterator` to determine if an object _is one_: see https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 > > Who's job is it to check if `next` (and technically `__iter__`) are methods? The programmer, and a user who does not trust the competence of the programmer. But this is the least of the possible errors. -- Terry Jan Reedy From bjruth at gmail.com Sun Mar 31 15:58:15 2013 From: bjruth at gmail.com (Byron Ruth) Date: Sun, 31 Mar 2013 12:58:15 -0700 (PDT) Subject: collections.Iterator __subclasshook__ does not check if next() is callable In-Reply-To: References: Message-ID: <3176fb72-afb3-454d-9553-37e42997e32d@googlegroups.com> Thanks for responding Terry. I can assure you I did not initially realize both the `next` and the `__iter__` methods were implemented when I ran into my original problem. I saw a behavior and had to work backwards to realize why it was behaving the way it was (the comparison against Iterator). Once I realized this, the behavior made complete sense. It just dawned on me the fact that `next` was not being checked to be callable (I was surprised by this at the time) which is why I investigated the `Iterator.__subclasshook__` and assumed it was behaving incorrectly based on my assumptions. On Sunday, March 31, 2013 3:47:07 PM UTC-4, Terry Jan Reedy wrote: > On 3/31/2013 1:57 PM, Byron Ruth wrote: > > > I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. > > > > > > Consider: > > > > > > ```python > > > class A(object): > > > def __init__(self): > > > self.r = iter(range(5)) > > > def __iter__(self): > > > return self > > > @property > > > def next(self): > > > return next(self.r) > > > ``` > > > > > > The `next` method is a property, however: > > > > A competent Python programmer should not do that. In Py3, the method is > > properly renamed '__next__', which should make doing that accidentally > > even less likely. > > > > > > > > ```python > > > from collections import Iterator > > > a = A() > > > isinstance(a, Iterator) # True > > > next(a) # TypeError: 'int' object is not callable > > > ``` > > > > > > I am using `collections.Iterator` as the means to check if the object is an iterator, > > > > Being an Iterator only means that it *might* be an iterator. > > > > > however I am not sure if that is _root_ problem here. My > > understanding of the iterator protocol is that is assumes the __iter__ > > and next *methods* are implemented. In the example, `A.next` is defined > > as a property, but is still identified as an iterator. To me, this is > > incorrect behavior since it's not conforming to the iterator protocol > > requirements (i.e. a `next` method, not a property). > > > > There is more to any protocol than can be statically checked. > > > > > Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." > > > > Having the required attributes is currently the definition of being an > > instance of an ABC. Adding 'not a property' would be possible. but > > hardly worthwhile. Checking signatures would be worthwhile, but > > signatures are not yet available to Python for C-coded methods, let > > alone other implementations. > > > > I think I understand _why_ this is the case.. but I downstream > > libraries use `collections.Iterator` to determine if an object _is one_: > > see > > https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 > > > > > > Who's job is it to check if `next` (and technically `__iter__`) are methods? > > > > The programmer, and a user who does not trust the competence of the > > programmer. But this is the least of the possible errors. > > > > -- > > Terry Jan Reedy From bjruth at gmail.com Sun Mar 31 15:58:15 2013 From: bjruth at gmail.com (Byron Ruth) Date: Sun, 31 Mar 2013 12:58:15 -0700 (PDT) Subject: collections.Iterator __subclasshook__ does not check if next() is callable In-Reply-To: References: Message-ID: <3176fb72-afb3-454d-9553-37e42997e32d@googlegroups.com> Thanks for responding Terry. I can assure you I did not initially realize both the `next` and the `__iter__` methods were implemented when I ran into my original problem. I saw a behavior and had to work backwards to realize why it was behaving the way it was (the comparison against Iterator). Once I realized this, the behavior made complete sense. It just dawned on me the fact that `next` was not being checked to be callable (I was surprised by this at the time) which is why I investigated the `Iterator.__subclasshook__` and assumed it was behaving incorrectly based on my assumptions. On Sunday, March 31, 2013 3:47:07 PM UTC-4, Terry Jan Reedy wrote: > On 3/31/2013 1:57 PM, Byron Ruth wrote: > > > I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. > > > > > > Consider: > > > > > > ```python > > > class A(object): > > > def __init__(self): > > > self.r = iter(range(5)) > > > def __iter__(self): > > > return self > > > @property > > > def next(self): > > > return next(self.r) > > > ``` > > > > > > The `next` method is a property, however: > > > > A competent Python programmer should not do that. In Py3, the method is > > properly renamed '__next__', which should make doing that accidentally > > even less likely. > > > > > > > > ```python > > > from collections import Iterator > > > a = A() > > > isinstance(a, Iterator) # True > > > next(a) # TypeError: 'int' object is not callable > > > ``` > > > > > > I am using `collections.Iterator` as the means to check if the object is an iterator, > > > > Being an Iterator only means that it *might* be an iterator. > > > > > however I am not sure if that is _root_ problem here. My > > understanding of the iterator protocol is that is assumes the __iter__ > > and next *methods* are implemented. In the example, `A.next` is defined > > as a property, but is still identified as an iterator. To me, this is > > incorrect behavior since it's not conforming to the iterator protocol > > requirements (i.e. a `next` method, not a property). > > > > There is more to any protocol than can be statically checked. > > > > > Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." > > > > Having the required attributes is currently the definition of being an > > instance of an ABC. Adding 'not a property' would be possible. but > > hardly worthwhile. Checking signatures would be worthwhile, but > > signatures are not yet available to Python for C-coded methods, let > > alone other implementations. > > > > I think I understand _why_ this is the case.. but I downstream > > libraries use `collections.Iterator` to determine if an object _is one_: > > see > > https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 > > > > > > Who's job is it to check if `next` (and technically `__iter__`) are methods? > > > > The programmer, and a user who does not trust the competence of the > > programmer. But this is the least of the possible errors. > > > > -- > > Terry Jan Reedy From ethan at stoneleaf.us Sun Mar 31 20:02:18 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 31 Mar 2013 17:02:18 -0700 Subject: collections.Iterator __subclasshook__ does not check if next() is callable In-Reply-To: References: Message-ID: <5158CE8A.8080101@stoneleaf.us> On 03/31/2013 10:57 AM, Byron Ruth wrote: > I submitted this as bug last night: http://bugs.python.org/issue17584 and was *honored* to be rejected by Raymond Hettinger. However, I would like feedback on whether my concern (this bug) is justified and clarity if not. > > Consider: > > ```python > class A(object): > def __init__(self): > self.r = iter(range(5)) > def __iter__(self): > return self > @property > def next(self): > return next(self.r) > ``` > > The `next` method is a property, however: > > ```python > from collections import Iterator > a = A() > isinstance(a, Iterator) # True > next(a) # TypeError: 'int' object is not callable > ``` > > I am using `collections.Iterator` as the means to check if the object is an iterator, however I am not sure if that is _root_ problem here. My understanding of the iterator protocol is that is assumes the __iter__ and next *methods* are implemented. In the example, `A.next` is defined as a property, but is still identified as an iterator. To me, this is incorrect behavior since it's not conforming to the iterator protocol requirements (i.e. a `next` method, not a property). The root problem is that whoever implemented A did so incorrectly. > Raymond stated: "The design of ABCs are to check for the existence to required named; none of them verify the signature." I think I understand _why_ this is the case.. but I downstream libraries use `collections.Iterator` to determine if an object _is one_: see https://github.com/django/django/blob/master/django/utils/itercompat.py#L22-L31 > > Who's job is it to check if `next` (and technically `__iter__`) are methods? The programmer who wrote it, with good tests. Technically, the issue is not that 'next' is a property, but that it is not returning a callable. If it did (and the callable was appropriate for the iterator), that would also work. -- ~Ethan~ From forman.simon at gmail.com Sun Mar 31 14:55:29 2013 From: forman.simon at gmail.com (forman.simon at gmail.com) Date: Sun, 31 Mar 2013 11:55:29 -0700 (PDT) Subject: "Laws of Form" are a notation for the SK calculus, demo in Python. Message-ID: <534fdb1d-1b0f-49bf-8443-0312277c35e7@googlegroups.com> I was investigating G. Spencer-Brown's Laws of Form[1] by implementing it in Python. You can represent the "marks" of LoF as datastructures in Python composed entirely of tuples. For example: A mark: () A mark next to a mark: (), () A mark within a mark: ((),) and so on... It is known that the propositional calculus can be represented by the "arithmetic of the mark". The two rules suffice: ((),) == nothing () == (), () There are details, but essentially math and logic can be derived from the behaviour of "the mark". After reading "Every Bit Counts"[2] I spent some time trying to come up with an EBC coding for the circle language (Laws of Form expressed as tuples, See Burnett-Stuart's "The Markable Mark"[3]) With a little skull-sweat I found the following encoding: For the empty state (no mark) write '0'. Start at the left, if you encounter a boundary (one "side" of a mark, or the left, opening, parenthesis) write a '1'. Repeat for the contents of the mark, then the neighbors. _ -> 0 () -> 100 (), () -> 10100 ((),) -> 11000 and so on... I recognized these numbers as the patterns of the language called 'Iota'.[4] Briefly, the SK combinators: S = ?x.?y.?z.xz(yz) K = ?x.?y.x Or, in Python: S = lambda x: lambda y: lambda z: x(z)(y(z)) K = lambda x: lambda y: x can be used to define the combinator used to implement Iota: i = ?c.cSK or, i = lambda c: c(S)(K) And the bitstrings are decoded like so: if you encounter '0' return i, otherwise decode two terms and apply the first to the second. In other words, the empty space, or '0', corresponds to i: _ -> 0 -> i and the mark () corresponds to i applied to itself: () -> 100 -> i(i) which is an Identity function I. The S and K combinators can be "recovered" by application of i to itself like so (this is Python code, note that I am able to use 'is' instead of the weaker '==' operator. The i combinator is actually recovering the very same lambda functions used to create it. Neat, eh?): K is i(i(i(i))) is decode('1010100') S is i(i(i(i(i)))) is decode('101010100') Where decode is defined (in Python) as: decode = lambda path: _decode(path)[0] def _decode(path): bit, path = path[0], path[1:] if bit == '0': return i, path A, path = _decode(path) B, path = _decode(path) return A(B), path (I should note that there is an interesting possibility of encoding the tuples two ways: contents before neighbors (depth-first) or neighbors before content (breadth-first). Here we look at the former.) So, in "Laws of Form" K is ()()() and S is ()()()() and, amusingly, the identity function I is (). The term '(())foo' applies the identity function to foo, which matches the behaviour of the (()) form in the Circle Arithmetic (()) == _ ("nothing".) (())A -> i(i)(A) -> I(A) -> A I just discovered this (that the Laws of Form have a direct mapping to the combinator calculus[5] by means of ?c.cSK) and I haven't found anyone else mentioning yet (although [6] might, I haven't worked my way all the way through it yet.) There are many interesting avenues to explore from here, and I personally am just beginning, but this seems like something worth reporting. Warm regards, ~Simon Peter Forman [1] http://en.wikipedia.org/wiki/Laws_of_Form [2] research.microsoft.com/en-us/people/dimitris/every-bit-counts.pdf [3] http://www.markability.net/ [4] http://semarch.linguistics.fas.nyu.edu/barker/Iota/ [5] http://en.wikipedia.org/wiki/SKI_combinator_calculus have [6] http://memristors.memristics.com/Combinatory%20Logic%20and%20LoF/Combinatory%20Logic%20and%20the%20Laws%20of%20Form.html From androidmaroso at gmail.com Sun Mar 31 15:22:28 2013 From: androidmaroso at gmail.com (androidmaroso at gmail.com) Date: Sun, 31 Mar 2013 12:22:28 -0700 (PDT) Subject: interacting with an opened libreoffice calc file Message-ID: <4b5ced78-8f1c-4e3e-b7eb-d182033184b1@googlegroups.com> Hi everyone, i'm new to the newsgroup and to python allthough (thanks to internet and the helpfull people i find) i've done a few scripts in python working like a charm. First of all i have to say i'm working on linux with python 2.3.7 (hope it's right) and libreoffice calc. My calc file gathers info from the web and adjusts it like i want and everything works fine there. My final result is a sheet called RESULTS where i have 6 columns : 1st column has BUY MARKET NAMES 2nd column has EURO PRICES (relative to the market's name in EURO currency) 3rd column has ORIG PRICE (value in the original currency) 4th column has SELL MARKET NAMES 5th column has EURO PRICES (relative to the market's name in EURO currency) 6th column has ORIG PRICE (value in the original currency) I would like to have another sheet or place (let's call it ALERTS) where i can make a list of alerts i would like to receive ... for example : MARKET1 BUY <= 20 MARKET2 SELL = 90 MARKET3 BUY > 59 What i would like is a script in python that reads all lines in the sheet ALERTS every n. (minutes or seconds) and compares the values from the RESULTS sheet and if the condition is TRUE then shoots an ALARM (soundfile would be great, maybe a customizable one) Is this possible? How can i acheive this? Thanks to anyone that can give me a solution, hint o show me the right direction. Cheers! Marco. From gerrymcgovern at gmail.com Sun Mar 31 16:10:22 2013 From: gerrymcgovern at gmail.com (jojo) Date: Sun, 31 Mar 2013 13:10:22 -0700 (PDT) Subject: Help with python code! Message-ID: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> Hi - I am a newbie to python and was wondering can someone tell me what the following code does. I need to figure out how to test it import time import glob import re import os current_time = time.time() + 60*60+24*30 dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt') q = re.compile('^Owner:.*CN=([^\s\,]+)') p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)') cert_name = "" days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7, "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12} for fname in dirList: cmd = "keytool ?printcert ?file " + fname for line in os.popen(cmd).readlines(): line = line.rstrip() m = p.search(line) if m: sue = time.mktime( (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), int(m.group(4)), int(m.group(5)), int(m.group(6)), int(days[m.group(1)]), 0, 0) ) expire_time = (sue ? current_time)/60/60/24 if expire_time < 0: print cert_name + " has already expired!" elif expire_time < 31: print cert_name + " expires in " +str(int(expire_time)) + " days" else: m = q.search(line) if m: cert_name = m.group(1) Im used to C# so the syntax looks bizarre to me! Any help would be great. From rosuav at gmail.com Sun Mar 31 16:39:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 07:39:11 +1100 Subject: Help with python code! In-Reply-To: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: > Im used to C# so the syntax looks bizarre to me! Any help would be great. The first thing you'll need to understand about Python syntax is that indentation is important. By posting this code flush-left, you've actually destroyed its block structure. Could you post it again, with indentation, please? We'd then be in a much better position to help. Chris Angelico From gerrymcgovern at gmail.com Sun Mar 31 17:06:19 2013 From: gerrymcgovern at gmail.com (jojo) Date: Sun, 31 Mar 2013 14:06:19 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> Message-ID: <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: > > > Im used to C# so the syntax looks bizarre to me! Any help would be great. > > > > The first thing you'll need to understand about Python syntax is that > > indentation is important. By posting this code flush-left, you've > > actually destroyed its block structure. Could you post it again, with > > indentation, please? We'd then be in a much better position to help. > > > > Chris Angelico Hi Chris, thanks for your reply. See code below... import time import glob import re import os current_time = time.time() + 60*60+24*30 dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt') q = re.compile('^Owner:.*CN=([^\s\,]+)') p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)') cert_name = "" days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7, "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12} for fname in dirList: cmd = "keytool ?printcert ?file " + fname for line in os.popen(cmd).readlines(): line = line.rstrip() m = p.search(line) if m: sue = time.mktime( (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), int(m.group(4)), int(m.group(5)), int(m.group(6)), int(days[m.group(1)]), 0, 0) ) expire_time = (sue ? current_time)/60/60/24 if expire_time < 0: print cert_name + " has already expired!" elif expire_time < 31: print cert_name + " expires in " +str(int(expire_time)) + " days" else: m = q.search(line) if m: cert_name = m.group(1) From gerrymcgovern at gmail.com Sun Mar 31 17:06:19 2013 From: gerrymcgovern at gmail.com (jojo) Date: Sun, 31 Mar 2013 14:06:19 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> Message-ID: <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: > > > Im used to C# so the syntax looks bizarre to me! Any help would be great. > > > > The first thing you'll need to understand about Python syntax is that > > indentation is important. By posting this code flush-left, you've > > actually destroyed its block structure. Could you post it again, with > > indentation, please? We'd then be in a much better position to help. > > > > Chris Angelico Hi Chris, thanks for your reply. See code below... import time import glob import re import os current_time = time.time() + 60*60+24*30 dirList = glob.glob('\content\paytek\ejbProperties\cybersource\*.crt') q = re.compile('^Owner:.*CN=([^\s\,]+)') p = re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)') cert_name = "" days = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} months = {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7, "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12} for fname in dirList: cmd = "keytool ?printcert ?file " + fname for line in os.popen(cmd).readlines(): line = line.rstrip() m = p.search(line) if m: sue = time.mktime( (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), int(m.group(4)), int(m.group(5)), int(m.group(6)), int(days[m.group(1)]), 0, 0) ) expire_time = (sue ? current_time)/60/60/24 if expire_time < 0: print cert_name + " has already expired!" elif expire_time < 31: print cert_name + " expires in " +str(int(expire_time)) + " days" else: m = q.search(line) if m: cert_name = m.group(1) From roy at panix.com Sun Mar 31 17:13:49 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 17:13:49 -0400 Subject: Help with python code! References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: In article <2912c674-e30b-4339-9344-1f460cb96b23 at googlegroups.com>, jojo wrote: > for fname in dirList: > cmd = "keytool ?printcert ?file " + fname > for line in os.popen(cmd).readlines(): > line = line.rstrip() > m = p.search(line) > if m: > sue = time.mktime( > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > int(m.group(4)), int(m.group(5)), int(m.group(6)), > int(days[m.group(1)]), 0, 0) > ) > expire_time = (sue ? current_time)/60/60/24 > if expire_time < 0: > print cert_name + " has already expired!" > elif expire_time < 31: > print cert_name + " expires in " +str(int(expire_time)) + " days" > else: > m = q.search(line) > if m: > cert_name = m.group(1) Was this code really indented like this when you got it? You've got (at least) three different indent sizes. I see 1, 2, and 3 space indents in different places in the code. I'm not even sure if this is legal, but even if it is, it's really bad form. Pick an indent, and stick with it uniformly. 4 spaces seems to be pretty standard. That being said, I'm going to return to my previous statement that until you know what the code is *supposed* to do, trying to test it is meaningless. From gerrymcgovern at gmail.com Sun Mar 31 17:21:50 2013 From: gerrymcgovern at gmail.com (jojo) Date: Sun, 31 Mar 2013 14:21:50 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> On Sunday, March 31, 2013 5:13:49 PM UTC-4, Roy Smith wrote: > In article <2912c674-e30b-4339-9344-1f460cb96b23 at googlegroups.com>, > > jojo wrote: > > > > > for fname in dirList: > > > cmd = "keytool ?printcert ?file " + fname > > > for line in os.popen(cmd).readlines(): > > > line = line.rstrip() > > > m = p.search(line) > > > if m: > > > sue = time.mktime( > > > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > > > int(m.group(4)), int(m.group(5)), int(m.group(6)), > > > int(days[m.group(1)]), 0, 0) > > > ) > > > expire_time = (sue ? current_time)/60/60/24 > > > if expire_time < 0: > > > print cert_name + " has already expired!" > > > elif expire_time < 31: > > > print cert_name + " expires in " +str(int(expire_time)) + " days" > > > else: > > > m = q.search(line) > > > if m: > > > cert_name = m.group(1) > > > > Was this code really indented like this when you got it? You've got (at > > least) three different indent sizes. I see 1, 2, and 3 space indents in > > different places in the code. > > > > I'm not even sure if this is legal, but even if it is, it's really bad > > form. Pick an indent, and stick with it uniformly. 4 spaces seems to > > be pretty standard. > > > > That being said, I'm going to return to my previous statement that until > > you know what the code is *supposed* to do, trying to test it is > > meaningless. Hi Rob. Thanks for your replies. Just to be clear this is for a interview and they would like me to figure out what the code does and come back with some test cases. I don't need to code the tests, just give some high level tests. As far as I can make out it is some system where you input your name and it will bring back your details plus how much time you have left on your card. Have to say I find the code extremely confusing, hopefully all python isn't like this!! From roy at panix.com Sun Mar 31 17:27:06 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 17:27:06 -0400 Subject: Help with python code! References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: In article <4455829d-5b4a-44ee-b65f-5f72d429ba9c at googlegroups.com>, jojo wrote: > Thanks for your replies. Just to be clear this is for a interview and they > would like me to figure out what the code does and come back with some test > cases. I don't need to code the tests, just give some high level tests. As > far as I can make out it is some system where you input your name and it will > bring back your details plus how much time you have left on your card. Have > to say I find the code extremely confusing, hopefully all python isn't like > this!! If this is for an interview, you really should be doing this on your own. I assume the point of the interview is to see how well you know Python. Please don't expect people here to take your interview for you. From gerrymcgovern at gmail.com Sun Mar 31 17:32:21 2013 From: gerrymcgovern at gmail.com (gerrymcgovern at gmail.com) Date: Sun, 31 Mar 2013 14:32:21 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: <40463d1c-013e-46c2-823a-787c1cca450f@googlegroups.com> On Sunday, March 31, 2013 5:27:06 PM UTC-4, Roy Smith wrote: > In article <4455829d-5b4a-44ee-b65f-5f72d429ba9c at googlegroups.com>, > > jojo wrote: > > > > > Thanks for your replies. Just to be clear this is for a interview and they > > > would like me to figure out what the code does and come back with some test > > > cases. I don't need to code the tests, just give some high level tests. As > > > far as I can make out it is some system where you input your name and it will > > > bring back your details plus how much time you have left on your card. Have > > > to say I find the code extremely confusing, hopefully all python isn't like > > > this!! > > > > If this is for an interview, you really should be doing this on your > > own. I assume the point of the interview is to see how well you know > > Python. Please don't expect people here to take your interview for you. Where did I ask people to take the interview for me? I asked for some tips on interpreting the code something which you have been unable to give me. If a senior dev (I am assuming you are a python dev) is unable to figure out what the code does, then I think me, been a newbie to new language (with horrible syntax) is entitled to ask for help. From rurpy at yahoo.com Sun Mar 31 17:46:26 2013 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 31 Mar 2013 14:46:26 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: <95056399-bafd-43c4-a261-c41f6943f5c5@googlegroups.com> On Sunday, March 31, 2013 3:27:06 PM UTC-6, Roy Smith wrote: > If this is for an interview, you really should be doing this on your > own. I assume the point of the interview is to see how well you know > Python. Please don't expect people here to take your interview for you. Maybe the interviewer gives higher ratings to someone who knows how to take advantage of all available resources than someone who goes off in a corner and tries to do it alone? From rosuav at gmail.com Sun Mar 31 17:35:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 08:35:38 +1100 Subject: Help with python code! In-Reply-To: <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 8:21 AM, jojo wrote: > Thanks for your replies. Just to be clear this is for a interview and they would like me to figure out what the code does and come back with some test cases That explains the utter lack of comments, then. In well-maintained code, you would simply read through the comments to get an idea of what it does. A couple of key things to look up: glob.glob and os.popen. When you know what they do, you should be able to get a broad understanding of the whole program. ChrisA From gerrymcgovern at gmail.com Sun Mar 31 17:41:06 2013 From: gerrymcgovern at gmail.com (gerrymcgovern at gmail.com) Date: Sun, 31 Mar 2013 14:41:06 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: <6285f193-5e3d-4696-a164-12bea6da3903@googlegroups.com> On Sunday, March 31, 2013 5:35:38 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 8:21 AM, jojo wrote: > > > Thanks for your replies. Just to be clear this is for a interview and they would like me to figure out what the code does and come back with some test cases > > > > That explains the utter lack of comments, then. In well-maintained > > code, you would simply read through the comments to get an idea of > > what it does. > > > > A couple of key things to look up: glob.glob and os.popen. When you > > know what they do, you should be able to get a broad understanding of > > the whole program. > > > > ChrisA OK perfect Chris. Thanks for your reply. From gerrymcgovern at gmail.com Sun Mar 31 17:41:06 2013 From: gerrymcgovern at gmail.com (gerrymcgovern at gmail.com) Date: Sun, 31 Mar 2013 14:41:06 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: <6285f193-5e3d-4696-a164-12bea6da3903@googlegroups.com> On Sunday, March 31, 2013 5:35:38 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 8:21 AM, jojo wrote: > > > Thanks for your replies. Just to be clear this is for a interview and they would like me to figure out what the code does and come back with some test cases > > > > That explains the utter lack of comments, then. In well-maintained > > code, you would simply read through the comments to get an idea of > > what it does. > > > > A couple of key things to look up: glob.glob and os.popen. When you > > know what they do, you should be able to get a broad understanding of > > the whole program. > > > > ChrisA OK perfect Chris. Thanks for your reply. From rosuav at gmail.com Sun Mar 31 17:21:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 08:21:00 +1100 Subject: Help with python code! In-Reply-To: <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 8:06 AM, jojo wrote: > On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: >> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: >> >> > Im used to C# so the syntax looks bizarre to me! Any help would be great. >> >> >> >> The first thing you'll need to understand about Python syntax is that >> >> indentation is important. By posting this code flush-left, you've >> >> actually destroyed its block structure. Could you post it again, with >> >> indentation, please? We'd then be in a much better position to help. >> >> >> >> Chris Angelico > > > Hi Chris, thanks for your reply. See code below... Ah, you appear to be posting from Google Groups. You may want to check this page out, as a lot of people rather dislike GG posts. http://wiki.python.org/moin/GoogleGroupsPython The best method is simply to avoid Google Groups altogether. Anyway, some code comments. (Though the biggest comment to make about the code is its utter lack of comments. Not a good idea in any language, for anything more than the most trivial script.) > current_time = time.time() + 60*60+24*30 This line doesn't, quite frankly, make a lot of sense; time.time() returns the current time already, but then an offset of one hour and twelve minutes is added. > if m: > sue = time.mktime( > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > int(m.group(4)), int(m.group(5)), int(m.group(6)), > int(days[m.group(1)]), 0, 0) > ) > expire_time = (sue ? current_time)/60/60/24 Here's a likely problem. There's supposed to be an operator - probably a plus sign - between sue and current_time. > else: > m = q.search(line) > if m: > cert_name = m.group(1) And this last line needs indentation. The very easiest way to debug Python code is to run it. If it runs, great! See what output it made and whether it's correct or not. If it doesn't, Python will give you an exception traceback that points you to the failing line. Get familiar with them, as you'll be seeing them a lot :) Chris Angelico From breamoreboy at yahoo.co.uk Sun Mar 31 18:02:05 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 31 Mar 2013 23:02:05 +0100 Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: On 31/03/2013 22:21, Chris Angelico wrote: >> sue = time.mktime( >> (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), >> int(m.group(4)), int(m.group(5)), int(m.group(6)), >> int(days[m.group(1)]), 0, 0) >> ) >> expire_time = (sue ? current_time)/60/60/24 > > Here's a likely problem. There's supposed to be an operator - probably > a plus sign - between sue and current_time. > There is actually a minus sign there which showed up when I pasted the code into the Eclipse/Pydev editor. That sadly doesn't fix the problem with the call to mktime, 12 open round brackets to 14 close if I've counted correctly. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rosuav at gmail.com Sun Mar 31 18:04:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 09:04:48 +1100 Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 9:02 AM, Mark Lawrence wrote: > On 31/03/2013 22:21, Chris Angelico wrote: >>> >>> sue = time.mktime( >>> (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), >>> int(m.group(4)), int(m.group(5)), int(m.group(6)), >>> int(days[m.group(1)]), 0, 0) >>> ) >>> expire_time = (sue ? current_time)/60/60/24 >> >> >> Here's a likely problem. There's supposed to be an operator - probably >> a plus sign - between sue and current_time. >> > > There is actually a minus sign there which showed up when I pasted the code > into the Eclipse/Pydev editor. That sadly doesn't fix the problem with the > call to mktime, 12 open round brackets to 14 close if I've counted > correctly. Oh, of course, since sue comes from mktime. But yeah, definitely needs an operator there. ChrisA From gerrymcgovern at gmail.com Sun Mar 31 17:24:42 2013 From: gerrymcgovern at gmail.com (gerrymcgovern at gmail.com) Date: Sun, 31 Mar 2013 14:24:42 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: <6a2b4d3e-b218-4e09-9ee1-c3aed1f454d3@googlegroups.com> On Sunday, March 31, 2013 5:21:00 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 8:06 AM, jojo wrote: > > > On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: > > >> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: > > >> > > >> > Im used to C# so the syntax looks bizarre to me! Any help would be great. > > >> > > >> > > >> > > >> The first thing you'll need to understand about Python syntax is that > > >> > > >> indentation is important. By posting this code flush-left, you've > > >> > > >> actually destroyed its block structure. Could you post it again, with > > >> > > >> indentation, please? We'd then be in a much better position to help. > > >> > > >> > > >> > > >> Chris Angelico > > > > > > > > > Hi Chris, thanks for your reply. See code below... > > > > Ah, you appear to be posting from Google Groups. You may want to check > > this page out, as a lot of people rather dislike GG posts. > > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > The best method is simply to avoid Google Groups altogether. > > > > Anyway, some code comments. (Though the biggest comment to make about > > the code is its utter lack of comments. Not a good idea in any > > language, for anything more than the most trivial script.) > > > > > current_time = time.time() + 60*60+24*30 > > > > This line doesn't, quite frankly, make a lot of sense; time.time() > > returns the current time already, but then an offset of one hour and > > twelve minutes is added. > > > > > if m: > > > sue = time.mktime( > > > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > > > int(m.group(4)), int(m.group(5)), int(m.group(6)), > > > int(days[m.group(1)]), 0, 0) > > > ) > > > expire_time = (sue ? current_time)/60/60/24 > > > > Here's a likely problem. There's supposed to be an operator - probably > > a plus sign - between sue and current_time. > > > > > else: > > > m = q.search(line) > > > if m: > > > cert_name = m.group(1) > > > > And this last line needs indentation. > > > > The very easiest way to debug Python code is to run it. If it runs, > > great! See what output it made and whether it's correct or not. If it > > doesn't, Python will give you an exception traceback that points you > > to the failing line. Get familiar with them, as you'll be seeing them > > a lot :) > > > > Chris Angelico Ok, thanks Chris!! From gerrymcgovern at gmail.com Sun Mar 31 17:24:42 2013 From: gerrymcgovern at gmail.com (gerrymcgovern at gmail.com) Date: Sun, 31 Mar 2013 14:24:42 -0700 (PDT) Subject: Help with python code! In-Reply-To: References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> Message-ID: <6a2b4d3e-b218-4e09-9ee1-c3aed1f454d3@googlegroups.com> On Sunday, March 31, 2013 5:21:00 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 8:06 AM, jojo wrote: > > > On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: > > >> On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: > > >> > > >> > Im used to C# so the syntax looks bizarre to me! Any help would be great. > > >> > > >> > > >> > > >> The first thing you'll need to understand about Python syntax is that > > >> > > >> indentation is important. By posting this code flush-left, you've > > >> > > >> actually destroyed its block structure. Could you post it again, with > > >> > > >> indentation, please? We'd then be in a much better position to help. > > >> > > >> > > >> > > >> Chris Angelico > > > > > > > > > Hi Chris, thanks for your reply. See code below... > > > > Ah, you appear to be posting from Google Groups. You may want to check > > this page out, as a lot of people rather dislike GG posts. > > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > The best method is simply to avoid Google Groups altogether. > > > > Anyway, some code comments. (Though the biggest comment to make about > > the code is its utter lack of comments. Not a good idea in any > > language, for anything more than the most trivial script.) > > > > > current_time = time.time() + 60*60+24*30 > > > > This line doesn't, quite frankly, make a lot of sense; time.time() > > returns the current time already, but then an offset of one hour and > > twelve minutes is added. > > > > > if m: > > > sue = time.mktime( > > > (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), > > > int(m.group(4)), int(m.group(5)), int(m.group(6)), > > > int(days[m.group(1)]), 0, 0) > > > ) > > > expire_time = (sue ? current_time)/60/60/24 > > > > Here's a likely problem. There's supposed to be an operator - probably > > a plus sign - between sue and current_time. > > > > > else: > > > m = q.search(line) > > > if m: > > > cert_name = m.group(1) > > > > And this last line needs indentation. > > > > The very easiest way to debug Python code is to run it. If it runs, > > great! See what output it made and whether it's correct or not. If it > > doesn't, Python will give you an exception traceback that points you > > to the failing line. Get familiar with them, as you'll be seeing them > > a lot :) > > > > Chris Angelico Ok, thanks Chris!! From roy at panix.com Sun Mar 31 17:08:10 2013 From: roy at panix.com (Roy Smith) Date: Sun, 31 Mar 2013 17:08:10 -0400 Subject: Help with python code! References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> Message-ID: In article <37f23623-8bf5-421a-ab6a-34ff622c69f1 at googlegroups.com>, jojo wrote: > Hi - I am a newbie to python and was wondering can someone tell me what the > following code does. I need to figure out how to test it I know this is going to sound unhelpful, but if your task is to test the code, what good does it do to know what it does? Clearly, it does what it does. What you really want to know is "What is it *supposed* to do?" Until you know what it's supposed to do, it is meaningless to even think about testing it. Seriously. I'm not trying to make life difficult for you. I've seen too much time and effort wasted on useless testing because there wasn't any specification for what the code was supposed to do. I will give you one hint, however. You've got stuff like: for line in os.popen(cmd).readlines(): line = line.rstrip() This is a syntax error because the indenting is wrong. Unlike C#, indenting is significant in Python. I don't know if the code you've got really is indented wrong, or it's just an artifact of how you posted it. But before anything else, you need to sort that out. Unless, of course, the specification for this code is, "It is supposed to raise IndentationError", in which case it passes the test :-)